quickjs-emscripten wraps the QuickJS interpreter compiled to WebAssembly. Host JavaScript can evaluate untrusted code in an isolated runtime and expose APIs safely.
Overview
quickjs-emscripten provides JavaScript and TypeScript bindings around QuickJS compiled to WebAssembly. Host applications create QuickJS runtimes and contexts to evaluate code, define globals, and call from guest scripts into host functions without sharing the main JS heap.
You load the WASM module through getQuickJS (async) or getQuickJSSync after the first load. Contexts belong to runtimes that share a JavaScript heap; handles returned from the API must be disposed manually because WASM memory is not garbage-collected like ordinary JS objects. Helpers include Scope, the using statement pattern, and Lifetime.consume for disposal.
The library supports ECMAScript modules, promises with executePendingJobs, CPU and memory limits on runtimes, and an asyncify build that lets guest code block while the host performs asynchronous work such as module loading. Variants trade size and speed (release vs debug, sync vs asyncify).
It runs in browsers, Node.js, Deno, Bun, Cloudflare Workers, and related environments, and installs from npm as quickjs-emscripten.
Key features
- QuickJS in WebAssembly
- Isolated eval of guest JavaScript
- Host function exposure
- Manual handle memory management
- ES module evaluation
- Asyncify for async host I/O
- Multiple WASM build variants
- npm package distribution
Use cases
- Sandboxing user-supplied scripts
- Plugins in Node or browser apps
- Synchronous loaders over async data