Archil
Persistent Firecracker microVMs with memory-preserving pause, forks, Archil disk mounts, native binary files, PTY and header-authenticated private previews.
Installation
pnpm add sbox-sdk diskUse disk >=1.15.1 and Node.js >=22.19. The SDK loads lazily on the first authenticated operation. This adapter targets persistent sandboxes, not Archil's one-shot serverless execution.
Authentication and quickstart
Set ARCHIL_API_KEY to the full key, including its key- prefix. ARCHIL_REGION selects the default region, for example aws-us-east-1. Both fall back to the disk SDK's environment handling when factory options are omitted. For BYOC, pass baseUrl explicitly. The sbox CLI also maps ARCHIL_BASE_URL to that option.
import { createSandboxClient } from "sbox-sdk";
import { archil } from "sbox-sdk/archil";
const client = createSandboxClient({ provider: archil() });
const verification = await client.verify(); // One disk-list page; never creates anything.
if (!verification.ok) throw new Error("Check Archil credentials");
const sandbox = await client.create({
template: "node:24-bookworm",
metadata: { project: "agent" },
resources: { vcpus: 2, memoryMB: 2048 },
});
try {
for await (const event of sandbox.commands.run(
"echo hello; echo warning >&2"
)) {
if (event.type === "stdout") process.stdout.write(event.data);
if (event.type === "stderr") process.stderr.write(event.data);
}
await sandbox.files.write("/tmp/data.bin", new Uint8Array([0, 128, 255]));
await sandbox.pause();
await sandbox.resume();
} finally {
await sandbox.destroy();
}The default image is explicitly node:24-bookworm, so it does not depend on changing provider defaults. image or imageId sets the factory default; they are mutually exclusive. A spec's template overrides that default. A 64-character hexadecimal template is a prepared Archil image ID; other strings are OCI references.
Capabilities
| Capability | Level | Notes |
|---|---|---|
streaming / background | native | Sandbox.run(), stdout and stderr kept separate |
killProcess | native | process kill; no signal argument |
stdin | native | sendInput / closeStdin |
pty | native | terminal run option, resize and reattach |
list | native | Sandboxes.list, fully paginated |
stop | native | disks persist (preservesDiskOnStop) |
pause | native | keeps memory and processes (preservesMemoryOnPause) |
setTimeout | native | setTimeout({ timeoutSeconds }), 60 s to 24 h |
filesUpload | native | files.uploadFile / downloadFile, binary-safe |
exposePort | native | public HTTPS routes |
privatePreview | native | X-Archil-Token header; no browser WebSocket auth |
egressControl | native | allow-all, block-all and allow-list, deny rules, inline header injection |
fork | native | writable disk branch with the source's labels |
volumes | native | Archil disks |
region | native | spec.region picks a regional client |
templateBuild | emulated | OCI images only; aliases and cache keys live in this process |
snapshot / ssh | unsupported | checkpoints belong to a sandbox; no SSH credential endpoint |
filesWatch / codeInterpreter / statefulKernel | unsupported | |
proxiedFetch / gpu / secretsVault / metrics | unsupported |
exitCodeNative and perCommandEnvCwd are true. resumeChangesId is false.
Create contract
- Idempotency is
exact. Archil sandbox names are unique within an account.create()always names the sandbox: yourname, orsbox-plus a hash of the idempotency key. It also stamps a retry label. A retried create looks the sandbox up by name first and reuses it. If two attempts race, the loser gets a 409 and adopts the sandbox the winner made, so a retry never makes a twin. A reused sandbox keeps whatever state it is in, includingfailed. A create whosenameis already taken by an unrelated sandbox fails withConflict. specSupport.vcpusandmemoryMBareexact.idleTimeoutMsandmaxAgeMsareapproximate: both round up to whole seconds, and the session budget restarts on every start or resume.diskMB,shmMBandgpuarerejected.limits. Up to 30metadataentries (Archil allows 32, and the adapter keeps two labels for retries and private previews). Keys are at most 63 characters from letters, digits and. _ / : -. Values are at most 256 bytes, so multi-byte text hits the limit sooner than the character count suggests. Timeouts are whole seconds (idleTimeoutStepMsandmaxAgeStepMsare 1000).maxAgeMsbelow 60 s or above 24 h andidleTimeoutMsabove 24 h are rejected withValidation, not adjusted.sizes. Archil sizes are free-form, so there are no fixed tiers. Thesizepresets expand tosmall1 vCPU / 2 GB,medium2 vCPU / 4 GB,large4 vCPU / 8 GB andxlarge8 vCPU / 16 GB, with no disk size because the disk grows with its contents. Fields you set inresourcesoverride the preset.
How the spec maps
| sbox field | Archil behavior |
|---|---|
name | Unique sandbox name, 1-63 lowercase letters, digits or dashes. |
env, inline environment secrets | Creation environment. Conflicting values reject. |
metadata | AND-matched labels, up to 32 including adapter retry/privacy labels. Keys are 1-63 valid characters; values are at most 256 bytes. |
resources.vcpus, memoryMB | 1-32 integer CPUs and 256-65536 MiB. |
size | Expands to vcpus and memoryMB only; see the create contract above. |
region | Regional SDK client for creation. Use the same factory region when reconnecting or listing. |
lifecycle.idleTimeoutMs | Idle TTL in seconds, rounded up. Zero disables idle expiry. |
lifecycle.maxAgeMs | Session TTL of 60 seconds to 24 hours, rounded up. This resets after start/resume, unlike an absolute age limit. Free accounts cap sessions at 30 minutes. |
lifecycle.onIdle | pause preserves memory; destroy maps to delete. stop rejects. The action applies to both TTLs. |
lifecycle.autoResume | true accepts Archil's automatic wake on authenticated ingress; false rejects. |
network | Creation-time egress policy, domain/CIDR allow and deny rules, inline header injection. |
volumes | Existing Archil disks, absolute mount paths, optional read-only mounts. |
ports | Public ports at creation; omitted from public exposure with previewVisibility: "private". |
idempotencyKey | Deterministic name when unnamed, with a retry label to distinguish retries from unrelated named creates. Concurrent name conflicts converge on the same sandbox. |
fromSnapshot, GPU, diskMB, shmMB, named vault secrets | Reject before creation. |
The internal _sbox_archil_private and _sbox_archil_retry labels are reserved and omitted from returned metadata. getOrCreate() looks up the exact native name in the requested region, reuses sandboxes created with create(), resumes paused or stopped matches, and reconnects to a concurrent name-conflict winner. Deleting sandboxes keep the name reserved and return Conflict. Ordinary create() only reuses matches with the same retry key. list() relies on the SDK's complete cursor pagination, then applies state, metadata and result limits. getInfo() refreshes live state.
Images
Archil prepares public or private x86-64 OCI images. It cannot build Dockerfiles or customize an image's environment, workdir, user, start command or readiness command through this API.
const image = await client.templates!.build({
source: { image: "python:3.13" },
resources: { vcpus: 2, memoryMB: 2048 },
});
const sandbox = await client.create({ template: image });
await sandbox.destroy();templateBuild is emulated. The provider API has no image aliases or cache-key labels. Name/cache-key lookup and cache hits last for this provider instance; save the returned image ID for reuse across processes. Native image IDs take precedence over local cache keys and names; cache keys take precedence over names. A name cannot replace an image identity or another build's cache entry. Lookup by an uncached image ID checks the account's actual image before falling back to local keys. There is no image list or delete API in disk 1.15.1. Build events report building and ready; the SDK does not stream build logs. Mutable image tags may rebuild on a later process's first call. Registry credentials pass to images.build() and are not written into a sandbox.
Previews and browser auth
ports.expose(port) exposes a public HTTPS route. For a private route:
const preview = await sandbox.ports!.expose(3000, { visibility: "private" });
if (preview.auth?.type === "header") {
const response = await fetch(preview.url, { headers: preview.auth.headers });
}Private previews use auth: { type: "header", headers: { "X-Archil-Token": token } }. The default token TTL is one hour; set portTokenTtl on the factory to change it. Browsers cannot supply this header on a WebSocket, so previewBrowserAuth is false. Use a trusted backend proxy or Archil's Node-only disk/tunnel helper for browser access. Do not put the token in a query string.
Requesting privacy first removes explicit public exposure and rejects if a service still publishes the port. Each private expose issues a new token and revokes this handle's previous token. Port changes on the same handle are serialized per port, including overlapping exposes and unexposes. ports.list() returns public routes and this handle's still-valid private previews; existing token secrets cannot be retrieved after reconnect. ports.unexpose() removes explicit exposure and revokes all tokens for the port, including tokens created by other connections. Established connections can remain open. If a service still publishes the port, it reports Conflict and the service must be disabled separately.
previewVisibility: "private" persists an adapter label and keeps future expose calls private, including after reconnect and fork.
Files, exec and terminals
Native files.uploadFile and downloadFile transfer binary data in chunks through the SDK. Upload accepts stream bodies; buffered reads allocate space for the complete file. Directory listing, stat, rename, mkdir and remove use the core's quoted shell helpers and require standard Linux utilities in the image. There is no native file watcher.
Commands use the SDK's binary output iterator with independent UTF-8 decoders for stdout and stderr. Exit codes come from the process result. cwd, env, stdin, PTY size and command timeout pass through; timeout milliseconds round up to seconds, with the core's additional timeout backstop. Commands always use the image's default user; per-command user rejects. Kill uses the provider's process-kill operation, not a sandbox stop; arbitrary signals are unavailable. Spawn returns a process handle immediately, and process reattachment uses attach. The SDK has no process-list API. PTY output merges into stdout, as expected for terminals.
Lifecycle, forks and volumes
Pause preserves memory and processes. Stop preserves disks and discards memory. Resume refreshes live state and selects resume for paused sandboxes or start for stopped ones. IDs remain stable.
destroy() stops a running or paused sandbox before deleting its root disk, and tolerates an already missing sandbox. It first destroys forks created through this handle. Other child forks must be deleted before their parent; the provider's Conflict is retained instead of deleting unknown sandboxes. Additional mounted disks survive sandbox deletion.
Forks preserve the source's labels and state. Archil refuses to fork a running or paused sandbox with mounted disks; stop it first. Multiple forks run sequentially because forking briefly pauses the source. If a later fork fails, the adapter attempts cleanup of earlier forks from that call.
client.volumes manages Archil disks through create, get by ID/name, complete paginated list, and delete. Disks grow with their contents; fixed sizeMB requests reject. Region-specific volumes must be accessed with a provider configured for that region. Disk deletion is permanent and remains subject to provider dependency checks.
Egress and other limits
Custom firewall policies and credential brokering require a paid Archil plan. The Free plan enforces Archil's managed allowlist and rejects custom policies with HTTP 403. Injection supports inline strings or secret values; named secret references reject. In allow-list mode, injection domains must also be explicitly allowed. Deny rules require allow-all mode. Header injections for the same exact domain merge; conflicting header values reject. Multiple different injection selectors involving a wildcard reject because Archil applies only its first matching rule. Domain rules also block connections without a hostname unless an IP/CIDR rule allows them. Network updates apply to new connections, leaving existing ones open.
Standalone snapshots, GPU, runtime metrics, code interpreter kernels, vault secrets and programmatic SSH credentials are unsupported. Disk checkpoints remain bound to a sandbox and cannot implement independent snapshot restore. The archil sandbox ssh CLI installs/configures OpenSSH and relays over the process API; it does not expose a reusable SSH credential endpoint.
No live account or resources are required to import this adapter or run its offline tests. Live conformance uses ARCHIL_API_KEY and optional ARCHIL_REGION; it creates billable sandboxes and must only be run with authorization.
Rivet agentOS
In-process VMs from Rivet agentOS (embedded mode). No credentials, no Docker daemon, no cloud account. Streaming exec with stdin and signals, a PTY, a stateful code interpreter for Python, JavaScript and TypeScript, and filesystem snapshots, via @rivet-dev/agentos-core.
Microsandbox
Local libkrun microVMs with native command streams, PTY, files, retained jobs, memory snapshots and forks. Beta; Node 22 or newer.