Skip to main content
QuickJS is the default runtime for node and js in both SDKs. It supports ES2023 for small scripts and pipe transforms, with access to workspace files under the same permissions as shell commands. Despite the command name, it does not provide Node.js APIs, npm packages or network access.

Installation

Download qjs-wasi.wasm from a quickjs-ng release. Point home, or MIRAGE_QUICKJS_HOME, at its directory.

Usage

QuickJS is in the default runtimes, so node works once it is installed. To list it yourself:

JavaScript compatibility

std and os are globals. The SDK columns identify where their APIs differ. In TypeScript, any std or os function not listed as supported throws TypeError. Examples assume a writable /data mount. Mount modes and permissions still apply.

std.open()

std.open(path, mode, errorObj) returns null on failure and sets errorObj.errno. A read-only mount refuses modes that write. Modes and modifiers are listed separately; for example, rb combines r and b.

File objects

std

Environment variables come from the Mirage session. std.loadFile() returns null when reading fails.

Standard streams

std.in receives the command’s piped input.

os

  • os.readdir(): Returns [value, errno].

console and printing

Runtime globals

  • scriptArgs: The invocation name and arguments.

Unavailable host APIs

Unavailable in this runtime.

Notes

  • -e <code> runs the argument, a file runs a mounted script, and with neither, piped input is the program. A .mjs file runs as an ES module; .js and -e run as classic scripts, and -m forces module mode.
  • console.log and print add a newline; std.out.puts and std.err.puts write raw.
  • An error in async code fails the run. In TypeScript this holds for a module and for the promise a script ends with, as in main(); a promise the script drops before then is not reported.
  • QuickJS cannot reach host files or the network. command_limits bound its time and output, and in TypeScript a run also stops at 64 MiB of memory. Run untrusted or heavy code in a sandbox.