SDK

Web Worker

The VM runs a single-threaded cooperative scheduler; on the main thread it can block the UI. NanoWorkerClient hosts it in a Web Worker with the same API, just async.

Create a worker-hosted VM

javascript
import { createNanoWorker } from "@userland-run/nano-sdk";

const client = await createNanoWorker(config);

NanoWorkerClient mirrors Nano — run / exec / shExec / node, shell(), scripting(), nodeRuntime(), serve mode, interactive stdin, cancel / destroy — over a message channel.

Async filesystem

client.fs has the same methods as Vfs, but every call is a promise (an RPC round-trip to the worker).

javascript
await client.fs.writeFile("/app/main.js", src);
const out = await client.fs.readText("/app/out.txt");

When to use it

  • Any UI that must stay responsive during long runs.
  • Serving and streaming output.
  • Cold Node boots, which are CPU-heavy.
The default worker is ./worker/worker.js relative to import.meta.url; pass a custom workerFactory if your bundler needs it. Hosting in a worker is the recommended deployment for interactive apps.