boxd
Persistent Linux microVMs with memory snapshots and public HTTPS previews.
Install and authenticate
pnpm add sbox-sdk @boxd-sh/sdk
export BOXD_API_KEY=bxd_...Use Node 20 or newer. The adapter loads the Node gRPC SDK lazily. It does not use
@boxd-sh/sdk/web, because that transport cannot run interactive exec or PTY.
An edge bundle must externalize this optional peer and use a Node runtime for boxd.
Importing the adapter alone does not open a channel or load gRPC.
An API key or session token.
| Option | Env var | Required | Description |
|---|---|---|---|
apiKey | BOXD_API_KEY | optional | boxd API key. |
token | BOXD_TOKEN | optional | Session token, takes precedence over the API key. |
baseUrl | BOXD_BASE_URL | optional | Cluster endpoint, defaults to https://boxd.sh:9443. |
region | BOXD_REGION | optional | Default region, such as fra or nyc. |
org | BOXD_ORG | optional | Organization to create and list machines in. |
Node gRPC transport. baseUrl selects a hosted or self-hosted cluster; region selects its region.
token takes precedence over apiKey, then the SDK checks BOXD_TOKEN and
BOXD_API_KEY. baseUrl maps to the SDK's baseURL and falls back to
BOXD_BASE_URL. The default is https://boxd.sh:9443. Pass region for the
cluster's region, for example fra or nyc, and org for an organization.
The CLI also reads BOXD_REGION and BOXD_ORG.
Quickstart
import { createSandboxClient } from "sbox-sdk";
import { boxd } from "sbox-sdk/boxd";
const client = createSandboxClient({ provider: boxd() });
try {
const sandbox = await client.create({
name: "agent-workspace",
metadata: { project: "demo" },
env: { NODE_ENV: "development" },
resources: { vcpus: 2, memoryMB: 8192 },
lifecycle: { maxAgeMs: 60 * 60 * 1000 },
});
try {
const result = await sandbox.commands.run("echo out; echo err >&2");
console.log(result.stdout, result.stderr, result.exitCode);
await sandbox.files.write("/tmp/binary", new Uint8Array([0, 128, 255]));
await sandbox.pause();
await sandbox.resume();
} finally {
await sandbox.destroy();
}
} finally {
await client.dispose();
}verify() lists machines without creating anything. Machine lists have no pages;
the adapter filters their complete array by metadata, state and limit. Lists are
scoped to the configured region and organization. An ordinary named create() is
found by getOrCreate() with that exact name. Retried creates derive a stable
name from the idempotency key when no name was supplied. Destroyed entries are
never reused. getInfo() reads current state rather than the creation response.
Templates and snapshots
const template = await client.templates.build({
name: "ubuntu-base",
source: { image: "ubuntu:24.04" },
env: { APP_MODE: "agent" },
readyCmd: "test -d /tmp",
});
const sandbox = await client.create({ template });
const snapshot = await sandbox.snapshots.create({ name: "workspace-save" });
const restored = await client.create({ fromSnapshot: snapshot });
const [fork] = await sandbox.fork();
// Destroy all three machines when finished. Delete snapshots/templates separately.Templates boot a temporary machine, run an optional readiness command, capture
its memory and disk in an account snapshot, then delete the temporary machine.
Sources are public images or existing snapshots. Cache keys and aliases are stored
in snapshot names. The adapter waits until the newly captured version is ready before returning.
Dockerfiles, registry auth, template user, workdir and startCmd are refused.
Snapshots and forks include memory. Filesystem-only snapshots and restoring a
snapshot into an existing machine are unavailable. Snapshot restores inherit size
and volumes; requests to change them are rejected. Cancelling an overwrite preserves earlier snapshot versions; the server may still
finish the newly submitted version. Snapshot references belong to
the configured region and account.
Previews and browser access
const preview = await sandbox.ports.expose(3000);
console.log(preview.url, preview.auth); // public HTTPS routeThe adapter creates a named HTTPS proxy sbox-3000 and turns machine-wide bot
protection off so the public route can be used by browsers and WebSockets.
This affects all routes on the machine. WebSocket URLs use the same host with
wss://. Private previews are unsupported; bot protection is not authentication.
Ports declared in create() configure named proxies, while ports.expose() also
sets their public access behavior. Raw TCP/UDP forwarding is available through
sandbox.raw().client.machines.ports.
Capabilities
| Capability | Level | Notes |
|---|---|---|
streaming / stdin | native | separate stdout/stderr, real exit codes, stdin and EOF |
pty | native | merged output, resize |
list | native | one unpaged list, filtered locally by metadata, state and limit |
stop | native | disk persists (preservesDiskOnStop) |
pause | native | suspend keeps RAM (preservesMemoryOnPause) |
setTimeout | native | delete-after deadline |
filesUpload | native | binary-safe transfers |
snapshot / fork | native | memory and disk |
egressControl | native | allow-all, block-all and hostname/IPv4 allow-list; no deny, inject |
exposePort | native | public HTTPS proxies |
volumes | native | persistent disks |
templateBuild | native | public image or snapshot sources, captured as a snapshot |
region | native | spec.region or the region option |
privatePreview | unsupported | previews are public |
background / killProcess | unsupported | no PID and no reconnect token in the SDK |
metrics | unsupported | the SDK reports billing usage only |
ssh | unsupported | needs a separately linked public key |
filesWatch / proxiedFetch | unsupported | |
codeInterpreter | unsupported | |
statefulKernel | unsupported | |
gpu / secretsVault | unsupported |
Create contract
- Idempotency is
exact. Machine names are unique, so a duplicate create is a Conflict. An unnamedcreate()derives the namesbox-<24 hex>from the idempotency key, looks for it first, and adopts its own machine when a retry or a racing process conflicts. A name you choose is never adopted by a plaincreate(): a machine already holding it makes the call fail with Conflict (only a retry of the same call, orgetOrCreate(), adopts it). Machines in a deleting state are not reused. - Limits. Metadata becomes machine labels: at most 64 entries, keys up to 63
characters and values up to 256 (from the SDK's label rules; the server also
restricts key characters and reserves the
boxd/prefix). Idle and max-age timeouts are rounded up to whole seconds.
| Field | Support | Behaviour |
|---|---|---|
resources.vcpus/memoryMB | approximate | smallest 1/4, 2/8, 4/16 or 8/32 (vCPU / GiB) tier that fits both |
resources.diskMB | approximate | disk is fixed at 100 GiB; larger requests throw |
resources.shmMB | rejected | custom shared memory is unavailable |
resources.gpu/gpuCount | rejected | no GPUs |
lifecycle.idleTimeoutMs | approximate | auto-suspend (or auto-destroy with onIdle: "destroy"), whole seconds |
lifecycle.maxAgeMs | approximate | delete-after, whole seconds |
Idle stop and autoResume: false are refused.
Sizes
spec.size maps onto boxd's four fixed machine sizes, so every preset lands on
a real tier. All of them have the fixed 100 GiB disk.
| Preset | Machine |
|---|---|
small | 1 vCPU, 4 GiB RAM |
medium | 2 vCPU, 8 GiB RAM |
large | 4 vCPU, 16 GiB RAM |
xlarge | 8 vCPU, 32 GiB RAM |
Snapshot restores inherit their size, so size or resources together with
fromSnapshot or a snapshot template throws Validation.
How the spec maps
| sbox | boxd |
|---|---|
name | name (must be unused) |
idempotencyKey | sbox-<24 hex> name when unnamed; a retried create reuses it |
template | image |
fromSnapshot / snapshot template | fromSnapshot |
env, inline secrets | machine env |
stored secrets | machine spec secrets (default image only, no rename) |
metadata | labels |
resources.vcpus / memoryMB | size / vcpu + memory, rounded up to a tier |
region | region |
lifecycle.idleTimeoutMs | autoSuspendTimeout (autoDestroyTimeout for onIdle: "destroy") |
lifecycle.maxAgeMs / ttlMs | deleteAfter |
network | machine spec egress (default image only) |
volumes | config.volumes |
ports | named sbox-<port> proxies |
| Capability | In-Memory19n | Docker19n | Rivet agentOS9n | Archil16n | Microsandbox14n | Microsandbox Cloud8n | E2B22n | Daytona24n | Vercel16n | Modal17n | Tensorlake18n | Superserve16n | Fly Sprites13n | Freestyle11n | Together11n | Maritime15n | boxd15n | Luxor Agent Cloud14n | Buddy Sandboxes10n | Instabox14n | Upstash Box13n | Styne18n | Agent3713n | Baseten14n | Blaxel18n | Boat13n | Beam13n | Railway11n | Northflank13n | Fly Machines10n | AWS Lambda MicroVMs10n | Morph10n | Cloudflare14n | CodeSandbox7n | Runloop6n |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| lifecycle | |||||||||||||||||||||||||||||||||||
| list | |||||||||||||||||||||||||||||||||||
| stop | |||||||||||||||||||||||||||||||||||
| pause | |||||||||||||||||||||||||||||||||||
| setTimeout | |||||||||||||||||||||||||||||||||||
| exec | |||||||||||||||||||||||||||||||||||
| background | |||||||||||||||||||||||||||||||||||
| streaming | |||||||||||||||||||||||||||||||||||
| killProcess | |||||||||||||||||||||||||||||||||||
| pty | |||||||||||||||||||||||||||||||||||
| stdin | |||||||||||||||||||||||||||||||||||
| filesystem | |||||||||||||||||||||||||||||||||||
| filesWatch | |||||||||||||||||||||||||||||||||||
| filesUpload | |||||||||||||||||||||||||||||||||||
| code | |||||||||||||||||||||||||||||||||||
| codeInterpreter | |||||||||||||||||||||||||||||||||||
| statefulKernel | |||||||||||||||||||||||||||||||||||
| network | |||||||||||||||||||||||||||||||||||
| exposePort | |||||||||||||||||||||||||||||||||||
| privatePreview | |||||||||||||||||||||||||||||||||||
| egressControl | |||||||||||||||||||||||||||||||||||
| ssh | |||||||||||||||||||||||||||||||||||
| proxiedFetch | |||||||||||||||||||||||||||||||||||
| snapshot | |||||||||||||||||||||||||||||||||||
| snapshot | |||||||||||||||||||||||||||||||||||
| fork | |||||||||||||||||||||||||||||||||||
| volumes | |||||||||||||||||||||||||||||||||||
| templateBuild | |||||||||||||||||||||||||||||||||||
| meta | |||||||||||||||||||||||||||||||||||
| gpu | |||||||||||||||||||||||||||||||||||
| region | |||||||||||||||||||||||||||||||||||
| secretsVault | |||||||||||||||||||||||||||||||||||
| metrics | |||||||||||||||||||||||||||||||||||
| create contract | |||||||||||||||||||||||||||||||||||
| idempotency | |||||||||||||||||||||||||||||||||||
| spec fidelity | |||||||||||||||||||||||||||||||||||
| vcpus | |||||||||||||||||||||||||||||||||||
| memoryMB | |||||||||||||||||||||||||||||||||||
| diskMB | |||||||||||||||||||||||||||||||||||
| shmMB | |||||||||||||||||||||||||||||||||||
| gpu | |||||||||||||||||||||||||||||||||||
| idleTimeoutMs | |||||||||||||||||||||||||||||||||||
| maxAgeMs | |||||||||||||||||||||||||||||||||||
| size presets | |||||||||||||||||||||||||||||||||||
| small | |||||||||||||||||||||||||||||||||||
| medium | |||||||||||||||||||||||||||||||||||
| large | |||||||||||||||||||||||||||||||||||
| xlarge | |||||||||||||||||||||||||||||||||||
| limits | |||||||||||||||||||||||||||||||||||
| maxPorts | 0 | 15 | 0 | 32 | 50 | ||||||||||||||||||||||||||||||
| maxLabels | 30 | 5 | 64 | 5 | 20 | ||||||||||||||||||||||||||||||
| labelKeyLength | 63 | 59 | 63 | 63 | |||||||||||||||||||||||||||||||
| labelValueLength | 256 | 256 | 256 | ||||||||||||||||||||||||||||||||
| minIdleTimeout | 1m | 1m | 1s | 5m | 1m | ||||||||||||||||||||||||||||||
| idleTimeoutStep | 1s | 1m | 1s | 1s | 1s | 1s | 1s | 1s | 1s | 1s | 1m | 1s | 1s | 1s | |||||||||||||||||||||
| minMaxAge | 1m | 1s | 5m | 5m | |||||||||||||||||||||||||||||||
| maxAgeStep | 1s | 1s | 1m | 1s | 1s | 1s | 1s | 1s | 1s | 1s | 1s | 1s | 1s | 1s | 1s | 1s | |||||||||||||||||||
- Exec streams keep stdout and stderr separate and preserve real exit codes. PTY streams merge them, as terminals normally do. Stdin, EOF and resize are supported. Commands honor env and cwd. The SDK does not expose a PID or a PTY reconnect token. Background reconnect and killing arbitrary PIDs are unavailable.
kill()and timeouts cancel the gRPC stream. Current boxd servers terminate its process group with TERM, then KILL. The streaming API has no timeout parameter, so the adapter appliestimeoutMswith a timer and closes the stream.userselection and arbitrary signal delivery are refused.- Sizes are 1 vCPU / 4 GiB, 2 / 8, 4 / 16 and 8 / 32. The adapter chooses the smallest satisfying size. Disk allocation is fixed at 100 GiB. GPUs and custom shared memory allocation are unavailable.
- Idle pause and idle destroy map to native timers, rounded up to seconds. Idle
stop and
autoResume: falseare refused.setTimeout()sets the delete-after deadline. Pausing preserves RAM; stopping preserves disk. - Egress allows hostnames and public IPv4 addresses, or
noneto block all. CIDR ranges, deny rules and credential injection are refused. Default-image creates use machine specs to apply egress at birth. Custom image creates with egress or stored secret references are refused; build a snapshot template first. - Inline secrets become environment variables. Stored secrets can be referenced by name through machine specs; renaming them is refused. This adapter does not manage the account secret vault.
- Volumes use native persistent disks and create-time mounts. They can attach to only one machine at a time. Delete disks separately after destroying machines.
- Native file transfers preserve binary data. Directory operations and stat use
machines.fs, which requires a current guest agent. Older agents reportAgentOutdatedError; reboot the machine. The adapter avoidslistDir's 5,000 entry cap by using the current filesystem API. - SSH requires a separately linked public key; the adapter cannot mint a private
credential. Resource usage is billing accounting, so
metricsis unsupported. File watches and code interpreter sessions are also unsupported. - The adapter uses the SDK's gRPC transport, not the core's injected
fetch. Callclient.dispose()to cancel local streams and close channels. It does not delete persistent machines, snapshots or disks.
Validation uses typed SDK fakes with MiniShell and local transport probes. Hosted account behavior and self-hosted server compatibility require live account tests.
Together Sandbox
Firecracker VMs booted from snapshots on Together AI (the successor to CodeSandbox). Remote Dockerfile builds, streamed execs, PTY, and hibernate/resume, via together-sandbox.
Upstash Box
Persistent and TTL-bound ephemeral Linux containers from Upstash, with streamed exec, native files and filesystem snapshots via @upstash/box.