Styne

Linux microVMs from Styne, restored from warm pools. Streamed exec with native cwd, env and user, background commands with stdin and signals, pause with memory, named snapshots, fork, volumes, token-gated ports and egress rules you can change live, over Styne's REST API with no peer SDK.

Installation

The adapter calls Styne's sandbox REST API (https://api.styne.ai) with fetch, so it needs no peer dependency and runs on Node 20+, Bun, Deno and edge runtimes.

pnpm add sbox-sdk

It doesn't wrap the official styne-sdk package. That package targets Styne's /v1 API, which has no volumes, no container images on create, and no calls to signal a command, write its stdin, set an absolute timeout or read metrics.

Usage

import { createSandboxClient } from "sbox-sdk";
import { styne } from "sbox-sdk/styne";

const client = createSandboxClient({
  provider: styne({ apiKey: process.env.STYNE_API_KEY! }),
});

const sandbox = await client.create({
  size: "large",
  lifecycle: { maxAgeMs: 30 * 60_000 },
  network: {
    mode: "allow-list",
    domains: ["pypi.org", "files.pythonhosted.org"],
  },
});

for await (const ev of sandbox.commands.run("pip install requests", {
  cwd: "/tmp",
})) {
  if (ev.type === "stdout") process.stdout.write(ev.data);
}

// Memory and disk, under a name that seeds new sandboxes.
const ref = await sandbox.snapshots!.create({ name: "with-requests" });
const copy = await client.create({ fromSnapshot: ref });

// Children copy the running parent, memory included.
const [a, b] = await sandbox.fork({ count: 2 });

Authentication

OptionEnv varRequiredNotes
apiKeySTYNE_API_KEYyesFrom the styne.ai dashboard; sent as Authorization: Bearer
regionSTYNE_REGIONnoash (US East). ams is accepted and served in Ashburn

client.verify() lists one sandbox (GET /sandboxes?limit=1); it never creates anything.

Options

Prop

Type

Spec mapping

SandboxSpec fieldStyne
template (an id or alias, such as base or code)templateID; resources.vcpus / memoryMB become vcpus / memory_mib
template (an image reference such as python:3.12)image: any public image on Docker Hub, ghcr.io or quay.io
template (a ref from client.templates.build())the image or snapshot it names, plus its env, startCmd and readyCmd
fromSnapshotsnapshot (the snapshot name)
size / resources with no templatesmallest fitting size: small 2 vCPU/4 GiB, default 4/8, large 8/16, xlarge 16/32
env, secrets (inline value)envVars
metadata, namemetadata (the name is stored as sbox-name)
lifecycle.maxAgeMs (or idleTimeoutMs, ttlMs)timeout, whole seconds, at most 86 400
lifecycle.idleTimeoutMsalso idleTimeout: the sandbox sleeps after that long without traffic (at most 3600 s)
lifecycle.onIdle: "pause" or "stop", autoResumelifecycle: { onTimeout: "pause", autoResume }
networkallow_internet_access plus network.allowOut / denyOut (hosts, IPs and CIDRs)
volumesvolumeMounts (name is the volume id or name)
regionregion
idempotencyKeyIdempotency-Key header, plus a sbox-idem metadata tag looked up before a retried create
GPUs, secrets without a value or with mode: "egress", network.inject, autoResume without pausing, volumes with onIdle: "pause"rejected with a Validation error

With a template, snapshot or image, the sandbox keeps that source's size, so resources are only sent with a template id.

Styne prepares a container image the first time you boot it and answers 202 until it's ready. The adapter repeats the create, honoring Retry-After, for up to imageWaitMs (10 minutes by default).

Lifecycle and states

pause() keeps memory, running processes and files; resume() (or the next connect) brings the sandbox back with the same id. The pauseTier option picks where a paused sandbox is kept: memory (the default, fastest), standby or archived. setTimeout(ms) sets a new lifetime counted from now. A sandbox with a volume attached can't be paused, snapshotted or forked.

Styne stateSandboxState
starting, resumingcreating
runningrunning
pausingsuspending
pausedpaused
killed or timed outdestroyed

Previews and browser auth

ports.expose(port) makes the port public at https://<port>-<sandbox-id>.<domain>. With { visibility: "private" } the port stays token-gated, and the preview carries auth: { type: "header", headers: { "e2b-traffic-access-token": "<token>" } }. Styne documents a ?token= query only for WebSocket upgrades, so previewBrowserAuth is false. ports.fetch(port, path) calls the port directly with the token, without exposing it. Up to 32 ports per sandbox.

Capabilities

CapabilityLevelNotes
listnativerunning and paused sandboxes; metadata filtered server-side
streamingnativeNDJSON exec stream, stdout and stderr kept separate
background / killProcessnativedetached commands, followed by pid and reattachable; TERM or KILL
stdinnativetext written to a spawned command's stdin
filesUploadnativeraw-byte file API; list, stat, mkdir and rename use the shell
exposePort / privatePreviewnativeper-port public URLs, or the traffic token in a header
proxiedFetchnativerequests to a port with the traffic token
egressControlnativeinternet on or off, allow and deny lists, replaced on a running sandbox
pausenativememory, processes and files kept
setTimeoutnativea new lifetime from now
snapshotnativememory and disk, named; restore() rewinds in place (Pro and Scale plans)
forknative1 to 1000 children of a running sandbox
volumesnativeext4 volumes that outlive sandboxes, 1 to 100 GiB
templateBuildnativepublic images and snapshots; Styne prepares the image on the first create
regionnativeash
metricsnativenewest CPU, memory and disk sample
ptyunsupportedexec takes a PTY, but typing into it needs a streamed request body
stopunsupporteduse pause
codeInterpreter / statefulKernelunsupported
ssh / filesWatch / gpu / secretsVaultunsupported

Flags: perCommandEnvCwd: true, exitCodeNative: true, preservesMemoryOnPause: true, preservesDiskOnStop: false, previewModel: "subdomain", previewBrowserAuth: false, templateSources: ["image", "snapshot"], idempotency: "best-effort", plus the specSupport, limits and sizes values in Create contract.

Create contract

  • Idempotency is best-effort. Every create sends an Idempotency-Key header (sbox-<hash of the key>) and tags the sandbox with the same hash in sbox-idem metadata. A retried create first looks that tag up among running and paused sandboxes and connects to a match. If Styne answers 409 because a create with the same key is still running, the adapter waits for it (up to 60 s) and adopts the sandbox it made instead of failing. Styne doesn't document what it answers to a repeated key once the first request has finished, so this isn't declared exact: a retry that misses the tag (the sandbox is not listed yet, or already gone) can still make a second sandbox. Each 202 image_building repeat sends a fresh key (<key>-<n>), since a 202 made no sandbox.
  • Sizing snaps to Styne's sizes. With no template, vcpus, memoryMB and diskMB pick the smallest size that fits all three, and a request past xlarge throws Validation. With a template id only vcpus and memoryMB are sent: Styne refuses more than the template has and serves the template's size otherwise. A snapshot or image keeps its own size, and resources are not sent.
  • Timeouts are rounded up to whole seconds. maxAgeMs becomes timeout (at most 86 400 s). idleTimeoutMs becomes idleTimeout (at most 3600 s), and also timeout when no maxAgeMs is set, so Styne's 300 s default doesn't end the sandbox first. Longer values throw Validation.
  • Rejected and ignored fields. GPUs throw Validation. shmMB is ignored, so strictSpec: true turns it into a NotSupported error.
  • Limits. At most 32 exposed ports. Styne documents no cap on metadata entries; the adapter reserves sbox-name and sbox-idem.
FieldValue
idempotencybest-effort
specSupport.vcpusapproximate
specSupport.memoryMBapproximate
specSupport.diskMBapproximate
specSupport.shmMBignored
specSupport.gpurejected
specSupport.idleTimeoutMsapproximate
specSupport.maxAgeMsapproximate
limits.maxPorts32
limits.idleTimeoutStepMs1000 (minimum 1000)
limits.maxAgeStepMs1000 (minimum 1000)
sizessmall 2/4/51, medium 4/8/51, large 8/16/111, xlarge 16/32/251 (vCPU / GiB memory / GiB disk); medium is Styne's default

Known limitations

  • client.templates.build() takes { image } (public registries only) or { snapshot }. Dockerfile sources throw NotSupported; workdir, user, template resources and registryAuth throw Validation. Push the image to a public registry and set those in the image instead.
  • killProcess sends SIGTERM or SIGKILL only; other signals throw Validation.
  • stdin is text: bytes that aren't valid UTF-8 are replaced.
  • snapshots.list() is not available, because Styne doesn't document the list answer.
  • The idempotency tag only finds a sandbox that is still running or paused. Styne doesn't document what it answers to a repeated Idempotency-Key once the first request has finished.
  • fork() throws if any child fails to start, after killing the children that did start.

On this page