Agent37
Always-on Linux instances from Agent37 that sleep when idle and wake on the next request. Signed previews, fork, disk snapshots, egress allow lists and Dockerfile builds, over the REST API with no SDK.
Installation
No provider SDK required: the adapter talks to the Agent37 REST API with fetch (pass fetch in the options to inject your own, for tests or proxies).
pnpm add sbox-sdkAuthentication
An Agent37 workspace API key.
| Option | Env var | Required | Description |
|---|---|---|---|
apiKey | AGENT37_API_KEY | required | Workspace key, `sk_live_…` (Dashboard → Cloud API → API keys). Read from AGENT37_API_KEY when omitted. |
instanceType | AGENT37_INSTANCE_TYPE | optional | Instance type: "default", "vm" (own kernel, 2.5x compute) or "performance" (reserved cores, 4x). |
region | AGENT37_REGION | optional | Default region: "us" (default), "eu" or "ap-south" (the last two run vm and performance only). |
One `sk_live_` workspace key covers both planes: the adapter sends it as `Authorization: Bearer` to api.agent37.com and as `X-Agent37-Key` to exec and preview URLs on agent37.app. Creating an instance needs one day of its running rate in the workspace wallet.
Create a key at agent37.com/dashboard/cloud/api-keys. The key goes to the control plane (https://api.agent37.com/v1) as a bearer token and to the exec plane (https://sandbox.agent37.app) as X-Agent37-Key. A create needs a funded workspace (Agent37 checks for one day of the instance's running rate). client.verify() calls GET /v1/billing and creates nothing.
Quickstart
import { createSandboxClient } from "sbox-sdk";
import { agent37 } from "sbox-sdk/agent37";
const client = createSandboxClient({
provider: agent37({ apiKey: process.env.AGENT37_API_KEY! }),
});
const sandbox = await client.create({
resources: { vcpus: 2, memoryMB: 4096 },
lifecycle: { idleTimeoutMs: 15 * 60_000, onIdle: "pause" },
metadata: { team: "agents" },
});
const res = await sandbox.commands.run("node -v");
console.log(res.stdout);
await sandbox.destroy();template defaults to agent37-base, which runs commands as node. resources picks the smallest documented shape that fits (2/4, 4/8, 4/16 or 4/32 vCPU/GB; 8/64 needs instanceType: "vm" or "performance").
How it maps
| Spec field | Agent37 API |
|---|---|
template / fromSnapshot | template (a template name, or name@revision from a snapshot) |
env / secrets with value | env (Agent37 has no secret store, so secret values become env vars) |
metadata | metadata (filtered client-side on list) |
resources | cpu / memory / disk in GB (rounded up to a documented shape) |
region | region (eu and ap-south need vm or performance) |
network | network: allow-all, deny-all or { allow: [...] } |
previewVisibility: "public" | public_ports from spec.ports |
lifecycle.idleTimeoutMs | auto_sleep + idle_timeout_seconds (300 to 86400 s) |
lifecycle.onIdle: "destroy" | auto_delete_seconds: 3600 (the minimum) |
idempotencyKey | sbox-idem metadata; a retried create returns the existing instance |
gpu, volumes and lifecycle.maxAgeMs are rejected with a Validation error: Agent37 has no GPUs, no volume API and no wall-clock TTL.
Create contract
- Idempotency is
best-effort. Agent37 has no idempotency key, so the adapter stores the client's key insbox-idemmetadata (hidden fromgetInfo()). A retried create lists instances first and returns the one carrying that key, waiting for it to reachrunning. A retry that races a still-in-flight first attempt can still make a second instance. An earlier attempt's instance that endedfailedis deleted before the retry creates a new one. - No orphans on a failed create.
POST /v1/instancesanswers once the instance isrunning. If an instance (or a fork) instead has to be polled and endsfailed, times out (waitTimeoutMs, default 15 minutes) or the call is aborted, the adapter deletes it before throwing, since the caller never sees its id. - Sizing is approximate. Agent37 only accepts fixed shapes: 2/4, 4/8, 4/16 and 4/32 vCPU/GB, plus 8/64 on
vmandperformanceinstances.vcpusandmemoryMBare rounded up to the smallest shape that fits both (asking for more than every shape throwsValidation).diskMBis rounded up to whole GB, at least 2 GB; each shape has its own maximum, and Agent37 rejects disk above it. WithoutdiskMB, Agent37 picks the shape's default disk. - Idle timeout is approximate.
idleTimeoutMsturns on auto-sleep (never a stop): it is rounded up to whole seconds and clamped to 300-86400 s, so anything under five minutes becomes five minutes and anything over a day becomes a day.onIdle: "destroy"also setsauto_delete_secondsto Agent37's minimum, one hour after the instance falls asleep. - Rejected fields.
gpu/gpuCountandlifecycle.maxAgeMsthrowValidationbefore any request.shmMBis ignored (Agent37 has no setting for it), sostrictSpecturns it into an error. - Limits.
minIdleTimeoutMs: 300000,idleTimeoutStepMs: 1000, andmaxPorts: 50(Agent37's cap on public ports per instance). Metadata has no entry limit, only a 4 KB cap on the serialized object, so no label limits are declared. - Sizes.
spec.sizemaps onto the native shapes:small2 vCPU / 4 GB,medium4 / 8 GB,large4 / 16 GB,xlarge4 / 32 GB. Disk is left to the shape default.
Exec and files
- Exec is buffered: the response arrives once the command exits, with at most 512 KB per stream (
truncatedis set past that). Undici'sfetchstops waiting for headers after 300 s, so start longer jobs withcommands.spawn()and poll. timeoutMsandkill()find the command by a unique$0marker in/proc/*/cmdlineand SIGKILL its process tree as root.commands.spawn()uses exec'sbackground: true, redirects output to temp files and polls for the exit code.commands.kill(pid)signals the pid over exec.- The files API on the instance URL exists only on agent templates, not on
agent37-base, so files go over exec as base64: reads in 256 KiB chunks (dd), writes in 90 KiB chunks (each chunk must fit Linux's 128 KiB limit for one argument). - Exec has no
cwd/envfields, so the core wraps the command (perCommandEnvCwd: false). Stdin is inlined into the command, so it shares that argument limit.
Previews
Each port gets its own subdomain, https://<id>-<port>.agent37.app.
// Public (default): a public port, no token needed
const pub = await sandbox.ports.expose(3000);
// Private: a signed URL that works in a browser, WebSockets included
const p = await sandbox.ports.expose(3000, { visibility: "private" });
// { url: "https://<id>-3000.agent37.app/?a37_token=…", auth: { type: "signed-url" }, expiresAt }
await sandbox.ports.fetch(3000, "/health"); // sends X-Agent37-Key for youThe edge turns a37_token into a cookie on the first request, so the URL works in an iframe or a new tab (previewBrowserAuth: true). signedUrlTtlSeconds sets the lifetime. ports.unexpose() removes a public port; ports.list() reads the instance's public_ports.
Templates, snapshots and fork
const tpl = await client.templates.build(
{
name: "py-tools",
source: { dockerfile: "FROM python:3.12\nRUN pip install uv" },
},
{ onEvent: (e) => e.type === "log" && console.log(e.line) }
);
const sb = await client.create({ template: tpl });- Dockerfile builds run in Agent37's cloud builder (
/v1/template-builds): the context is uploaded as a gzipped tar, then the adapter polls the build logs and emits them as events. - Image sources register the image directly (
POST /v1/templates). Plain images get a keep-alive entrypoint so the instance stays up; passkeepAlive: falsefor images that run their own long-lived process.readyCmdis not supported. snapshots.create()callsPOST /snapshot, which saves the disk as a workspace template; the ref isname@revision, used withfromSnapshot. It cannot be restored in place, andmode: "memory"throwsNotSupported.fork()copies the disk to a new instance (running processes do not carry over).
Options
Prop
Type
Capabilities
| Capability | Level | Notes |
|---|---|---|
list / region / metrics | native | list has no pagination; metrics are the latest sample |
stop / pause | native | pause = sleep (memory kept, usually) |
background | native | exec background: true |
exposePort / privatePreview | native | signed URLs or public ports |
proxiedFetch | native | X-Agent37-Key on the preview host |
fork / snapshot | native | disk only |
templateBuild | native | Dockerfile (cloud build) or image |
egressControl | native | allow lists only; deny rules and injection are rejected |
filesUpload / killProcess | emulated | over exec |
streaming | unsupported | exec answers once the command exits |
ssh | unsupported | needs your own registered key and the agent37 CLI tunnel |
volumes / secretsVault | unsupported | no volume API; no secret store |
setTimeout | unsupported | no wall-clock TTL |
pty / stdin / gpu | unsupported |
Flags: perCommandEnvCwd: false, preservesMemoryOnPause: true, preservesDiskOnStop: true, previewModel: "subdomain", previewBrowserAuth: true, idempotency: "best-effort". See Create contract for specSupport, limits and sizes.
Limitations
- 512 KB of output per stream per exec call, and a 300 s wait in Node's
fetch. Exec request bodies are capped at 1 MB. - No wall-clock TTL:
maxAgeMsandsetTimeout()are unsupported.onIdle: "destroy"maps to Agent37's minimumauto_delete_secondsof one hour. - A wake usually restores memory but can boot fresh if the instance had to be rebuilt.
- Snapshots and forks copy the disk only.
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.
Maritime
Short-lived Firecracker VMs with native binary files, file watches, private previews, memory snapshots and account template builds.