Open History to see the last commit
1{
2 "$schema": "node_modules/wrangler/config-schema.json",
3 "name": "tanstack-ai-sandbox-cloudflare",
4 // Custom server entry: TanStack Start SSR + the agent's DOs/container in one
5 // Worker. The @cloudflare/vite-plugin builds this entry and wires the client
6 // assets automatically (no `assets` block needed here).
7 "main": "src/server.ts",
8 "compatibility_date": "2026-05-01",
9 // node:crypto/node:buffer used transitively by the TanStack AI packages + the
10 // MCP SDK. The DO/Worker code itself uses Web Crypto for the bearer check.
11 "compatibility_flags": ["nodejs_compat"],
12
13 // The container image that the @cloudflare/sandbox Sandbox DO runs. It ships
14 // all three harness CLIs — claude, codex, grok (see Dockerfile + README
15 // Limitations re: stdin) — so `HARNESS` can select one without a rebuild.
16 //
17 // FOOTGUN — `sleepAfter`: the Sandbox class's idle timeout (a class/option
18 // property, not a wrangler key) counts RPC activity, not agent CPU. A run
19 // that is detached AND quiet (nobody tailing, no bridge/tool calls in
20 // flight) looks idle, so the container can sleep mid-run — which presents as
21 // "durability failed" when it is the idle timeout working as configured.
22 // Size it above your longest expected quiet stretch before relying on
23 // detached runs. See docs/sandbox/cloudflare.md "What edge durability does
24 // not buy you".
25 "containers": [
26 {
27 "class_name": "Sandbox",
28 "image": "./Dockerfile",
29 // A few warm instances so concurrent chat threads each get a sandbox.
30 "max_instances": 5,
31 },
32 ],
33
34 "durable_objects": {
35 "bindings": [
36 // The coordinator that owns each run (drives chat(), the run-log, the
37 // WebSocket tails, and the /_bridge MCP endpoint).
38 { "name": "RUN_COORDINATOR", "class_name": "RunCoordinator" },
39 // The @cloudflare/sandbox container host DO.
40 { "name": "Sandbox", "class_name": "Sandbox" },
41 ],
42 },
43
44 "migrations": [
45 {
46 "tag": "v1",
47 // Both DO classes use the SQLite-backed storage backend (required for the
48 // sandbox SDK, and what DurableObjectRunEventLog persists run events to).
49 "new_sqlite_classes": ["RunCoordinator", "Sandbox"],
50 },
51 ],
52
53 // Two host surfaces, both OPTIONAL here (request-derived when unset):
54 //
55 // • PUBLIC_HOSTNAME — the CONTAINER→Worker bridge host (`/_bridge`, `/tool-exec`).
56 // Unset → derived from the trigger request, which is safe on Cloudflare (the
57 // edge only routes hostnames you own to your Worker). A `*.workers.dev` deploy
58 // works with ZERO config; locally the coordinator uses `host.docker.internal`.
59 // Set it only to override (e.g. a stable named dev tunnel).
60 //
61 // • PREVIEW_HOSTNAME — OPTIONAL, and NOT needed for this example. Browser previews
62 // default to a Cloudflare quick tunnel (`*.trycloudflare.com`) served by
63 // `cloudflared` inside the sandbox — works with zero config, local or on a
64 // `*.workers.dev` deploy. PREVIEW_HOSTNAME only applies to the alternative
65 // `exposePort`-fronted path (the Worker serves the preview on YOUR domain): that
66 // needs WILDCARD DNS, so set a `*.<domain>` route + this var, e.g.:
67 // "routes": [{ "pattern": "*.preview.example.com/*", "zone_name": "example.com" }]
68 // "vars": { "PREVIEW_HOSTNAME": "preview.example.com" }
69 // See `resolvePreviewHost` in @tanstack/ai-sandbox-cloudflare.
70
71 // The harness's API key is a SECRET, not a var — set the one for your chosen
72 // HARNESS (see below). It is injected into the sandbox env (never persisted to
73 // logs/snapshots):
74 // claude-code → wrangler secret put ANTHROPIC_API_KEY
75 // codex → wrangler secret put CODEX_API_KEY (or OPENAI_API_KEY)
76 // grok → wrangler secret put XAI_API_KEY (or GROK_API_KEY)
77
78 "vars": {
79 // Which in-sandbox coding agent to run: claude-code (default) | codex | grok.
80 // The container image ships all three CLIs; this just picks which one chat()
81 // drives (see selectHarness in src/agent.ts). Change it + redeploy to switch.
82 "HARNESS": "claude-code",
83 // Container-control transport for the Sandbox DO. `rpc` is required for
84 // `sandbox.tunnels` (the quick-tunnel preview URLs `exposePreview` returns);
85 // on the default `http` it throws "requires the RPC transport". The getSandbox
86 // providers also pass `transport: 'rpc'` (client side) to match. See
87 // `exposePreviewTool` / `cloudflareSandbox` in @tanstack/ai-sandbox-cloudflare.
88 "SANDBOX_TRANSPORT": "rpc",
89 },
90
91 "observability": { "enabled": true },
92}