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-sdk

Authentication

An Agent37 workspace API key.

Authentication variables for the agent37 adapter.
OptionEnv varRequiredDescription
apiKeyAGENT37_API_KEYrequiredWorkspace key, `sk_live_…` (Dashboard → Cloud API → API keys). Read from AGENT37_API_KEY when omitted.
instanceTypeAGENT37_INSTANCE_TYPEoptionalInstance type: "default", "vm" (own kernel, 2.5x compute) or "performance" (reserved cores, 4x).
regionAGENT37_REGIONoptionalDefault 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 fieldAgent37 API
template / fromSnapshottemplate (a template name, or name@revision from a snapshot)
env / secrets with valueenv (Agent37 has no secret store, so secret values become env vars)
metadatametadata (filtered client-side on list)
resourcescpu / memory / disk in GB (rounded up to a documented shape)
regionregion (eu and ap-south need vm or performance)
networknetwork: allow-all, deny-all or { allow: [...] }
previewVisibility: "public"public_ports from spec.ports
lifecycle.idleTimeoutMsauto_sleep + idle_timeout_seconds (300 to 86400 s)
lifecycle.onIdle: "destroy"auto_delete_seconds: 3600 (the minimum)
idempotencyKeysbox-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 in sbox-idem metadata (hidden from getInfo()). A retried create lists instances first and returns the one carrying that key, waiting for it to reach running. A retry that races a still-in-flight first attempt can still make a second instance. An earlier attempt's instance that ended failed is deleted before the retry creates a new one.
  • No orphans on a failed create. POST /v1/instances answers once the instance is running. If an instance (or a fork) instead has to be polled and ends failed, 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 vm and performance instances. vcpus and memoryMB are rounded up to the smallest shape that fits both (asking for more than every shape throws Validation). diskMB is rounded up to whole GB, at least 2 GB; each shape has its own maximum, and Agent37 rejects disk above it. Without diskMB, Agent37 picks the shape's default disk.
  • Idle timeout is approximate. idleTimeoutMs turns 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 sets auto_delete_seconds to Agent37's minimum, one hour after the instance falls asleep.
  • Rejected fields. gpu/gpuCount and lifecycle.maxAgeMs throw Validation before any request. shmMB is ignored (Agent37 has no setting for it), so strictSpec turns it into an error.
  • Limits. minIdleTimeoutMs: 300000, idleTimeoutStepMs: 1000, and maxPorts: 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.size maps onto the native shapes: small 2 vCPU / 4 GB, medium 4 / 8 GB, large 4 / 16 GB, xlarge 4 / 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 (truncated is set past that). Undici's fetch stops waiting for headers after 300 s, so start longer jobs with commands.spawn() and poll.
  • timeoutMs and kill() find the command by a unique $0 marker in /proc/*/cmdline and SIGKILL its process tree as root.
  • commands.spawn() uses exec's background: 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/env fields, 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 you

The 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; pass keepAlive: false for images that run their own long-lived process. readyCmd is not supported.
  • snapshots.create() calls POST /snapshot, which saves the disk as a workspace template; the ref is name@revision, used with fromSnapshot. It cannot be restored in place, and mode: "memory" throws NotSupported.
  • fork() copies the disk to a new instance (running processes do not carry over).

Options

Prop

Type

Capabilities

CapabilityLevelNotes
list / region / metricsnativelist has no pagination; metrics are the latest sample
stop / pausenativepause = sleep (memory kept, usually)
backgroundnativeexec background: true
exposePort / privatePreviewnativesigned URLs or public ports
proxiedFetchnativeX-Agent37-Key on the preview host
fork / snapshotnativedisk only
templateBuildnativeDockerfile (cloud build) or image
egressControlnativeallow lists only; deny rules and injection are rejected
filesUpload / killProcessemulatedover exec
streamingunsupportedexec answers once the command exits
sshunsupportedneeds your own registered key and the agent37 CLI tunnel
volumes / secretsVaultunsupportedno volume API; no secret store
setTimeoutunsupportedno wall-clock TTL
pty / stdin / gpuunsupported

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: maxAgeMs and setTimeout() are unsupported. onIdle: "destroy" maps to Agent37's minimum auto_delete_seconds of 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.

On this page