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
- Python
- TypeScript
qjs-wasi.wasm from a
quickjs-ng release.
Point home, or MIRAGE_QUICKJS_HOME, at its directory.Usage
QuickJS is in the default runtimes, sonode works once it is installed. To
list it yourself:
- Python
- TypeScript
- YAML
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.
Example: append to a workspace file
Example: append to a workspace file
Limitations
Limitations
File objects
Example: write, seek and read a file
Example: write, seek and read a file
Limitations
Limitations
std
Environment variables come from the Mirage session. std.loadFile() returns
null when reading fails.
Example: read a session environment variable
Example: read a session environment variable
Limitations
Limitations
Standard streams
std.in receives the command’s piped input.
Example: forward piped input
Example: forward piped input
Limitations
Limitations
os
os.readdir(): Returns[value, errno].
Example: list a workspace directory
Example: list a workspace directory
Limitations
Limitations
console and printing
Example: print a result
Example: print a result
Limitations
Limitations
Runtime globals
scriptArgs: The invocation name and arguments.
Example: read arguments and encode text
Example: read arguments and encode text
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.mjsfile runs as an ES module;.jsand-erun as classic scripts, and-mforces module mode.console.logandprintadd a newline;std.out.putsandstd.err.putswrite 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_limitsbound its time and output, and in TypeScript a run also stops at 64 MiB of memory. Run untrusted or heavy code in a sandbox.