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

providers.md

167 lines7.8 KB

1---
2title: Providers
3id: providers
4order: 3
5description: "Pick where a TanStack AI sandbox runs (local process, Docker container, Docker Sandboxes microVM, Daytona, Vercel, Sprites, Upstash Box, Blaxel, E2B, boxd, or Railway), install it, and configure it."
6---
7​
8A provider is where the sandbox runs: a local process for a fast loop, or an isolated VM in production.
9​
10A provider is that place. Every provider has the same contract, so your [workspace](./workspace), [policy](./policy), and harness stay the same when you change the provider.
11​
12## Set up a provider
13​
141. Pick a row from the table.
15​
16| Provider | Package | Isolation | Needs |
17| --- | --- | --- | --- |
18| Local process | `@tanstack/ai-sandbox-local-process` | None (your host) | Nothing. For trusted dev work only. |
19| Docker | `@tanstack/ai-sandbox-docker` | Container | Docker running. |
20| Docker Sandboxes (`sbx`) | `@tanstack/ai-sandbox-docker` | microVM | The `sbx` CLI, `sbx login`, and a hypervisor. |
21| [Daytona](https://www.daytona.io/) | `@tanstack/ai-sandbox-daytona` | Cloud sandbox | `DAYTONA_API_KEY` |
22| [Vercel](https://vercel.com/docs/sandbox) | `@tanstack/ai-sandbox-vercel` | microVM | `VERCEL_TOKEN`, a team, and a project. |
23| [Sprites](https://sprites.dev) | `@tanstack/ai-sandbox-sprites` | Stateful sandbox | `SPRITES_API_KEY` |
24| [Upstash Box](https://github.com/upstash/box) | `@tanstack/ai-sandbox-upstash-box` | Cloud sandbox | `UPSTASH_BOX_API_KEY` |
25| [Blaxel](https://blaxel.ai) | `@tanstack/ai-sandbox-blaxel` | Cloud sandbox | `BL_API_KEY` and `BL_WORKSPACE`, or a Blaxel CLI login. |
26| [E2B](https://e2b.dev) | `@tanstack/ai-sandbox-e2b` | microVM | `E2B_API_KEY` |
27| [boxd](https://boxd.sh) | `@tanstack/ai-sandbox-boxd` | microVM | `BOXD_API_KEY` and `BOXD_ORG`. |
28| [Railway](https://railway.com) | `@tanstack/ai-sandbox-railway` | microVM | `RAILWAY_API_TOKEN` or `RAILWAY_TOKEN`, and an environment. |
29​
302. Install its package. This example installs the Docker provider. Use the package from your row.
31​
32<!-- ::start:tabs variant="package-manager" mode="install" -->
33​
34react: @tanstack/ai-sandbox-docker
35vue: @tanstack/ai-sandbox-docker
36solid: @tanstack/ai-sandbox-docker
37svelte: @tanstack/ai-sandbox-docker
38preact: @tanstack/ai-sandbox-docker
39angular: @tanstack/ai-sandbox-docker
40vanilla: @tanstack/ai-sandbox-docker
41octane: @tanstack/ai-sandbox-docker
42​
43<!-- ::end:tabs -->
44​
453. Set the env vars from the "Needs" column.
46​
474. Pass the provider to `defineSandbox`:
48​
49```ts
50import {
51 createSecrets,
52 defineSandbox,
53 defineWorkspace,
54 githubRepo,
55} from '@tanstack/ai-sandbox'
56import { dockerSandbox } from '@tanstack/ai-sandbox-docker'
57​
58export const repoSandbox = defineSandbox({
59 id: 'repo-agent',
60 provider: dockerSandbox({ image: 'node:22' }),
61 workspace: defineWorkspace({
62 source: githubRepo({ repo: 'owner/app' }),
63 setup: ['corepack enable', 'pnpm install'],
64 secrets: createSecrets({
65 XAI_API_KEY: process.env.XAI_API_KEY ?? '',
66 }),
67 }),
68})
69```
70​
71To change the provider, change only the `provider` line. Here is the constructor for each one:
72​
73```ts
74import { localProcessSandbox } from '@tanstack/ai-sandbox-local-process'
75import { dockerSandbox, sbxSandbox } from '@tanstack/ai-sandbox-docker'
76import { daytonaSandbox } from '@tanstack/ai-sandbox-daytona'
77import { vercelSandbox } from '@tanstack/ai-sandbox-vercel'
78import { spritesSandbox } from '@tanstack/ai-sandbox-sprites'
79import { upstashBoxSandbox } from '@tanstack/ai-sandbox-upstash-box'
80import { blaxelSandbox } from '@tanstack/ai-sandbox-blaxel'
81import { e2bSandbox } from '@tanstack/ai-sandbox-e2b'
82import { boxdSandbox } from '@tanstack/ai-sandbox-boxd'
83import { railwaySandbox } from '@tanstack/ai-sandbox-railway'
84​
85const dev = localProcessSandbox() // runs on your host
86const isolated = dockerSandbox({ image: 'node:22' }) // container
87const microvm = sbxSandbox() // Docker Sandboxes microVM
88const daytona = daytonaSandbox({ apiKey: process.env.DAYTONA_API_KEY })
89const vercel = vercelSandbox({ runtime: 'node24' })
90const sprites = spritesSandbox({ apiKey: process.env.SPRITES_API_KEY })
91const box = upstashBoxSandbox({ apiKey: process.env.UPSTASH_BOX_API_KEY })
92const blaxel = blaxelSandbox() // uses the API key or the CLI login
93const e2b = e2bSandbox() // reads E2B_API_KEY
94const boxd = boxdSandbox({ org: 'acme' }) // reads BOXD_API_KEY
95const railway = railwaySandbox() // reads RAILWAY_TOKEN and RAILWAY_ENVIRONMENT_ID
96```
97​
98`dockerSandbox()` and `sbxSandbox()` come from the same package. Every other provider has its own package. For the edge, see [Cloudflare](./cloudflare).
99​
100## How it works
101​
102- The provider decides **where** the agent runs. The [harness](./harnesses) decides **which** agent runs.
103- The provider does not pick how the agent signs in. Set `authMode` on the harness. See [Harness Auth](./auth).
104- Isolated and cloud providers have no host CLI login. Pass API keys as workspace secrets there.
105- Provider-native snapshots and resume keep or recreate the provider state. They make bootstrap faster. [Portable Snapshots](./portable-snapshots) store finished files in your own persistence.
106​
107> [!NOTE]
108> Cloud providers (Daytona, Vercel, Sprites, Upstash Box, Blaxel, E2B, boxd, and Railway) run remotely. When you drive them from your laptop, [bridged tools](./tools) cannot reach your `localhost`. Use the ngrok bridge tunnel from the [tools guide](./tools), or see [Cloudflare](./cloudflare) for the edge setup.
109​
110## Capabilities
111​
112Each provider reports what it can do with `capabilities()`. Code that needs an optional capability checks the flag first:
113​
114```ts
115import { localProcessSandbox } from '@tanstack/ai-sandbox-local-process'
116​
117const provider = localProcessSandbox()
118​
119if (provider.capabilities().snapshots) {
120 // This provider can take a snapshot.
121} else {
122 // Skip the snapshot. Local process has no snapshots.
124```
125​
126| Capability | Meaning |
127| --- | --- |
128| `fs` | Read and write the sandbox filesystem. |
129| `exec` | Run commands. |
130| `env` | Inject environment variables. |
131| `ports` | Expose ports (preview URLs). |
132| `backgroundProcesses` | Keep long-running processes alive between calls. |
133| `writableStdin` | A spawned process has a writable stdin from the host. |
134| `killableProcesses` | A spawned process can be stopped with `SpawnHandle.kill()` and with the `signal` passed to `spawn`. |
135| `snapshots` | Take and restore point-in-time snapshots. |
136| `networkPolicy` | Enforce network allow and deny rules. |
137| `durableFilesystem` | The disk stays across resumes. |
138| `fork` | Create a new sandbox from an existing one. |
139​
140The framework checks these flags for you. For example, bootstrap takes a snapshot only when `snapshots` is `true`, so `localProcessSandbox` skips that step. If you call an unsupported optional method directly, it throws an `UnsupportedCapabilityError`.
141​
142Branch on the flag, not on the provider name. Then your code keeps working when you change the provider.
143​
144### `killableProcesses` across the bundled providers
145​
146The [run journal](./journal) reads this flag to decide how to read a run's output. It also limits what a cancel can do. On a `false` provider, cancel destroys the sandbox. See [what cancel means on a provider that cannot kill](./takeover#what-cancel-means-on-a-provider-that-cannot-kill).
147​
148| Provider | `killableProcesses` |
149| --- | --- |
150| Local process | `true` |
151| Docker | `true` |
152| Docker Sandboxes (`sbx`) | `false` |
153| Daytona | `false` |
154| Vercel | `false` |
155| Sprites | `true` (not verified) |
156| Upstash Box | `true` |
157| Blaxel | `true` |
158| E2B | `true` |
159| Cloudflare | `false` |
160| boxd | `true` |
161| Railway | `true` |
162​
163A bring-your-own provider must set this flag too. For the reason behind each value, see [Providers (Advanced)](./providers-advanced#killableprocesses-per-provider).
164​
165## Advanced
166​
167Each provider has its own options and limits: idle timers, ports, network rules, non-root users, and snapshot behavior. Read them in [Providers (Advanced)](./providers-advanced) before you go to production.