Reference
CLI & JS API
Drive NanoVM from the command line with the test runner, or embed it in your own app with the browser wrapper.
Command-line runner
test/run.mjs loads an image and runs one command, printing its output and exit status.
bash
node test/run.mjs <image> --cmd <program> [args...]
# examples
node test/run.mjs images/busybox --cmd ls /usr/bin
node test/run.mjs images/node --cmd node -e "console.log(1+1)"Browser wrapper
container/nanovm.mjs wraps the WASM module together with the in-memory filesystem and the virtual server.
javascript
import { NanoVM } from "./container/nanovm.mjs";
const vm = await NanoVM.create();
await vm.fs.writeFile("/app.js", "console.log(process.arch)");
const { stdout } = await vm.run(["node", "/app.js"]);
console.log(stdout); // riscv64Filesystem (MemFS)
container/memfs.mjs implements an in-memory POSIX filesystem you can populate before a run and read back afterwards.
Method
Purpose
writeFile(path, data)
create or overwrite a file
readFile(path)
read a file as bytes or text
mkdir(path)
create a directory
readdir(path)
list directory entries
Prefer the SDK for apps
container/nanovm.mjs is the low-level browser wrapper. For embedding NanoVM in a real web app, use the SDK (@userland-run/nano-sdk) instead — it adds a typed filesystem, a shell engine, serve mode, scripting, a worker transport and an app catalog on top of this core. See the SDK overview.
The exact surface follows the source in container/. Treat the snippets above as the shape of the API, and check the module for the authoritative signatures.