Skip to content

Runtime APIs

Ved Gupta edited this page Nov 13, 2026 · 5 revisions

Runtime APIs

CodeLab executes JavaScript, TypeScript, C++20, and Python 3.12 entirely inside isolated browser Web Workers. User code interacts with an in-memory POSIX filesystem and virtual loopback network stack without needing any remote execution server.


Node.js v22 Built-In Modules

All 50 standard Node.js built-in modules are implemented in pure JavaScript and available through both CommonJS and ES module imports:

Area Supported Capabilities
Filesystem & Streams Synchronous, callback, promise, and streaming file operations backed directly by the virtual workspace and temporary directories
HTTP & Loopback Networking In-memory HTTP, HTTPS, HTTP/2, TCP, TLS, and UDP servers and clients bound to the virtual port table and reachable from the terminal or Web Preview
Cryptography & Compression Hashing, HMACs, random UUIDs and byte buffers, key derivation, and Gzip or Deflate compression utilities
Testing & Assertions Structured test suites, nested subtests, lifecycle hooks, strict assertions, and per-test execution timing
Workers, VM & WASI Sandboxed VM contexts, worker threads, process globals, timers, and a full WASI Preview 1 host wired to the virtual filesystem
import http from 'node:http';
import fs from 'node:fs/promises';

await fs.writeFile('/workspace/hello.txt', 'Hello from Node v22 in the browser!');

http.createServer(async (_req, res) => {
  const body = await fs.readFile('/workspace/hello.txt', 'utf8');
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end(body);
}).listen(8080);

Bun v1.1 Runtime Support

CodeLab includes native compatibility for core Bun APIs alongside Node.js:

  • HTTP Servers: Start high-level Fetch-based servers that register automatically in the Ports and Web Preview tabs.
  • File I/O: Read and write virtual workspace files using standard Web Blob and Response interfaces.
  • Embedded SQLite: Run relational queries, transactions, and aggregates in memory or persisted inside the virtual filesystem.
  • Test Runner: Write Jest-compatible test suites with matchers, lifecycle hooks, and mocks.
  • Utilities: Hash values, verify passwords, sleep asynchronously, and spawn subprocesses.
import { Database } from 'bun:sqlite';

const db = new Database(':memory:');
db.run('CREATE TABLE items (id INTEGER PRIMARY KEY, name TEXT)');
db.run('INSERT INTO items (name) VALUES (?)', ['Token Bucket']);

console.log(db.query('SELECT * FROM items').all());

C++20 WebAssembly Toolchain

When the C++ extension is enabled, CodeLab downloads a WebAssembly Clang/LLVM compiler, linker, and WASI standard library on demand (~35 MB) and caches it in IndexedDB for offline reuse:

  • Supports C++17, C++20, and C++23 standards with configurable optimization levels.
  • Pre-mounts competitive programming headers, linked list and binary tree builders, and a lightweight unit test header wired into the Test Suite drawer.
  • Maps compiler errors directly to inline editor squiggles and the Problems panel.

Python 3.12 WebAssembly Runtime

When the Python extension is enabled, CodeLab loads CPython 3.12 in WebAssembly via Pyodide and caches the runtime in IndexedDB:

  • Synchronizes files bidirectionally with the virtual workspace so scripts can read and write project files normally.
  • Includes built-in data structure helpers (linked lists, trees, heaps) and a structured test harness alongside pytest support.
  • Maps Python tracebacks directly to inline editor error markers.

Installing Packages

Install real open-source packages and their transitive dependencies from jsDelivr directly into the virtual workspace from the integrated terminal:

npm install zod
pnpm add nanoid
bun add hono

Clone this wiki locally