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

providers.md

602 lines34.0 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, or boxd) 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​
38Most providers are their own package. `dockerSandbox()` and `sbxSandbox()` both
39come from `@tanstack/ai-sandbox-docker`. The constructor is the only thing that
40differs between them:
41​
42```ts
43import { localProcessSandbox } from '@tanstack/ai-sandbox-local-process'
44import { dockerSandbox, sbxSandbox } from '@tanstack/ai-sandbox-docker'
45import { daytonaSandbox } from '@tanstack/ai-sandbox-daytona'
46import { vercelSandbox } from '@tanstack/ai-sandbox-vercel'
47import { upstashBoxSandbox } from '@tanstack/ai-sandbox-upstash-box'
48import { blaxelSandbox } from '@tanstack/ai-sandbox-blaxel'
49import { e2bSandbox } from '@tanstack/ai-sandbox-e2b'
50import { boxdSandbox } from '@tanstack/ai-sandbox-boxd'
51​
52const dev = localProcessSandbox() // runs on your host
53const isolated = dockerSandbox({ image: 'node:22' }) // container
54const microvm = sbxSandbox() // Docker Sandboxes microVM
55const daytona = daytonaSandbox({ apiKey: process.env.DAYTONA_API_KEY }) // managed cloud sandbox
56const vercel = vercelSandbox({ runtime: 'node24' }) // managed Vercel microVM
57const box = upstashBoxSandbox({ apiKey: process.env.UPSTASH_BOX_API_KEY }) // managed Upstash Box
58const blaxel = blaxelSandbox() // managed Blaxel sandbox; uses API-key or CLI credentials
59const e2b = e2bSandbox() // managed E2B microVM; reads E2B_API_KEY
60const boxd = boxdSandbox({ org: 'acme' }) // managed boxd microVM; reads BOXD_API_KEY
61```
62​
63> Cloud providers (including Daytona, Vercel, Sprites, Upstash Box, Blaxel, E2B, and boxd)
64> run remotely. When you drive them from your laptop, [tools](./tools) bridged
65> from `chat()` can't dial your machine's
66> `localhost`, you need the bridge tunnel. See the [tools guide](./tools) for the
67> ngrok subpath, and the [Cloudflare guide](./cloudflare) for the edge-native
68> co-located model.
69​
70## Local process
71​
72```ts
73import { localProcessSandbox } from '@tanstack/ai-sandbox-local-process'
74​
75const dev = localProcessSandbox()
76```
77​
78- **Isolation:** none. The harness runs directly on your host, inheriting your
79 host environment. Use it for trusted or dev work only. There is no boundary
80 between the agent and your machine.
81- **Auth / env:** inherits the host environment. Set `authMode` on the harness
82 (`'host'` or `'api-key'`). The provider does not pick this. See
83 [Harness Auth](./auth).
84- **Snapshot / resume:** no snapshots and no durable resume-by-id; each run
85 re-creates and re-bootstraps under the same identity. The snapshot step is
86 skipped silently (see [Capabilities](#capabilities)).
87​
88### Host login vs API key (`scrubEnv`)
89​
90The provider is where the agent runs, not how it signs in. The default
91`authMode` is `'api-key'`. Set `'host'` when the machine already has a CLI
92login. A local-process run can be your laptop or a GitHub runner. See
93[Harness Auth](./auth).
94​
95`localProcessSandbox` inherits the host environment, including any API keys
96exported there. If you set `authMode: 'host'`, pass `scrubEnv` so those keys
97do not override the CLI login:
98​
99```ts
100import { localProcessSandbox } from '@tanstack/ai-sandbox-local-process'
101​
102const hostLogin = localProcessSandbox({
103 scrubEnv: ['XAI_API_KEY', 'GROK_API_KEY'],
104})
105```
106​
107If the same local-process sandbox runs on a CI machine, set
108`authMode: 'api-key'`. Then inject the key as a workspace secret. Isolated and
109cloud providers have no host CLI login. Use `authMode: 'api-key'` and
110workspace secrets there.
111​
112### Windows process teardown (`logger`)
113​
114Killing a spawned process means killing the whole tree, and on Windows that takes
115more than `taskkill /T`. Commands run through a git-bash `sh`, and MSYS's
116fork emulation runs the final command of a statement list, such as the
117`tail -f` behind a [journal](./journal) follow read, under an intermediate shell
118that immediately exits. Windows never reparents, so the surviving process points
119at a dead parent and `taskkill /T`, which walks only live parent links, cannot
120reach it **while still exiting `0`**. Left alone, every follow read leaks a
121process for the life of the machine.
122​
123`localProcessSandbox` therefore consults MSYS's own process table, which does
124keep the logical parentage before killing, then kills any descendant `/T` missed.
125Teardown is total by construction: it never throws, because a throwing kill would
126strand a run mid-flight. That means a kill it genuinely cannot complete (a
127protected process, access denied) is otherwise invisible, so pass a `logger` to
128see it:
129​
130```ts
131import { localProcessSandbox } from '@tanstack/ai-sandbox-local-process'
132​
133const dev = localProcessSandbox({
134 logger: {
135 warn: (message, meta) => console.warn(message, meta),
136 },
137})
138```
139​
140Any object with a `warn(message, meta?)` method works, so the `InternalLogger`
141your adapter already receives can be handed straight in. A process that had
142already exited on its own is **not** a failure and is never reported.
143​
144Nothing here changes on POSIX, where `sh` really is the command's parent and
145signalling the wrapper is enough.
146​
147## Docker
148​
149```ts
150import { dockerSandbox } from '@tanstack/ai-sandbox-docker'
151​
152const isolated = dockerSandbox({ image: 'node:22' })
153```
154​
155- **Isolation:** a real container boundary between the agent and your host.
156- **Auth / env:** no host login; provide credentials as workspace secrets, which
157 are injected into the container env at create/resume. The agent reaches host
158 tools over `host.docker.internal` (see [tools](./tools)).
159- **Snapshot / resume:** full commit-based snapshots, `fork`, and resume-by-id.
160 Bootstrap snapshots after `setup` completes, so subsequent runs resume from the
161 snapshot instead of re-running setup.
162​
163## Docker Sandboxes (sbx)
164​
165```ts
166import { sbxSandbox } from '@tanstack/ai-sandbox-docker'
167import { defineSandbox, defineWorkspace, githubRepo } from '@tanstack/ai-sandbox'
168​
169const isolated = sbxSandbox({
170 allowNetwork: ['*.npmjs.org', 'registry.npmjs.org'],
171})
172​
173const sandbox = defineSandbox({
174 id: 'repo-agent',
175 provider: isolated,
176 workspace: defineWorkspace({
177 source: githubRepo({ repo: 'owner/repo' }),
178 setup: ['pnpm install'],
179 }),
180})
181```
182​
183- **Isolation:** a hypervisor microVM. The sandbox has its own kernel and its own Docker daemon. This is not `dockerSandbox()`, which starts a container.
184- **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.
185- **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.
186- **Auth / env:** inject API keys as workspace secrets. v1 does not call `sbx secret`.
187- **Snapshot / resume:** no snapshots and no fork. Resume reconnects by name (`sbx ls`). A stopped sandbox starts again on the next `sbx exec`.
188- **Network:** this is the first provider with `networkPolicy: true`. See [Policy](./policy).
189​
190## Daytona
191​
192```ts
193import { daytonaSandbox } from '@tanstack/ai-sandbox-daytona'
194​
195const daytona = daytonaSandbox({
196 apiKey: process.env.DAYTONA_API_KEY,
197 snapshot: 'daytona-medium',
198 autoStopInterval: 0,
199})
200```
201​
202- **Isolation:** a managed cloud sandbox on a remote VM you do not run yourself.
203- **Auth / env:** needs `DAYTONA_API_KEY`. Put harness credentials in
204 [workspace secrets](./provisioning). At create and snapshot restore,
205 Daytona stores each value as an organization Secret and mounts a
206 placeholder in the sandbox env. The create record, the dashboard env
207 view, and session command strings do not contain the real value. Daytona
208 substitutes the value on outbound HTTPS requests. Per-command `opts.env`
209 uses `executeCommand`'s env argument or a sourced env file. It never
210 writes `export KEY=` prefixes into the command string.
211- **Snapshot / resume:** point-in-time snapshots after setup (default when
212 `lifecycle.snapshot` is `'after-setup'`). Pass `snapshot` on
213 `daytonaSandbox()` to pick the Daytona image (for example
214 `'daytona-medium'`). Resume starts a `stopped` or `archived` sandbox, then
215 returns the handle.
216- **Idle stop:** Daytona stops an idle sandbox after 15 minutes by default.
217 Set `autoStopInterval` in minutes to change that. Pass `0` to turn auto-stop
218 off. Set `ephemeral: true` to delete the sandbox when it stops.
219- **Network:** `policy.capabilities.network: 'deny'` blocks all outbound
220 network on create.
221- **Working directory:** the portable root `/workspace` maps to
222 `/home/daytona/workspace` by default. Override with `workdir` on
223 `daytonaSandbox()` if you need another path.
224- **Stdin:** spawned processes accept host stdin (`writableStdin: true`).
225- **Privileges:** the Daytona user is not root. Package installs in `setup`
226 must use `sudo -n` (for example `sudo -n apt-get install …`). Do not put
227 `sudo *` in a [policy](./policy) deny list for this provider.
228- **Bridge:** the sandbox is remote, so a [bridged tool](./tools) call cannot
229 reach your laptop's `localhost`. In local dev, tunnel the bridge (see
230 [tools](./tools)). A deployed orchestrator is reachable without a tunnel.
231​
232Default headless path on Daytona:
233​
234```ts
235import { chat } from '@tanstack/ai'
236import { grokBuildText } from '@tanstack/ai-grok-build'
237import {
238 defineSandbox,
239 defineSandboxPolicy,
240 defineWorkspace,
241 gitSkill,
242 githubRepo,
243 withSandbox,
244} from '@tanstack/ai-sandbox'
245import { daytonaSandbox } from '@tanstack/ai-sandbox-daytona'
246​
247const sandbox = defineSandbox({
248 id: 'daytona-agent',
249 provider: daytonaSandbox({
250 apiKey: process.env.DAYTONA_API_KEY,
251 snapshot: 'daytona-medium',
252 }),
253 workspace: defineWorkspace({
254 source: githubRepo({ repo: 'owner/app' }),
255 skills: [gitSkill({ repo: 'owner/skills-pack' })],
256 }),
257 policy: defineSandboxPolicy({
258 default: 'allow',
259 }),
260})
261​
262const stream = chat({
263 adapter: grokBuildText('grok-build'),
264 messages: [{ role: 'user', content: 'List the project files.' }],
265 middleware: [withSandbox(sandbox)],
266})
267```
268​
269Headless Grok Build and Codex stay on auto-approve with `default: 'allow'`.
270Isolation is the Daytona VM. Use Claude Code when you need command-level deny.
271​
272## Vercel
273​
274```ts
275import { vercelSandbox } from '@tanstack/ai-sandbox-vercel'
276​
277const vercel = vercelSandbox({ runtime: 'node24' })
278```
279​
280- **Isolation:** a managed microVM (Vercel Sandbox).
281- **Auth / env:** needs `VERCEL_TOKEN` plus a team/project. Harness credentials
282 are injected as workspace secrets.
283- **Snapshot / resume:** persistent resume-by-id with a durable filesystem, plus
284 exposed-port domains for previews.
285- **Bridge:** like Daytona, it is a remote VM, so bridged tools need the tunnel in local
286 dev (see [tools](./tools)).
287​
288## Sprites
289​
290```ts
291import { spritesSandbox } from '@tanstack/ai-sandbox-sprites'
292​
293const sprites = spritesSandbox({ apiKey: process.env.SPRITES_API_KEY })
294```
295​
296- **Isolation:** a managed [Sprites](https://sprites.dev) stateful sandbox
297 (Fly.io), a remote VM you do not run yourself.
298- **Auth / env:** needs `SPRITES_API_KEY` (token form
299 `org/projectNumber/tokenId/secret`); override the control-plane URL with
300 `apiUrl` / `SPRITES_API_URL`. Harness credentials are injected as workspace
301 secrets.
302- **Snapshot / resume:** resume-by-id reconnects to the named Sprite (its
303 filesystem is durable across idle suspend/resume). `snapshot()` creates a
304 Sprite **checkpoint** (a save point of the writable overlay); restore is
305 **in-place** on the same Sprite via the handle's `restoreCheckpoint()` /
306 `listCheckpoints()`. A checkpoint does not survive Sprite deletion, so the
307 provider intentionally does **not** implement the reconstruct-after-gone
308 `restoreSnapshot`, when a Sprite is gone the framework degrades to a fresh
309 create instead. Restore restarts the environment and can take minutes;
310 `restoreCheckpoint()` polls the workspace until it is listable again before
311 resolving. Note that immediately after a restore the overlay can be listable
312 while individual file reads briefly return an I/O error as it settles, so retry
313 reads if you act on the filesystem the instant restore returns.
314- **Ports:** a Sprite proxies a single internal HTTP port (default `8080`,
315 configurable via `httpPort`) to its always-on public URL. `ports.connect(8080)`
316 switches the URL to `public` auth and returns it; other ports are not exposed.
317- **Bridge:** like Daytona and Vercel, it is a remote VM, so bridged tools need the tunnel in
318 local dev (see [tools](./tools)).
319​
320## Upstash Box
321​
322```ts
323import { upstashBoxSandbox } from '@tanstack/ai-sandbox-upstash-box'
324​
325const box = upstashBoxSandbox({ apiKey: process.env.UPSTASH_BOX_API_KEY })
326```
327​
328- **Isolation:** a managed [Upstash Box](https://github.com/upstash/box) cloud
329 sandbox, a remote container you do not run yourself.
330- **Auth / env:** needs `UPSTASH_BOX_API_KEY` (or `apiKey`); override the API
331 base with `baseUrl` / `UPSTASH_BOX_BASE_URL`. Pick the image and size with
332 `runtime` (default `node`) and `size`.
333- **Paths:** the conventional `/workspace` virtual root maps to the box home,
334 `/workspace/home`, which is the handle's `workspaceRoot`.
335- **Processes:** `spawn()` opens a live `exec.session` over a WebSocket, so a
336 background process has a real in-box pid, a writable stdin, separate stdout and
337 stderr, and server-side signals. A session owns its process: dropping the
338 connection kills the command and sessions cannot be reattached, so `spawn()` is
339 scoped to the lifetime of the handle rather than the box. Blocking `exec()`
340 stays on the HTTP path and is shell-wrapped for `cwd`/env, which the session
341 takes natively.
342- **Snapshot / resume:** `snapshot()` calls `box.snapshot()` and
343 `restoreSnapshot()` reconstructs a new box from it via `Box.fromSnapshot()`, so
344 a snapshot survives deletion of the box that made it. Resume-by-id uses
345 `Box.get` (id or name) and probes `getStatus`, so a deleted record resumes as
346 `null` rather than a tombstone handle.
347- **Ports:** `ports.connect(port)` mints a preview URL via `getPublicURL`. Pass
348 `publicUrlAuth` to gate it, `{ bearerToken: true }` returns a token plus an
349 `Authorization: Bearer` header and `{ basicAuth: true }` returns Basic
350 credentials; without it the preview URL is unauthenticated.
351- **Network:** a `policy.capabilities.network` of `'deny'` maps to Box's
352 `deny-all` egress mode. The contract's gate is coarse, so Box's domain and CIDR
353 allowlists are not reachable through it. This is stricter than providers that
354 model deny as an allowlist: `deny-all` blocks every outbound connection, so an
355 agent that works under an allowlist-style deny will not reach package
356 registries or model provider hosts here. Leave the capability unset if the
357 agent needs either.
358- **Fork:** `fork()` snapshots the box and creates a new one from that snapshot,
359 the same shape as Docker's commit plus create. It costs a full snapshot round
360 trip (about 25 seconds), unlike Docker's local commit.
361- **Bridge:** like Daytona and Vercel, it is a remote VM, so bridged tools need
362 the tunnel in local dev (see [tools](./tools)).
363​
364## Blaxel
365​
366```ts
367import { blaxelSandbox } from '@tanstack/ai-sandbox-blaxel'
368​
369const blaxel = blaxelSandbox({
370 apiKey: process.env.BL_API_KEY,
371 workspace: process.env.BL_WORKSPACE,
372})
373```
374​
375- **Isolation:** a managed [Blaxel](https://blaxel.ai) cloud sandbox — a remote VM
376 you don't run yourself. Pick the image with `image` (default
377 `blaxel/base-image:latest`) and the size with `memory` (default 2048 MB). Set
378 `region` (or `BL_REGION`) to choose a region and to silence the SDK's warning
379 that it will become required.
380- **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.
381- **Lifetime:** created sandboxes carry a `1h` TTL by default so an abandoned run
382 cannot strand a paid sandbox. Override with `ttl`, or pass `ttl: null` to manage
383 lifetime yourself.
384- **Resume:** resume-by-id reconnects to the named sandbox, and its filesystem
385 is durable across idle suspend/resume for the sandbox's lifetime. Blaxel's
386 snapshot/fork API is currently a source-scoped private preview, has no
387 entitlement probe, and does not document snapshots surviving source deletion.
388 The framework requires `snapshots` to reconstruct after the source is gone, so
389 this provider conservatively advertises both `snapshots` and `fork` as `false`
390 and does not expose `restoreSnapshot`.
391- **Ports:** `ports.connect(port)` creates a per-port preview URL. Previews are
392 token-gated by default and the returned channel carries both the token and the
393 ready-to-send `X-Blaxel-Preview-Token` header. Set `publicPreviews: true` for
394 unauthenticated URLs.
395- **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`.
396- **Process output:** stdout and stderr remain live-streamed through bounded
397 remote capture pipelines. Concurrent stdout and stderr use labeled records on
398 one transport stream, including across keepalive boundaries. Each stream has an 8 MiB total limit; exceeding it
399 fails and remotely reaps the process instead of accumulating unbounded logs in
400 the provider host. Cancellation uses the same process-group supervisor because
401 the pinned SDK does not prove named-process kill reaches child processes.
402 Custom images must provide Bash plus `cat`, `mkfifo`, `dd`, `base64`, `tr`,
403 and `wc` (the default Blaxel base image does). The supervisor invokes Bash
404 explicitly so job-control process groups do not depend on the image's
405 `/bin/sh` implementation.
406- **Resume semantics:** a destroyed sandbox does not disappear immediately —
407 Blaxel keeps the record in a teardown state before purging it. `resume()`
408 treats deleting, deactivating, failed, and terminated records as gone, while a
409 `DEACTIVATED` sandbox remains resumable consistently with the pinned SDK.
410- **Bridge:** like Daytona/Vercel, a remote VM — bridged tools need the tunnel in
411 local dev (see [tools](./tools)).
412​
413## boxd
414​
415```ts
416import { boxdSandbox } from '@tanstack/ai-sandbox-boxd'
417​
418const boxd = boxdSandbox({
419 apiKey: process.env.BOXD_API_KEY,
420 org: 'acme',
421 vcpu: 2,
422})
423```
424​
425- **Isolation:** a managed [boxd](https://boxd.sh) KVM microVM, a remote VM
426 you do not run yourself. Every machine is created `isolated`: no in-VM
427 `boxd` CLI, no metadata endpoint, no org integrations, and no peers on the
428 org network. The image is Ubuntu 24.04 with Node 24, Python 3, git, Docker,
429 and the Claude Code and Codex CLIs preinstalled.
430- **Auth / env:** needs `BOXD_API_KEY` (or `apiKey`) and the org the key
431 belongs to (`org` or `BOXD_ORG`). Override the endpoint with `baseUrl` /
432 `BOXD_BASE_URL`. Harness credentials are injected as workspace secrets and
433 travel as per-command env. The API key never enters the machine.
434- **Size:** pick `vcpu` (`1`, `2`, or `4`). boxd resolves memory from it:
435 4, 8, or 16 GiB. The default is the org's default size. Every machine has a
436 100 GB disk.
437- **Working directory:** the portable root `/workspace` maps to
438 `/home/boxd/workspace`. Override with `workdir`.
439- **Processes:** `spawn()` opens a streaming exec with separate stdout and
440 stderr and a writable stdin. `kill()` signals the process group inside the
441 machine and verifies that it is gone, so `killableProcesses` is measured,
442 not assumed.
443- **Snapshot / resume:** `snapshot()` captures memory and disk into a boxd
444 snapshot named `<machine>-<label>` and waits until it is restorable (about
445 25 s for an 8 GiB machine). `restoreSnapshot()` boots a new machine from it
446 in about 1 s, with the captured processes still running. Resume-by-id
447 reconnects to the same machine across stop (2 to 3 s to start), suspend
448 (about 140 ms) and hibernate.
449- **Fork:** `fork()` is a live boxd fork: disk, memory and running processes,
450 ready in under a second.
451- **Lifetime:** a machine is persistent until `destroy()`. It suspends after
452 `autoSuspendTimeout` idle seconds and hibernates after 4 hours idle by
453 default, at no compute cost, and wakes on the next command. Idle means no
454 inbound connection. Set `autoDestroyTimeout` as a safety net for abandoned
455 sandboxes. `stop` is a power-off: a file written seconds before it can still
456 sit in the page cache and be lost, so run `sync` before you stop a machine
457 yourself. Suspend, hibernate, snapshot and fork keep memory, so they do not
458 lose it.
459- **Ports:** every machine has one public HTTPS URL, `https://<name>.boxd.sh`.
460 `ports.connect(port)` pins that URL to `port` and returns it. The URL is
461 public: anyone who has it can reach the port.
462- **Golden image:** pass `fromSnapshot` to boot every new sandbox from a
463 snapshot you baked after `setup`, instead of the default image. The size is
464 then fixed by the snapshot.
465- **Bridge:** like the other cloud providers, it is a remote VM, so bridged
466 tools need the tunnel in local dev (see [tools](./tools)).
467​
468## E2B
469​
470```ts
471import { e2bSandbox } from '@tanstack/ai-sandbox-e2b'
472​
473const e2b = e2bSandbox({ apiKey: process.env.E2B_API_KEY })
474```
475​
476- **Isolation:** a managed [E2B](https://e2b.dev) sandbox, a Firecracker microVM
477 you do not run yourself. Pick the image with `template` (default: the E2B
478 `base` template).
479- **Auth / env:** needs `E2B_API_KEY` (or `apiKey`). Set `domain` (or
480 `E2B_DOMAIN`) for a self-hosted or BYOC deployment. Harness credentials are
481 injected as [workspace secrets](./provisioning). At create and snapshot
482 restore they are sent as sandbox `envs`. Per-command `env` goes through the
483 SDK's native `envs` argument. No value is written into a command string.
484- **Lifetime:** a sandbox lives for `timeoutMs` (default 30 minutes) and is
485 killed when that time elapses, so an abandoned run cannot keep billing.
486 Resume extends the lifetime by the same amount. Set `onTimeout: 'pause'` to
487 keep a timed-out sandbox resumable instead. E2B caps the lifetime at 1 hour
488 on the Hobby plan and 24 hours on Pro.
489- **Snapshot / resume:** `snapshot()` calls `createSnapshot()`. The sandbox is
490 paused briefly, then resumed. `restoreSnapshot()` creates a new sandbox from
491 that snapshot, so a snapshot survives deletion of its source. Resume-by-id
492 uses `Sandbox.connect`, which also wakes a paused sandbox. A killed or
493 expired sandbox resumes as `null`.
494- **Fork:** `fork()` is native. The parent is checkpointed in place and the copy
495 boots from that checkpoint.
496- **Processes:** every command runs as the leader of its own process group
497 (`setsid`), so `kill()` reaches backgrounded children. `kill()` always sends
498 `SIGKILL`. `spawn()` has a real sandbox pid, a writable stdin, and separate
499 stdout and stderr. A custom template must include `setsid` (util-linux); the
500 default template has it.
501- **Ports:** `ports.connect(port)` returns
502 `https://<port>-<sandbox-id>.<domain>`. With `allowPublicTraffic: false` the
503 URL is gated by the `e2b-traffic-access-token` header, and the channel carries
504 that header in `headers`. Browsers cannot send it, so leave public traffic on
505 for preview links a person clicks.
506- **Network:** `policy.capabilities.network: 'deny'` maps to
507 `allowInternetAccess: false`, which blocks all outbound traffic. E2B's
508 per-host allow and deny lists are not reachable through the contract's coarse
509 gate.
510- **Paths:** the portable root `/workspace` maps to `/home/user/workspace` by
511 default. Override with `workdir`. The sandbox user is `user` (not root) with
512 passwordless `sudo`, and `/workspace` itself is not writable.
513- **Bridge:** like Daytona and Vercel, it is a remote VM, so bridged tools need
514 the tunnel in local dev (see [tools](./tools)).
515​
516## Capabilities
517​
518Providers declare what they support via `capabilities()`. The flags are:
519​
520| Capability | Meaning |
521| --- | --- |
522| `fs` | Read/write the sandbox filesystem. |
523| `exec` | Run commands. |
524| `env` | Inject environment variables. |
525| `ports` | Expose/forward ports (preview URLs). |
526| `backgroundProcesses` | Keep long-running processes alive between calls. |
527| `writableStdin` | A spawned process exposes a writable host→process stdin. `true` for local-process, Docker container, Daytona, Upstash Box, E2B, and boxd. `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. |
528| `killableProcesses` | A spawned process can be forcibly stopped via `SpawnHandle.kill()` **and** aborted mid-flight via the `signal` passed to `spawn`. |
529| `snapshots` | Capture and restore point-in-time snapshots. |
530| `networkPolicy` | Enforce network allow/deny rules. |
531| `durableFilesystem` | Disk that survives across resumes. |
532| `fork` | Branch a sandbox from an existing one. |
533​
534Code that uses an **optional** capability checks the flag first and degrades
535gracefully. For example, bootstrap only snapshots when `snapshots` is supported,
536so `localProcessSandbox` simply skips the step. Calling an unsupported optional
537method directly (instead of checking the flag) throws an
538`UnsupportedCapabilityError`:
539​
540```ts
541import { localProcessSandbox } from '@tanstack/ai-sandbox-local-process'
542​
543const provider = localProcessSandbox()
544const caps = provider.capabilities()
545​
546if (caps.snapshots) {
547 // safe to take a snapshot
548} else {
549 // degrade gracefully, local-process has no snapshots
551```
552​
553Use the flags to write provider-agnostic code: branch on the capability rather
554than the concrete provider, and your sandbox definition keeps working when you
555swap one provider for another.
556​
557### `killableProcesses` across the bundled providers
558​
559This flag is **measured, not asserted**. A wrong `true` hands the journal reader
560an unstoppable `tail -f` and leaks a process per run, so a provider only declares
561it once killing has been observed to work against a real sandbox. Two of these
562declarations were once `true` on reasoning alone and both turned out to be false
563when probed (Docker's stream destroy left the container-side process in `ps`;
564local-process's `sh -c` did not `exec`, so killing the shell left the command
565alive). Anything that cannot be measured yet stays `false`, because `poll` is
566merely slower while a wrong `follow` is a leak.
567​
568| Provider | `killableProcesses` | Why |
569| --- | --- | --- |
570| 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). |
571| 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. |
572| 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. |
573| 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`. |
574| 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. |
575| 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`. |
576| 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`. |
577| 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. |
578| 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`. |
579| Cloudflare | `false` | `kill()` is a no-op, and the caller's `AbortSignal` reaches neither `exec` nor `spawn`, because Workers RPC cannot serialize one. |
580| 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`. |
581​
582Each of the remote providers registers the shared journal conformance suite, so
583the claim is falsifiable rather than asserted: with credentials present the suite
584runs against a real sandbox, and without them it reports a **named skip** carrying
585the reason instead of a silent pass. Cloudflare's gate is the runtime rather than
586credentials, its provider can only create a sandbox through a `Sandbox` Durable
587Object binding, which no Node test process has, so its registration is a named
588skip saying exactly that, until a Workers-runtime harness can measure it.
589​
590This flag is required on every provider, including a bring-your-own one. A
591provider that omitted it would be treated as killable, which is the dangerous
592default: a follower process started there could never be reclaimed, and it would
593keep running inside the sandbox for as long as the sandbox lives.
594​
595It is the flag the [run journal](./journal) reads to decide how to tail a run's
596output: a killable provider gets a streaming `tail -f`, and a provider like
597Cloudflare gets a loop of bounded reads, each of which terminates on its own.
598​
599The flag also bounds what *cancel* can mean. On a `false` provider there is no
600signal path to the agent process, so the only cancel that actually stops the
601agent means destroying the sandbox, which is what the cancel path does. See
602[what cancel means on a provider that cannot kill](./takeover#what-cancel-means-on-a-provider-that-cannot-kill).