MicrosandboxBeta
Local libkrun microVMs with native command streams, PTY, files, retained jobs, memory snapshots and forks. Beta; Node 22 or newer.
Microsandbox embeds a native microVM runtime without a daemon. Linux needs KVM, macOS needs Apple Silicon, and Windows needs WHP. The project is beta. The adapter is checked against published SDK 0.8.3 declarations and current official docs.
Installation
pnpm add sbox-sdk microsandbox@0.8.3The provider SDK requires Node 22 or newer. Importing this adapter or constructing its factory does not load the native addon. The first operation loads it.
The full microsandbox@0.8.3 npm tarball omits its platform binary dependencies.
If it reports a missing native binding, install the matching 0.8.3 binary. On
Apple Silicon macOS:
npm install @superradcompany/microsandbox-darwin-arm64@0.8.3Other published targets are linux-x64-gnu, linux-arm64-gnu,
win32-x64-msvc, and win32-arm64-msvc, with the same package prefix and version.
Alternatively, install @microsandbox/local@0.8.3 and import it before using the
adapter to register its local binding. Follow the provider's
runtime setup guide for libkrun and host
permissions. This adapter does not install or download a runtime automatically.
Usage
import { createSandboxClient } from "sbox-sdk";
import { microsandbox } from "sbox-sdk/microsandbox";
const client = createSandboxClient({ provider: microsandbox() });
const sandbox = await client.create({
template: "alpine:3.22",
env: { APP_ENV: "test" },
metadata: { project: "demo" },
resources: { vcpus: 2, memoryMB: 1024, diskMB: 4096 },
lifecycle: { idleTimeoutMs: 60_000, maxAgeMs: 300_000, onIdle: "stop" },
});
try {
const output = await sandbox.commands.run("pwd; echo ok", { cwd: "/tmp" });
console.log(output.stdout);
await sandbox.files.write("/tmp/blob.bin", new Uint8Array([0, 255, 128]));
} finally {
await sandbox.destroy();
}microsandbox({ image, home, configPath }) creates a retained local context. It
ignores MSB_BACKEND, so another factory or environment change cannot redirect
it. No API key is needed. verify() lists at most one sandbox without booting,
starting or creating one. A successful verify confirms catalog access, not that
hardware virtualization, image pulls or guest execution work.
Images and creation options
template is an OCI image reference. templateRef.id is accepted for this
provider. The default is alpine:3.22. Image cache operations and Sandboxfiles do
not provide the template build/alias registry required by templates.build();
that capability is unsupported. Build OCI images with external tooling first.
Environment and metadata map to native env and labels. CPU, memory MiB and root
disk MiB map to the native builder. Existing named volumes can be mounted with
volumes: [{ id: volume.name, mountPath: "/data", readOnly: true }].
client.volumes creates, gets, lists and deletes directory volumes; sizeMB
sets their quota. Creation uses persistent detached sandboxes, so dropping a
JavaScript handle does not destroy them. Always call destroy() to remove them.
Idle and maximum-age limits must be positive whole seconds expressed in ms.
Only onIdle: "stop" and autoResume: false are accepted. setTimeout() is
unsupported because SDK 0.8.3 cannot update these limits after creation. Names
are preserved, and unnamed retries derive the same name from the idempotency
key. getOrCreate({ name }) uses the native operation; existing settings win.
If that named operation finishes after cancellation, it detaches the returned
handle and keeps the named sandbox. The SDK does not say whether it created or
reused the name, so cancellation cannot safely delete it. Reconnect by name to
inspect it or destroy it explicitly.
Region, GPU and shared-memory sizing are rejected.
Execution and files
Exec runs /bin/sh -c with native cwd, env, user, timeout, separate output streams,
real exit codes, stdin and signals. Cancellation before or during startup keeps
ownership of late processes and kills them. Native stdin/file streams are closed
on completion or error. Files use the native binary API, including stream
uploads and downloads, with no shell or base64 encoding.
Local commands.spawn() uses retained jobs and exposes their job IDs for
connect, list and kill. Attachments replay up to 1 MiB; older output is dropped
and the stream continues. A broken attachment fails the stream but leaves the
job running, so you can reconnect; only cancelling spawn() kills it. PTY
output is merged by the
provider. Resize swaps the SDK's rows/columns order correctly. PTY reconnect is
limited to sessions still attached to the same sandbox handle.
Previews
Local published ports use http://127.0.0.1:<port> and
ws://127.0.0.1:<port>. They bind to loopback and are unauthenticated, with
auth: { type: "public" }. They are reachable from the runtime host, not a
remote browser. privatePreview and previewBrowserAuth are false.
const preview = await sandbox.ports.expose(8080);
console.log(preview.url);
await sandbox.ports.unexpose(8080);spec.ports publishes matching host/guest ports at creation. A host-port conflict
is a provider error. Dynamic exposure requires the SDK to confirm a live port
change; the adapter rejects unconfirmed or deferred changes.
Snapshots, pause and fork
Local pause keeps RAM and disk. Stop keeps disk; resume restarts the same
persisted sandbox. Snapshots are disk-only by default; mode: "memory" captures
memory/device state and sets includesMemory: true. Boot a new sandbox with
client.create({ fromSnapshot: ref }). In-place restore is unavailable.
Snapshots survive sandbox deletion and remain caller-owned resources.
fork(count) creates native copy-on-write children and removes already-created
children if a later fork fails. Metrics use the native sample and keep unavailable
disk measurements undefined.
Network and secrets
Creation accepts network.mode of allow-all, block-all, or allow-list, with
domain/CIDR allows and denials. Denials precede allows. Domain allowlists allow
DNS only through the host gateway. Wildcard domains map to suffix rules.
There is no live network policy setter in 0.8.3, so egressControl is unsupported.
Inline secrets in default env mode map to ordinary guest environment values.
Provider-side vault references and mode: "egress" are rejected. Microsandbox's
host-bound placeholder substitution does not insert absent headers; the adapter
rejects network.inject and does not claim secretsVault.
Capabilities
| Capability | Level | Notes |
|---|---|---|
streaming / stdin | native | execStreamWith("/bin/sh"), stderr kept separate, real exit codes |
background / killProcess | native | retained jobs: commands.spawn(), connect, list and kill by job ID |
pty | native | TTY exec; reconnect only through the same sandbox handle |
filesUpload | native | native binary file streams |
list | native | cursor-paginated, then filtered by state, metadata and limit |
stop | native | disk persists (preservesDiskOnStop) |
pause | native | resident pause keeps RAM (preservesMemoryOnPause) |
snapshot | native | disk by default; mode: "memory" captures memory |
fork | native | copy-on-write children |
exposePort | native | loopback 127.0.0.1 port publishing, auth: { type: "public" } |
volumes | native | named directory volumes; sizeMB sets the quota |
metrics | native | native metrics sample |
egressControl | unsupported | no live policy setter; spec.network is applied at create |
setTimeout | unsupported | idle and max-age limits can't change after create |
privatePreview | unsupported | published ports are unauthenticated |
templateBuild | unsupported | build OCI images with external tooling |
region / gpu | unsupported | rejected at create |
secretsVault | unsupported | inline env secrets only |
ssh | unsupported | SDK SSH doesn't return a host/port/key tuple |
codeInterpreter | unsupported | |
statefulKernel | unsupported | |
filesWatch / proxiedFetch | unsupported |
idempotency is exact: an unnamed create gets a name derived from the
idempotency key, and the adapter never asks the SDK to replace an existing
sandbox, so a retried create fails with Conflict instead of making a second
VM. perCommandEnvCwd and exitCodeNative are true.
How the spec maps
| sbox | Microsandbox |
|---|---|
template / templateRef.id | image (OCI reference; default alpine:3.22) |
fromSnapshot | sandboxes.restore(checkpoint), a new sandbox |
name / idempotencyKey | sandbox name (sbox-<sha256(key)> when unnamed) |
env, env-mode secrets | envs / env |
metadata | labels |
resources.vcpus | cpus (exact) |
resources.memoryMB | memory MiB (exact) |
resources.diskMB | rootDisk MiB (exact; rejected with fromSnapshot) |
resources.shmMB / gpu / gpuCount | rejected |
lifecycle.idleTimeoutMs | idleTimeoutSeconds (exact; must be whole seconds) |
lifecycle.maxAgeMs | maxDurationSeconds (exact; must be whole seconds) |
lifecycle.onIdle / autoResume | only "stop" / false; other values are rejected |
network | network.policy rules at create |
volumes | named volume mounts |
ports | portBind("127.0.0.1", port, port) |
region | rejected |
Microsandbox has no fixed size tiers, so spec.size uses the default ladder.
The adapter declares no label or port limits; the SDK limits sandbox names to
128 UTF-8 bytes.
Limitations and verification
There is no mapped SSH credential endpoint: SDK SSH sessions/servers do not
return the host/port/key tuple required by ssh.create(). Code interpreter,
stateful kernels, file watching and template builds are unsupported.
Offline live: true conformance runs through a typed SDK fake backed by MiniShell,
including a 5 MiB binary round trip. Real SDK loopback tests check authentication,
pagination, live state and error normalization. Fake tests run on Node 20.10;
real SDK tests are gated to Node 22+. No hardware VM or paid account has been
used for this implementation.
To opt in to local live conformance after installing the runtime:
MSB_LIVE=1 SBOX_LIVE=microsandbox pnpm --filter sbox-sdk test:liveSee Microsandbox Cloud for the separate cloud factory and its smaller capability map.
Archil
Persistent Firecracker microVMs with memory-preserving pause, forks, Archil disk mounts, native binary files, PTY and header-authenticated private previews.
Microsandbox Cloud
Managed microVMs with native exec streams, stdin, PTY, binary files, volumes and stopped filesystem snapshots. Beta; Node 22 or newer.