Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

providers.md

695 lines40.3 KB

1---
2title: Providers
3id: providers
4order: 3
5description: "Pick and configure where a TanStack AI sandbox runs (local process, Docker container, Docker Sandboxes microVM, Daytona, Vercel, Upstash Box, Blaxel, E2B, boxd, or Railway) and what each one can do."
6---
7​
8A provider owns the isolation primitive: where the harness actually runs. Every
9provider implements the same `SandboxProvider` / `SandboxHandle` contract, so the
10[workspace](./workspace) you hand the agent and the [policy](./policy) that guards
11it are provider-agnostic. Pick a provider for the isolation, auth, and
12snapshot/resume behaviour you need; the rest of your sandbox definition stays the
13same.
14​
15Provider-native snapshots and resume keep or recreate provider state. They can
16reduce bootstrap time. [Portable Snapshots](./portable-snapshots) store
17completed workspace data in your application persistence for reconstruction.
18​
19> The provider is _where_ the agent runs. For _which_ agent runs (Grok Build,
20> Claude Code, Codex, OpenCode, or any ACP agent via `acpCompatible`) see
21> [Harnesses](./harnesses).
22​
23## Choosing a provider
24​
25| Provider | Package | Isolation | Notes |
26| --- | --- | --- | --- |
27| Local process | `@tanstack/ai-sandbox-local-process` | none (host) | The fast, no-Docker dev loop. Trusted/dev use only. |
28| Docker | `@tanstack/ai-sandbox-docker` | container | Real isolation; commit-based snapshots, fork, resume-by-id. |
29| Docker Sandboxes (`sbx`) | `@tanstack/ai-sandbox-docker` | microVM | Native Docker Sandboxes. Same package as `dockerSandbox()`, different export: `sbxSandbox()`. Needs the `sbx` CLI, a login, and a hypervisor. |
30| Daytona | `@tanstack/ai-sandbox-daytona` | cloud sandbox | Managed [Daytona](https://www.daytona.io/) sandboxes; snapshots after setup, port preview links, resume-by-id. Needs `DAYTONA_API_KEY`. |
31| Vercel | `@tanstack/ai-sandbox-vercel` | microVM | Managed [Vercel Sandbox](https://vercel.com/docs/sandbox) microVMs; exposed-port domains, resume-by-id (persistent). Needs `VERCEL_TOKEN` + team/project. |
32| Sprites | `@tanstack/ai-sandbox-sprites` | stateful sandbox | Managed [Sprites](https://sprites.dev) (Fly.io) sandboxes; durable filesystem, in-place checkpoints, single proxied public-URL port, resume-by-id. Needs `SPRITES_API_KEY`. |
33| Upstash Box | `@tanstack/ai-sandbox-upstash-box` | cloud sandbox | Managed [Upstash Box](https://github.com/upstash/box) sandboxes; interactive processes over a WebSocket session (real pid, stdin, signals), native snapshots, preview URLs, resume-by-id. Needs `UPSTASH_BOX_API_KEY`. |
34| Blaxel | `@tanstack/ai-sandbox-blaxel` | cloud sandbox | Managed [Blaxel](https://blaxel.ai) sandboxes; durable filesystem, per-port preview URLs, native file watch, resume-by-id. Snapshot/fork remain disabled while the source-scoped private-preview semantics are unproven. Accepts `BL_API_KEY` + `BL_WORKSPACE` or SDK-resolved CLI or client credentials. |
35| E2B | `@tanstack/ai-sandbox-e2b` | microVM | Managed [E2B](https://e2b.dev) Firecracker sandboxes. Native snapshots and fork, preview URLs, writable stdin, process-group kill, resume-by-id (also wakes a paused sandbox). Needs `E2B_API_KEY`. |
36| boxd | `@tanstack/ai-sandbox-boxd` | microVM | Managed [boxd](https://boxd.sh) KVM microVMs; live fork (memory and processes), snapshots that restore into a new machine, persistent disk, resume-by-id across stop, suspend and hibernate, one public HTTPS URL per machine. Needs `BOXD_API_KEY` + `BOXD_ORG`. |
37| Railway | `@tanstack/ai-sandbox-railway` | microVM | Managed [Railway](https://railway.com) sandboxes. Private networking to your other Railway services, live disk fork, environment-scoped checkpoints that survive deletion of their source, durable exec sessions, create-time HTTP domains, resume-by-id. Needs `RAILWAY_API_TOKEN` or `RAILWAY_TOKEN` + an environment. |
38​
39Most providers are their own package. `dockerSandbox()` and `sbxSandbox()` both
40come from `@tanstack/ai-sandbox-docker`. The constructor is the only thing that
41differs between them:
42​
43```ts
44import { localProcessSandbox } from '@tanstack/ai-sandbox-local-process'
45import { dockerSandbox, sbxSandbox } from '@tanstack/ai-sandbox-docker'
46import { daytonaSandbox } from '@tanstack/ai-sandbox-daytona'
47import { vercelSandbox } from '@tanstack/ai-sandbox-vercel'
48import { upstashBoxSandbox } from '@tanstack/ai-sandbox-upstash-box'
49import { blaxelSandbox } from '@tanstack/ai-sandbox-blaxel'
50import { e2bSandbox } from '@tanstack/ai-sandbox-e2b'
51import { boxdSandbox } from '@tanstack/ai-sandbox-boxd'
52import { railwaySandbox } from '@tanstack/ai-sandbox-railway'
53​
54const dev = localProcessSandbox() // runs on your host
55const isolated = dockerSandbox({ image: 'node:22' }) // container
56const microvm = sbxSandbox() // Docker Sandboxes microVM
57const daytona = daytonaSandbox({ apiKey: process.env.DAYTONA_API_KEY }) // managed cloud sandbox
58const vercel = vercelSandbox({ runtime: 'node24' }) // managed Vercel microVM
59const box = upstashBoxSandbox({ apiKey: process.env.UPSTASH_BOX_API_KEY }) // managed Upstash Box
60const blaxel = blaxelSandbox() // managed Blaxel sandbox; uses API-key or CLI credentials
61const e2b = e2bSandbox() // managed E2B microVM; reads E2B_API_KEY
62const boxd = boxdSandbox({ org: 'acme' }) // managed boxd microVM; reads BOXD_API_KEY
63const railway = railwaySandbox() // managed Railway sandbox; reads RAILWAY_TOKEN + RAILWAY_ENVIRONMENT_ID
64```
65​
66> Cloud providers (including Daytona, Vercel, Sprites, Upstash Box, Blaxel, E2B, boxd, and Railway)
67> run remotely. When you drive them from your laptop, [tools](./tools) bridged
68> from `chat()` can't dial your machine's
69> `localhost`, you need the bridge tunnel. See the [tools guide](./tools) for the
70> ngrok subpath, and the [Cloudflare guide](./cloudflare) for the edge-native
71> co-located model.
72​
73## Local process
74​
75```ts
76import { localProcessSandbox } from '@tanstack/ai-sandbox-local-process'
77​
78const dev = localProcessSandbox()
79```
80​
81- **Isolation:** none. The harness runs directly on your host, inheriting your
82 host environment. Use it for trusted or dev work only. There is no boundary
83 between the agent and your machine.
84- **Auth / env:** inherits the host environment. Set `authMode` on the harness
85 (`'host'` or `'api-key'`). The provider does not pick this. See
86 [Harness Auth](./auth).
87- **Snapshot / resume:** no snapshots and no durable resume-by-id; each run
88 re-creates and re-bootstraps under the same identity. The snapshot step is
89 skipped silently (see [Capabilities](#capabilities)).
90​
91### Host login vs API key (`scrubEnv`)
92​
93The provider is where the agent runs, not how it signs in. The default
94`authMode` is `'api-key'`. Set `'host'` when the machine already has a CLI
95login. A local-process run can be your laptop or a GitHub runner. See
96[Harness Auth](./auth).
97​
98`localProcessSandbox` inherits the host environment, including any API keys
99exported there. If you set `authMode: 'host'`, pass `scrubEnv` so those keys
100do not override the CLI login:
101​
102```ts
103import { localProcessSandbox } from '@tanstack/ai-sandbox-local-process'
104​
105const hostLogin = localProcessSandbox({
106 scrubEnv: ['XAI_API_KEY', 'GROK_API_KEY'],
107})
108```
109​
110If the same local-process sandbox runs on a CI machine, set
111`authMode: 'api-key'`. Then inject the key as a workspace secret. Isolated and
112cloud providers have no host CLI login. Use `authMode: 'api-key'` and
113workspace secrets there.
114​
115### Windows process teardown (`logger`)
116​
117Killing a spawned process means killing the whole tree, and on Windows that takes
118more than `taskkill /T`. Commands run through a git-bash `sh`, and MSYS's
119fork emulation runs the final command of a statement list, such as the
120`tail -f` behind a [journal](./journal) follow read, under an intermediate shell
121that immediately exits. Windows never reparents, so the surviving process points
122at a dead parent and `taskkill /T`, which walks only live parent links, cannot
123reach it **while still exiting `0`**. Left alone, every follow read leaks a
124process for the life of the machine.
125​
126`localProcessSandbox` therefore consults MSYS's own process table, which does
127keep the logical parentage before killing, then kills any descendant `/T` missed.
128Teardown is total by construction: it never throws, because a throwing kill would
129strand a run mid-flight. That means a kill it genuinely cannot complete (a
130protected process, access denied) is otherwise invisible, so pass a `logger` to
131see it:
132​
133```ts
134import { localProcessSandbox } from '@tanstack/ai-sandbox-local-process'
135​
136const dev = localProcessSandbox({
137 logger: {
138 warn: (message, meta) => console.warn(message, meta),
139 },
140})
141```
142​
143Any object with a `warn(message, meta?)` method works, so the `InternalLogger`
144your adapter already receives can be handed straight in. A process that had
145already exited on its own is **not** a failure and is never reported.
146​
147Nothing here changes on POSIX, where `sh` really is the command's parent and
148signalling the wrapper is enough.
149​
150## Docker
151​
152```ts
153import { dockerSandbox } from '@tanstack/ai-sandbox-docker'
154​
155const isolated = dockerSandbox({ image: 'node:22' })
156```
157​
158- **Isolation:** a real container boundary between the agent and your host.
159- **Auth / env:** no host login; provide credentials as workspace secrets, which
160 are injected into the container env at create/resume. The agent reaches host
161 tools over `host.docker.internal` (see [tools](./tools)).
162- **Snapshot / resume:** full commit-based snapshots, `fork`, and resume-by-id.
163 Bootstrap snapshots after `setup` completes, so subsequent runs resume from the
164 snapshot instead of re-running setup.
165​
166## Docker Sandboxes (sbx)
167​
168```ts
169import { sbxSandbox } from '@tanstack/ai-sandbox-docker'
170import { defineSandbox, defineWorkspace, githubRepo } from '@tanstack/ai-sandbox'
171​
172const isolated = sbxSandbox({
173 allowNetwork: ['*.npmjs.org', 'registry.npmjs.org'],
174})
175​
176const sandbox = defineSandbox({
177 id: 'repo-agent',
178 provider: isolated,
179 workspace: defineWorkspace({
180 source: githubRepo({ repo: 'owner/repo' }),
181 setup: ['pnpm install'],
182 }),
183})
184```
185​
186- **Isolation:** a hypervisor microVM. The sandbox has its own kernel and its own Docker daemon. This is not `dockerSandbox()`, which starts a container.
187- **Needs:** `sbx` on `PATH`, `sbx login` (or a PAT piped to `sbx login --password-stdin` in CI), and a hypervisor (Hyper-V, Virtualization.framework, or KVM). A Docker socket is not enough.
188- **Workspace:** `sbx create --clone` copies a host Git repo into the VM. Pass `workspaceDir` that contains `.git`, or set `workspace.source` to a git URL. If there is no Git repo, create throws. There is no bind-mount fallback.
189- **Auth / env:** inject API keys as workspace secrets. v1 does not call `sbx secret`.
190- **Snapshot / resume:** no snapshots and no fork. Resume reconnects by name (`sbx ls`). A stopped sandbox starts again on the next `sbx exec`.
191- **Network:** this is the first provider with `networkPolicy: true`. See [Policy](./policy).
192​
193## Daytona
194​
195```ts
196import { daytonaSandbox } from '@tanstack/ai-sandbox-daytona'
197​
198const daytona = daytonaSandbox({
199 apiKey: process.env.DAYTONA_API_KEY,
200 snapshot: 'daytona-medium',
201 autoStopInterval: 0,
202})
203```
204​
205- **Isolation:** a managed cloud sandbox on a remote VM you do not run yourself.
206- **Auth / env:** needs `DAYTONA_API_KEY`. Put harness credentials in
207 [workspace secrets](./provisioning). At create and snapshot restore,
208 Daytona stores each value as an organization Secret and mounts a
209 placeholder in the sandbox env. The create record, the dashboard env
210 view, and session command strings do not contain the real value. Daytona
211 substitutes the value on outbound HTTPS requests. Per-command `opts.env`
212 uses `executeCommand`'s env argument or a sourced env file. It never
213 writes `export KEY=` prefixes into the command string.
214- **Snapshot / resume:** point-in-time snapshots after setup (default when
215 `lifecycle.snapshot` is `'after-setup'`). Pass `snapshot` on
216 `daytonaSandbox()` to pick the Daytona image (for example
217 `'daytona-medium'`). Resume starts a `stopped` or `archived` sandbox, then
218 returns the handle.
219- **Idle stop:** Daytona stops an idle sandbox after 15 minutes by default.
220 Set `autoStopInterval` in minutes to change that. Pass `0` to turn auto-stop
221 off. Set `ephemeral: true` to delete the sandbox when it stops.
222- **Network:** `policy.capabilities.network: 'deny'` blocks all outbound
223 network on create.
224- **Working directory:** the portable root `/workspace` maps to
225 `/home/daytona/workspace` by default. Override with `workdir` on
226 `daytonaSandbox()` if you need another path.
227- **Stdin:** spawned processes accept host stdin (`writableStdin: true`).
228- **Privileges:** the Daytona user is not root. Package installs in `setup`
229 must use `sudo -n` (for example `sudo -n apt-get install …`). Do not put
230 `sudo *` in a [policy](./policy) deny list for this provider.
231- **Bridge:** the sandbox is remote, so a [bridged tool](./tools) call cannot
232 reach your laptop's `localhost`. In local dev, tunnel the bridge (see
233 [tools](./tools)). A deployed orchestrator is reachable without a tunnel.
234​
235Default headless path on Daytona:
236​
237```ts
238import { chat } from '@tanstack/ai'
239import { grokBuildText } from '@tanstack/ai-grok-build'
240import {
241 defineSandbox,
242 defineSandboxPolicy,
243 defineWorkspace,
244 gitSkill,
245 githubRepo,
246 withSandbox,
247} from '@tanstack/ai-sandbox'
248import { daytonaSandbox } from '@tanstack/ai-sandbox-daytona'
249​
250const sandbox = defineSandbox({
251 id: 'daytona-agent',
252 provider: daytonaSandbox({
253 apiKey: process.env.DAYTONA_API_KEY,
254 snapshot: 'daytona-medium',
255 }),
256 workspace: defineWorkspace({
257 source: githubRepo({ repo: 'owner/app' }),
258 skills: [gitSkill({ repo: 'owner/skills-pack' })],
259 }),
260 policy: defineSandboxPolicy({
261 default: 'allow',
262 }),
263})
264​
265const stream = chat({
266 adapter: grokBuildText('grok-build'),
267 messages: [{ role: 'user', content: 'List the project files.' }],
268 middleware: [withSandbox(sandbox)],
269})
270```
271​
272Headless Grok Build and Codex stay on auto-approve with `default: 'allow'`.
273Isolation is the Daytona VM. Use Claude Code when you need command-level deny.
274​
275## Vercel
276​
277```ts
278import { vercelSandbox } from '@tanstack/ai-sandbox-vercel'
279​
280const vercel = vercelSandbox({ runtime: 'node24' })
281```
282​
283- **Isolation:** a managed microVM (Vercel Sandbox).
284- **Auth / env:** needs `VERCEL_TOKEN` plus a team/project. Harness credentials
285 are injected as workspace secrets.
286- **Snapshot / resume:** persistent resume-by-id with a durable filesystem, plus
287 exposed-port domains for previews.
288- **Bridge:** like Daytona, it is a remote VM, so bridged tools need the tunnel in local
289 dev (see [tools](./tools)).
290​
291## Sprites
292​
293```ts
294import { spritesSandbox } from '@tanstack/ai-sandbox-sprites'
295​
296const sprites = spritesSandbox({ apiKey: process.env.SPRITES_API_KEY })
297```
298​
299- **Isolation:** a managed [Sprites](https://sprites.dev) stateful sandbox
300 (Fly.io), a remote VM you do not run yourself.
301- **Auth / env:** needs `SPRITES_API_KEY` (token form
302 `org/projectNumber/tokenId/secret`); override the control-plane URL with
303 `apiUrl` / `SPRITES_API_URL`. Harness credentials are injected as workspace
304 secrets.
305- **Snapshot / resume:** resume-by-id reconnects to the named Sprite (its
306 filesystem is durable across idle suspend/resume). `snapshot()` creates a
307 Sprite **checkpoint** (a save point of the writable overlay); restore is
308 **in-place** on the same Sprite via the handle's `restoreCheckpoint()` /
309 `listCheckpoints()`. A checkpoint does not survive Sprite deletion, so the
310 provider intentionally does **not** implement the reconstruct-after-gone
311 `restoreSnapshot`, when a Sprite is gone the framework degrades to a fresh
312 create instead. Restore restarts the environment and can take minutes;
313 `restoreCheckpoint()` polls the workspace until it is listable again before
314 resolving. Note that immediately after a restore the overlay can be listable
315 while individual file reads briefly return an I/O error as it settles, so retry
316 reads if you act on the filesystem the instant restore returns.
317- **Ports:** a Sprite proxies a single internal HTTP port (default `8080`,
318 configurable via `httpPort`) to its always-on public URL. `ports.connect(8080)`
319 switches the URL to `public` auth and returns it; other ports are not exposed.
320- **Bridge:** like Daytona and Vercel, it is a remote VM, so bridged tools need the tunnel in
321 local dev (see [tools](./tools)).
322​
323## Upstash Box
324​
325```ts
326import { upstashBoxSandbox } from '@tanstack/ai-sandbox-upstash-box'
327​
328const box = upstashBoxSandbox({ apiKey: process.env.UPSTASH_BOX_API_KEY })
329```
330​
331- **Isolation:** a managed [Upstash Box](https://github.com/upstash/box) cloud
332 sandbox, a remote container you do not run yourself.
333- **Auth / env:** needs `UPSTASH_BOX_API_KEY` (or `apiKey`); override the API
334 base with `baseUrl` / `UPSTASH_BOX_BASE_URL`. Pick the image and size with
335 `runtime` (default `node`) and `size`.
336- **Paths:** the conventional `/workspace` virtual root maps to the box home,
337 `/workspace/home`, which is the handle's `workspaceRoot`.
338- **Processes:** `spawn()` opens a live `exec.session` over a WebSocket, so a
339 background process has a real in-box pid, a writable stdin, separate stdout and
340 stderr, and server-side signals. A session owns its process: dropping the
341 connection kills the command and sessions cannot be reattached, so `spawn()` is
342 scoped to the lifetime of the handle rather than the box. Blocking `exec()`
343 stays on the HTTP path and is shell-wrapped for `cwd`/env, which the session
344 takes natively.
345- **Snapshot / resume:** `snapshot()` calls `box.snapshot()` and
346 `restoreSnapshot()` reconstructs a new box from it via `Box.fromSnapshot()`, so
347 a snapshot survives deletion of the box that made it. Resume-by-id uses
348 `Box.get` (id or name) and probes `getStatus`, so a deleted record resumes as
349 `null` rather than a tombstone handle.
350- **Ports:** `ports.connect(port)` mints a preview URL via `getPublicURL`. Pass
351 `publicUrlAuth` to gate it, `{ bearerToken: true }` returns a token plus an
352 `Authorization: Bearer` header and `{ basicAuth: true }` returns Basic
353 credentials; without it the preview URL is unauthenticated.
354- **Network:** a `policy.capabilities.network` of `'deny'` maps to Box's
355 `deny-all` egress mode. The contract's gate is coarse, so Box's domain and CIDR
356 allowlists are not reachable through it. This is stricter than providers that
357 model deny as an allowlist: `deny-all` blocks every outbound connection, so an
358 agent that works under an allowlist-style deny will not reach package
359 registries or model provider hosts here. Leave the capability unset if the
360 agent needs either.
361- **Fork:** `fork()` snapshots the box and creates a new one from that snapshot,
362 the same shape as Docker's commit plus create. It costs a full snapshot round
363 trip (about 25 seconds), unlike Docker's local commit.
364- **Bridge:** like Daytona and Vercel, it is a remote VM, so bridged tools need
365 the tunnel in local dev (see [tools](./tools)).
366​
367## Blaxel
368​
369```ts
370import { blaxelSandbox } from '@tanstack/ai-sandbox-blaxel'
371​
372const blaxel = blaxelSandbox({
373 apiKey: process.env.BL_API_KEY,
374 workspace: process.env.BL_WORKSPACE,
375})
376```
377​
378- **Isolation:** a managed [Blaxel](https://blaxel.ai) cloud sandbox — a remote VM
379 you don't run yourself. Pick the image with `image` (default
380 `blaxel/base-image:latest`) and the size with `memory` (default 2048 MB). Set
381 `region` (or `BL_REGION`) to choose a region and to silence the SDK's warning
382 that it will become required.
383- **Auth / env:** Pass `apiKey` and `workspace` as constructor options, or set `BL_API_KEY` and `BL_WORKSPACE`. If you omit the API key, the provider uses the SDK CLI login or client credentials. A requested workspace must match those credentials. `@blaxel/core` authentication is process-global. The provider records the resolved workspace at construction and rejects a later provider that asks for a different workspace.
384- **Lifetime:** created sandboxes carry a `1h` TTL by default so an abandoned run
385 cannot strand a paid sandbox. Override with `ttl`, or pass `ttl: null` to manage
386 lifetime yourself.
387- **Resume:** resume-by-id reconnects to the named sandbox, and its filesystem
388 is durable across idle suspend/resume for the sandbox's lifetime. Blaxel's
389 snapshot/fork API is currently a source-scoped private preview, has no
390 entitlement probe, and does not document snapshots surviving source deletion.
391 The framework requires `snapshots` to reconstruct after the source is gone, so
392 this provider conservatively advertises both `snapshots` and `fork` as `false`
393 and does not expose `restoreSnapshot`.
394- **Ports:** `ports.connect(port)` creates a per-port preview URL. Previews are
395 token-gated by default and the returned channel carries both the token and the
396 ready-to-send `X-Blaxel-Preview-Token` header. Set `publicPreviews: true` for
397 unauthenticated URLs.
398- **Files:** `fs.watch()` is native, so file-event and diff hooks work without polling. `fs.lstat()` reports file, directory, and symlink metadata without following links; missing paths return `undefined`, while other errors propagate. Custom images must provide GNU `stat`.
399- **Process output:** stdout and stderr remain live-streamed through bounded
400 remote capture pipelines. Concurrent stdout and stderr use labeled records on
401 one transport stream, including across keepalive boundaries. Each stream has an 8 MiB total limit; exceeding it
402 fails and remotely reaps the process instead of accumulating unbounded logs in
403 the provider host. Cancellation uses the same process-group supervisor because
404 the pinned SDK does not prove named-process kill reaches child processes.
405 Custom images must provide Bash plus `cat`, `mkfifo`, `dd`, `base64`, `tr`,
406 and `wc` (the default Blaxel base image does). The supervisor invokes Bash
407 explicitly so job-control process groups do not depend on the image's
408 `/bin/sh` implementation.
409- **Resume semantics:** a destroyed sandbox does not disappear immediately —
410 Blaxel keeps the record in a teardown state before purging it. `resume()`
411 treats deleting, deactivating, failed, and terminated records as gone, while a
412 `DEACTIVATED` sandbox remains resumable consistently with the pinned SDK.
413- **Bridge:** like Daytona/Vercel, a remote VM — bridged tools need the tunnel in
414 local dev (see [tools](./tools)).
415​
416## boxd
417​
418```ts
419import { boxdSandbox } from '@tanstack/ai-sandbox-boxd'
420​
421const boxd = boxdSandbox({
422 apiKey: process.env.BOXD_API_KEY,
423 org: 'acme',
424 vcpu: 2,
425})
426```
427​
428- **Isolation:** a managed [boxd](https://boxd.sh) KVM microVM, a remote VM
429 you do not run yourself. Every machine is created `isolated`: no in-VM
430 `boxd` CLI, no metadata endpoint, no org integrations, and no peers on the
431 org network. The image is Ubuntu 24.04 with Node 24, Python 3, git, Docker,
432 and the Claude Code and Codex CLIs preinstalled.
433- **Auth / env:** needs `BOXD_API_KEY` (or `apiKey`) and the org the key
434 belongs to (`org` or `BOXD_ORG`). Override the endpoint with `baseUrl` /
435 `BOXD_BASE_URL`. Harness credentials are injected as workspace secrets and
436 travel as per-command env. The API key never enters the machine.
437- **Size:** pick `vcpu` (`1`, `2`, or `4`). boxd resolves memory from it:
438 4, 8, or 16 GiB. The default is the org's default size. Every machine has a
439 100 GB disk.
440- **Working directory:** the portable root `/workspace` maps to
441 `/home/boxd/workspace`. Override with `workdir`.
442- **Cancellation:** if you abort create or snapshot restore during startup,
443 the provider tries to delete the new machine after the current SDK call
444 finishes.
445- **Processes:** `spawn()` opens a streaming exec with separate stdout and
446 stderr and a writable stdin. `kill()` signals the process group inside the
447 machine and verifies that it is gone, so `killableProcesses` is measured,
448 not assumed.
449- **Snapshot / resume:** `snapshot()` captures memory and disk into a boxd
450 snapshot named `<machine>-<label>` and waits until it is restorable (about
451 25 s for an 8 GiB machine). `restoreSnapshot()` boots a new machine from it
452 in about 1 s, with the captured processes still running. Resume-by-id
453 reconnects to the same machine across stop (2 to 3 s to start), suspend
454 (about 140 ms) and hibernate.
455- **Fork:** `fork()` is a live boxd fork: disk, memory and running processes,
456 ready in under a second.
457- **Lifetime:** a machine is persistent until `destroy()`. It suspends after
458 `autoSuspendTimeout` idle seconds and hibernates after 4 hours idle by
459 default, at no compute cost, and wakes on the next command. Idle means no
460 inbound connection. Set `autoDestroyTimeout` as a safety net for abandoned
461 sandboxes. `stop` is a power-off: a file written seconds before it can still
462 sit in the page cache and be lost, so run `sync` before you stop a machine
463 yourself. Suspend, hibernate, snapshot and fork keep memory, so they do not
464 lose it.
465- **Ports:** every machine has one public HTTPS URL, `https://<name>.boxd.sh`.
466 `ports.connect(port)` pins that URL to `port` and returns it. The URL is
467 public: anyone who has it can reach the port.
468- **Golden image:** pass `fromSnapshot` to boot every new sandbox from a
469 snapshot you baked after `setup`, instead of the default image. The size is
470 then fixed by the snapshot.
471- **Bridge:** like the other cloud providers, it is a remote VM, so bridged
472 tools need the tunnel in local dev (see [tools](./tools)).
473​
474## E2B
475​
476```ts
477import { e2bSandbox } from '@tanstack/ai-sandbox-e2b'
478​
479const e2b = e2bSandbox({ apiKey: process.env.E2B_API_KEY })
480```
481​
482- **Isolation:** a managed [E2B](https://e2b.dev) sandbox, a Firecracker microVM
483 you do not run yourself. Pick the image with `template` (default: the E2B
484 `base` template).
485- **Auth / env:** needs `E2B_API_KEY` (or `apiKey`). Set `domain` (or
486 `E2B_DOMAIN`) for a self-hosted or BYOC deployment. Harness credentials are
487 injected as [workspace secrets](./provisioning). At create and snapshot
488 restore they are sent as sandbox `envs`. Per-command `env` goes through the
489 SDK's native `envs` argument. No value is written into a command string.
490- **Lifetime:** a sandbox lives for `timeoutMs` (default 30 minutes) and is
491 killed when that time elapses, so an abandoned run cannot keep billing.
492 Resume extends the lifetime by the same amount. Set `onTimeout: 'pause'` to
493 keep a timed-out sandbox resumable instead. E2B caps the lifetime at 1 hour
494 on the Hobby plan and 24 hours on Pro.
495- **Snapshot / resume:** `snapshot()` calls `createSnapshot()`. The sandbox is
496 paused briefly, then resumed. `restoreSnapshot()` creates a new sandbox from
497 that snapshot, so a snapshot survives deletion of its source. Resume-by-id
498 uses `Sandbox.connect`, which also wakes a paused sandbox. A killed or
499 expired sandbox resumes as `null`.
500- **Fork:** `fork()` is native. The parent is checkpointed in place and the copy
501 boots from that checkpoint.
502- **Processes:** every command runs as the leader of its own process group
503 (`setsid`), so `kill()` reaches backgrounded children. `kill()` always sends
504 `SIGKILL`. `spawn()` has a real sandbox pid, a writable stdin, and separate
505 stdout and stderr. A custom template must include `setsid` (util-linux); the
506 default template has it.
507- **Ports:** `ports.connect(port)` returns
508 `https://<port>-<sandbox-id>.<domain>`. With `allowPublicTraffic: false` the
509 URL is gated by the `e2b-traffic-access-token` header, and the channel carries
510 that header in `headers`. Browsers cannot send it, so leave public traffic on
511 for preview links a person clicks.
512- **Network:** `policy.capabilities.network: 'deny'` maps to
513 `allowInternetAccess: false`, which blocks all outbound traffic. E2B's
514 per-host allow and deny lists are not reachable through the contract's coarse
515 gate.
516- **Paths:** the portable root `/workspace` maps to `/home/user/workspace` by
517 default. Override with `workdir`. The sandbox user is `user` (not root) with
518 passwordless `sudo`, and `/workspace` itself is not writable.
519- **Bridge:** like Daytona and Vercel, it is a remote VM, so bridged tools need
520 the tunnel in local dev (see [tools](./tools)).
521​
522## Railway
523​
524```ts
525import { railwaySandbox } from '@tanstack/ai-sandbox-railway'
526​
527const railway = railwaySandbox({
528 environmentId: process.env.RAILWAY_ENVIRONMENT_ID,
529 region: 'us-west2',
530 idleTimeoutMinutes: 30,
531 resources: { cpu: 2, memoryGB: 4 },
532 // Optional: publish preview domains. Requires PRIVATE networking.
533 networkIsolation: 'PRIVATE',
534 ports: [3000],
535})
536```
537​
538- **Isolation:** a managed [Railway](https://railway.com) sandbox, a VM you do
539 not run yourself, created in a Railway environment. Boot from the base image,
540 a named `checkpoint`, or a `Sandbox.template()` recipe (`template`).
541- **Auth / env:** the SDK reads `RAILWAY_TOKEN` (a project token) or
542 `RAILWAY_API_TOKEN` (an account or workspace token). An explicit `token`
543 defaults to bearer auth; pass `authType: 'project-token'` for a project
544 token. Scope is the environment (`environmentId` or
545 `RAILWAY_ENVIRONMENT_ID`), frozen per provider. Harness credentials are
546 injected as [workspace secrets](./provisioning): at create and restore they
547 are sent as the sandbox's runtime `env`, and per-command `env` travels in the
548 exec init frame. No value is written into a command string.
549- **Private networking:** with `networkIsolation: 'PRIVATE'` the sandbox joins
550 the environment's private network, so the agent can reach your other Railway
551 services (databases, internal APIs) by their private hostnames. The default,
552 `ISOLATED`, has no private-network access.
553- **Lifetime:** Railway destroys a sandbox after `idleTimeoutMinutes` of
554 inactivity (plan default when omitted; `0` disables idle destruction where
555 the plan allows it). There is no stop/start that keeps the disk, so
556 `durableFilesystem` is `false`: use a checkpoint or
557 [Portable Snapshots](./portable-snapshots) to keep work across idle expiry.
558 `SandboxCreateInput` carries no lifecycle hint, so set the timeout here.
559 Resume resets the idle countdown.
560- **Size:** `resources: { cpu, memoryGB }` sets vCPU (fractions allowed) and
561 memory in decimal GB for every create, restore, and fork. Omitted fields use
562 the workspace default; values above its maximum fail at create.
563- **Snapshot / resume:** `snapshot(label)` captures a native Railway checkpoint
564 named `tsai-<sandbox-id>-<uuid>`. The label stays on the returned ref only,
565 because checkpoint names are environment-scoped and a capture replaces an
566 existing name. Checkpoints belong to the environment, not the sandbox, so
567 `restoreSnapshot()` boots a new sandbox from one after its source is
568 destroyed, and reapplies env, network mode, domains, and idle timeout from
569 the provider config. Restores and forks run in the source region, so
570 `region` applies to fresh sandboxes only. Checkpoints count
571 against a per-plan quota and the contract has no delete hook: prune
572 `tsai-*` checkpoints you no longer reference with `Sandbox.checkpoints()`
573 and `Sandbox.deleteCheckpoint()` from the `railway` SDK. Resume-by-id uses
574 `Sandbox.connect`. A missing, `DESTROYED`, `DESTROYING`, or `FAILED` sandbox
575 resumes as `null`, a `CREATING` one is awaited, and auth or transport errors
576 are rethrown.
577- **Fork:** `fork()` is a native live disk fork of the running sandbox into a
578 new one in the same environment and region. Processes are not copied. The
579 fork gets the parent's network mode, domains, idle timeout, and a copy of
580 its env overlay.
581- **Processes:** stdout and stderr stay separate. `spawn()` runs in a durable
582 exec session with a flow-controlled stdin writer, so it keeps running if the
583 host disconnects; this provider does not expose reattach, because TanStack's
584 [run journal](./journal) owns run identity. Blocking `exec` runs without a
585 durable session and is killed if the connection drops. `spawn()` reports
586 `pid: -1` because the exec bridge exposes no remote pid. `kill()` and an
587 aborted `exec` send `TERM` to the process group and escalate to `KILL` after
588 2 s. An aborted `spawn` sends `KILL` at once. All of them settle on the
589 confirmed remote exit. An aborted `exec` resolves with the signalled exit
590 code.
591- **Cancellation:** if create fails or times out after Railway minted the
592 sandbox, or the caller aborts while it boots, the provider tries to destroy
593 it. Both are best effort.
594- **Ports:** Railway publishes HTTP domains at create time only. Declare them
595 with `ports` (at most 10), which requires `networkIsolation: 'PRIVATE'`;
596 `ports.connect(port)` returns `https://<domain>` for a declared port and
597 rejects any other. Without `ports`, the `ports` capability is `false`. The
598 domain is public: it carries no preview token.
599- **Network:** `networkPolicy` is `false`. Both modes keep public internet
600 egress, so `policy.capabilities.network: 'deny'` is rejected at create
601 instead of being dropped.
602- **Paths:** the portable root `/workspace` is a real directory created at
603 boot. Override with `workdir`. `fs.remove` is recursive (`rm -rf`) and
604 `fs.lstat` is a GNU `stat` probe that does not follow symlinks.
605- **Bridge:** like the other cloud providers, it is a remote VM, so bridged
606 tools need the tunnel in local dev (see [tools](./tools)).
607​
608## Capabilities
609​
610Providers declare what they support via `capabilities()`. The flags are:
611​
612| Capability | Meaning |
613| --- | --- |
614| `fs` | Read/write the sandbox filesystem. |
615| `exec` | Run commands. |
616| `env` | Inject environment variables. |
617| `ports` | Expose/forward ports (preview URLs). |
618| `backgroundProcesses` | Keep long-running processes alive between calls. |
619| `writableStdin` | A spawned process exposes a writable host→process stdin. `true` for local-process, Docker container, Daytona, Upstash Box, E2B, boxd, and Railway. `false` for Docker Sandboxes (`sbx`), Vercel, Sprites, Blaxel, and Cloudflare. When `false`, stdin-fed harnesses write the prompt to a file and redirect it in the shell. |
620| `killableProcesses` | A spawned process can be forcibly stopped via `SpawnHandle.kill()` **and** aborted mid-flight via the `signal` passed to `spawn`. |
621| `snapshots` | Capture and restore point-in-time snapshots. |
622| `networkPolicy` | Enforce network allow/deny rules. |
623| `durableFilesystem` | Disk that survives across resumes. |
624| `fork` | Branch a sandbox from an existing one. |
625​
626Code that uses an **optional** capability checks the flag first and degrades
627gracefully. For example, bootstrap only snapshots when `snapshots` is supported,
628so `localProcessSandbox` simply skips the step. Calling an unsupported optional
629method directly (instead of checking the flag) throws an
630`UnsupportedCapabilityError`:
631​
632```ts
633import { localProcessSandbox } from '@tanstack/ai-sandbox-local-process'
634​
635const provider = localProcessSandbox()
636const caps = provider.capabilities()
637​
638if (caps.snapshots) {
639 // safe to take a snapshot
640} else {
641 // degrade gracefully, local-process has no snapshots
643```
644​
645Use the flags to write provider-agnostic code: branch on the capability rather
646than the concrete provider, and your sandbox definition keeps working when you
647swap one provider for another.
648​
649### `killableProcesses` across the bundled providers
650​
651This flag is **measured, not asserted**. A wrong `true` hands the journal reader
652an unstoppable `tail -f` and leaks a process per run, so a provider only declares
653it once killing has been observed to work against a real sandbox. Two of these
654declarations were once `true` on reasoning alone and both turned out to be false
655when probed (Docker's stream destroy left the container-side process in `ps`;
656local-process's `sh -c` did not `exec`, so killing the shell left the command
657alive). Anything that cannot be measured yet stays `false`, because `poll` is
658merely slower while a wrong `follow` is a leak.
659​
660| Provider | `killableProcesses` | Why |
661| --- | --- | --- |
662| Local process | `true` | **Measured.** Kills the process GROUP, not the wrapper: `detached` spawn plus `process.kill(-pid, signal)` on POSIX (killing only the `sh` left the command running, dash does not reliably `exec`); on Windows `taskkill /T` plus a verified sweep, see [Windows teardown](#windows-process-teardown-logger). |
663| Docker | `true` | **Measured.** Signals the process INSIDE the container by the pid the wrapper recorded for itself, process group first and escalating to `KILL`. Destroying the hijacked exec stream is *not* sufficient: it only detaches the client. |
664| Docker Sandboxes (`sbx`) | `false` | Unmeasured. Live tests named-skip until `sbx login`. The handle records a pid in the VM, but `killableProcesses` stays `false` until that kill is observed. |
665| Daytona | `false` | `kill()` only aborts the client-side poll loop and does not await any termination; the `deleteSession` that might terminate the command runs later from the pump's teardown, is failure-swallowed, and is documented as cleanup for a *completed* session. Unmeasured, needs `DAYTONA_API_KEY`. |
666| Vercel | `false` | The abort signal reaches only the HTTP request that STARTS a detached command, so the old `kill()` was a no-op. It now issues the SDK's server-side `Command.kill`, but whether that reaches a forked child (the follow command is a multi-statement shell, so `tail -f` is always a child) is unmeasured, needs Vercel credentials. |
667| Sprites | `true` (unverified) | Not a client-side detach: `kill()` issues a real server-side `POST /exec/<sessionId>/kill` before closing the socket. What that endpoint signals (process group or pid) is undocumented and unmeasured; needs `SPRITES_API_KEY`. |
668| Upstash Box | `true` | **Measured.** `kill()` sends an allowlisted signal (`TERM`/`KILL`/`INT`/`HUP`) that the box agent delivers to the process TREE server-side, so a forked child is signalled too. Verified against production: a spawned `sleep 5 && touch <marker>` was killed and the marker never appeared. Needs `UPSTASH_BOX_API_KEY`. |
669| Blaxel | `true` | The provider reaps supervisor and child process groups, then waits for the remote reaper to finish. Credential-gated journal conformance verifies that cancellation leaves no active follower process. |
670| E2B | `true` | **Measured.** The SDK's own kill is a SIGKILL to the shell pid, and a backgrounded `( … ) & wait` child survived it. Every command therefore runs as a `setsid` group leader and `kill()` runs `kill -KILL -- -<pid>` inside the sandbox. The shared journal conformance kill case passes against a real sandbox. Needs `E2B_API_KEY`. |
671| Cloudflare | `false` | `kill()` is a no-op, and the caller's `AbortSignal` reaches neither `exec` nor `spawn`, because Workers RPC cannot serialize one. |
672| boxd | `true` | **Measured.** The spawn wrapper runs under `setsid`, so the pid it records leads its own process group. `kill()` runs a shell inside the machine that signals that group, escalates to `KILL`, and checks with `kill -0`. Closing the stream alone is not a kill: the process survived it. Verified against production: a spawned `sleep 5 && touch <marker>` was killed and the marker never appeared. Needs `BOXD_API_KEY`. |
673| Railway | `true` | **Measured.** `kill()` and an aborted `exec` send `TERM` to the command's process group and escalate to `KILL` after 2 s. An aborted `spawn` sends `KILL` at once. Each settles only when the remote exit is confirmed. Verified against production: the shared journal conformance kill case passes, and spawned `sleep 5 && touch <marker>` commands (including a backgrounded child) were killed before the marker appeared, for `kill()`, an aborted `exec`, and an aborted `spawn`. Needs `RAILWAY_API_TOKEN` or `RAILWAY_TOKEN` + `RAILWAY_ENVIRONMENT_ID`. |
674​
675Each of the remote providers registers the shared journal conformance suite, so
676the claim is falsifiable rather than asserted: with credentials present the suite
677runs against a real sandbox, and without them it reports a **named skip** carrying
678the reason instead of a silent pass. Cloudflare's gate is the runtime rather than
679credentials, its provider can only create a sandbox through a `Sandbox` Durable
680Object binding, which no Node test process has, so its registration is a named
681skip saying exactly that, until a Workers-runtime harness can measure it.
682​
683This flag is required on every provider, including a bring-your-own one. A
684provider that omitted it would be treated as killable, which is the dangerous
685default: a follower process started there could never be reclaimed, and it would
686keep running inside the sandbox for as long as the sandbox lives.
687​
688It is the flag the [run journal](./journal) reads to decide how to tail a run's
689output: a killable provider gets a streaming `tail -f`, and a provider like
690Cloudflare gets a loop of bounded reads, each of which terminates on its own.
691​
692The flag also bounds what *cancel* can mean. On a `false` provider there is no
693signal path to the agent process, so the only cancel that actually stops the
694agent means destroying the sandbox, which is what the cancel path does. See
695[what cancel means on a provider that cannot kill](./takeover#what-cancel-means-on-a-provider-that-cannot-kill).