Sandbox SDK Migrator

Migrate stable → Sandbox SDK 1.0 preview (`@next`)

by cloudflare · Apache-2.0 license · ★ 2,976 on GitHub

Migrate stable → Sandbox SDK 1.0 preview (`@next`) cover

Migrate Cloudflare Sandbox apps from stable @cloudflare/sandbox to @cloudflare/sandbox@next (SDK 1.0 preview). Use sandbox-next for apps already on the preview.

---
name: sandbox-migrate-to-next
description: Migrate Cloudflare Sandbox apps from stable @cloudflare/sandbox to @cloudflare/sandbox@next (SDK 1.0 preview). Use sandbox-next for apps already on the preview.
---

# Migrate stable → Sandbox SDK 1.0 preview (`@next`)

**Perform** the port. Follow the steps in order. Depth lives in docs—fetch the linked page when a step needs detail.

Human guide: [Migrate](https://developers.cloudflare.com/sandbox/sdk/migrate/index.md) · [1.0 preview](https://developers.cloudflare.com/sandbox/index.md)

**New projects** should start on `@next` (**`sandbox-next`**), not this skill. **Day-to-day stable work** → **`sandbox-stable`**. Deprecated-API cleanup **without** moving to `@next` → [2026 deprecation guide](https://developers.cloudflare.com/sandbox/sdk/migrate/index.md) first if needed.

Existing apps should migrate **when you can**, so you are ready when 1.0 becomes the stable release. Do **not** force production cutover without the user agreeing.

**Prefer installed `@next` types and the migrate doc over memory.**

## Workflow

Overview

Perform the port. Follow the steps in order. Depth lives in docs—fetch the linked page when a step needs detail.

Manual install (npx, ZIP)
Claude Codenpx skills add cloudflare/skills --skill sandbox-migrate-to-next -g -a claude-code
Claude Code (degit)npx degit cloudflare/skills/skills/sandbox-migrate-to-next#main ~/.claude/skills/sandbox-migrate-to-next
Claude.ai / desktopZip the folder and upload it under Settings → Capabilities → Skills.
Codex, Cursor, other agentsPoint them at SKILL.md. The other files are plain text.

Connects with Agent Alley MCP · agentalley.io/mcp

Files included

  • SKILL.md7.7 KB
Read SKILL.md here
cloudflare/main1 file shown
SKILL.md
Show the full text186 lines

Migrate stable → Sandbox SDK 1.0 preview (@next)

Perform the port. Follow the steps in order. Depth lives in docs—fetch the linked page when a step needs detail.

Human guide: Migrate · 1.0 preview

New projects should start on @next (sandbox-next), not this skill. Day-to-day stable work → sandbox-stable. Deprecated-API cleanup without moving to @next → 2026 deprecation guide first if needed.

Existing apps should migrate when you can, so you are ready when 1.0 becomes the stable release. Do not force production cutover without the user agreeing.

Prefer installed @next types and the migrate doc over memory.

Workflow

  1. Review hard rules and the replacement map
  2. Audit the codebase; list hits and target shapes
  3. Clarify with the user (cutover, bridge, Python image, unclear sites)
  4. Upgrade package, image, and code
  5. Validate

Stop after any step that needs a user decision.

Hard rules

  • Worker package and container image must be the same @next line.
  • Production cutover uses immediate container rollout. Stable and @next control protocols are incompatible both ways; gradual rollout leaves a broken mixed window. In-flight container work can stop.
  • After cutover, await sandbox.exec(...) means process started, not command finished.
  • Argv is as-is (no implicit shell). Shell syntax needs an explicit shell binary.
  • Process handles have no stdin → terminals for interactive input.
  • Observation timeout / AbortSignal cancel the wait only, not the process.
  • No single retry loop for every error.
  • Do not invent APIs (gitCheckout on core, process stdin, string-exec completion helper).
  • Self-deployed bridge stays on stable (not part of the preview line yet).

Replacement map

Stable @next
SANDBOX_TRANSPORT / transport / setTransport Remove — RPC only
await sandbox.exec("cmd") → buffered result await sandbox.exec(argv) → handle, then output / waits
execStream / startProcess Same handle: logs, waitFor*, kill
Default / named sessions Gone — cwd/env per launch, or one shell script
sandbox.terminal(request) / session terminal createTerminal + terminal.connect(request)
xterm sessionId terminalId
Interpreter methods on Sandbox withInterpreter → sandbox.interpreter.*
gitCheckout argv git via exec
String kill signals Numeric only
Files, mounts, backups, ports, tunnels, proxyToSandbox Mostly unchanged (ignore session/transport bits on stable pages)

Depth: Migrate · after port, day-to-day → sandbox-next

Audit

rg 'SANDBOX_TRANSPORT|transport:|setTransport|enableDefaultSession|createSession|getSession|deleteSession|execStream\(|startProcess\(|killProcess\(|sandbox\.terminal\(|sessionId|gitCheckout\(|SandboxTransport|ExecutionSession'

Also: string exec(, cd then a later exec, bare createCodeContext / runCode on Sandbox.

Clarify (ask when needed)

  • OK to cut production with --containers-rollout=immediate (live processes/terminals/streams may stop)?
  • Self-deployed bridge? Leave on stable.
  • Python interpreter → -python image variant?
  • Call sites not covered by the map?

Upgrade

Package and image
npm install @cloudflare/sandbox@next
FROM cloudflare/sandbox:next
# Python: cloudflare/sandbox:next-python

Same prerelease tag on Worker and image when not on floating next.

Code by area

Apply replacements from the map. For each area, implement from the doc—not from stable habits:

Area Doc
Commands / handles / waits Processes · Processes API
cwd / env / secrets Environment · Outbound traffic
Drop sessions Migrate · Lifecycle
Terminals Terminals
Interpreter Interpreter
Errors Errors
Durable job across requests Process execution — lifetime / durability

Commands (shape):

// Before (stable)
const result = await sandbox.exec("npm test");

// After (@next)
const process = await sandbox.exec(["/bin/bash", "-lc", "npm test"]);
const result = await process.output({ encoding: "utf8" });
const server = await sandbox.exec(["/bin/bash", "-lc", "npm run dev"], {
  cwd: "/workspace/app",
});
await server.waitForPort(3000, { timeout: 60_000 });
await server.kill(); // numeric; default 15

Terminals (shape):

const terminal = await sandbox.createTerminal({ command: ["bash"], cwd: "/workspace" });
const t = await sandbox.getTerminal(terminal.id);
if (!t) return new Response("terminal gone", { status: 410 });
return t.connect(request, { cursor, cols, rows });

Interpreter (shape):

import { Sandbox as BaseSandbox } from "@cloudflare/sandbox";
import { withInterpreter } from "@cloudflare/sandbox/interpreter";

export class Sandbox extends BaseSandbox<Env> {
  interpreter = withInterpreter(this);
}

Git (shape):

const clone = await sandbox.exec(
  ["git", "clone", "--depth", "1", "--", repoUrl, "/workspace/repo"],
  { cwd: "/workspace" },
);
const result = await clone.output({ encoding: "utf8" });

Delete transport settings entirely. Remove session APIs. Isolate users with separate sandbox IDs.

Deploy cutover

Staging/branch first. Production is one deploy of matching Worker + image:

npx wrangler deploy --containers-rollout=immediate

Leave rollout_active_grace_period at default 0 (or set 0 if raised). After cutover, pre-deploy process/terminal IDs are invalid. Details: Migrate · Container rollouts

Validate

  1. Lockfile + Dockerfile on the same @next line
  2. Typecheck against @next
  3. Smoke argv exec + output({ encoding: "utf8" })
  4. Smoke long process / terminal / interpreter if used
  5. Errors distinguished: unavailable / interrupted-RPC / stale / local wait
  6. No live secrets in sandbox env
  7. Grep again for removed APIs
  8. Production used --containers-rollout=immediate

Then day-to-day work uses sandbox-next.

Red flags — stop and fix

  • Mixing @next Worker with stable image (or reverse)
  • Gradual container rollout for this cutover
  • Treating await exec as command completion
  • Assuming cd / exports persist across exec calls
  • One retry wrapper for every error
  • Inventing gitCheckout, process stdin, or undocumented APIs
  • Keeping pre-cutover process/terminal IDs after deploy
  • Forcing production cutover without user agreement
  • Putting live secrets in setEnvVars / launch env
1---
2name: sandbox-migrate-to-next
3description: Migrate Cloudflare Sandbox apps from stable @cloudflare/sandbox to @cloudflare/sandbox@next (SDK 1.0 preview). Use sandbox-next for apps already on the preview.
4---
5 
6# Migrate stable → Sandbox SDK 1.0 preview (`@next`)
7 
8**Perform** the port. Follow the steps in order. Depth lives in docs—fetch the linked page when a step needs detail.
9 
10Human guide: [Migrate](https://developers.cloudflare.com/sandbox/sdk/migrate/index.md) · [1.0 preview](https://developers.cloudflare.com/sandbox/index.md)
11 
12**New projects** should start on `@next` (**`sandbox-next`**), not this skill. **Day-to-day stable work** → **`sandbox-stable`**. Deprecated-API cleanup **without** moving to `@next` → [2026 deprecation guide](https://developers.cloudflare.com/sandbox/sdk/migrate/index.md) first if needed.
13 
14Existing apps should migrate **when you can**, so you are ready when 1.0 becomes the stable release. Do **not** force production cutover without the user agreeing.
15 
16**Prefer installed `@next` types and the migrate doc over memory.**
17 
18## Workflow
19 
201. **Review** hard rules and the replacement map
212. **Audit** the codebase; list hits and target shapes
223. **Clarify** with the user (cutover, bridge, Python image, unclear sites)
234. **Upgrade** package, image, and code
245. **Validate**
25 
26Stop after any step that needs a user decision.
27 
28## Hard rules
29 
30- Worker package and container image must be the **same** `@next` line.
31- Production cutover uses **immediate** container rollout. Stable and `@next` control protocols are incompatible both ways; gradual rollout leaves a broken mixed window. In-flight container work can stop.
32- After cutover, `await sandbox.exec(...)` means process **started**, not command **finished**.
33- Argv is as-is (no implicit shell). Shell syntax needs an explicit shell binary.
34- Process handles have **no stdin** → terminals for interactive input.
35- Observation `timeout` / `AbortSignal` cancel the **wait only**, not the process.
36- No single retry loop for every error.
37- Do not invent APIs (`gitCheckout` on core, process stdin, string-exec completion helper).
38- Self-deployed bridge stays on **stable** (not part of the preview line yet).
39 
40## Replacement map
41 
42| Stable | `@next` |
43| ------ | ------- |
44| `SANDBOX_TRANSPORT` / `transport` / `setTransport` | Remove — RPC only |
45| `await sandbox.exec("cmd")` → buffered result | `await sandbox.exec(argv)` → handle, then `output` / waits |
46| `execStream` / `startProcess` | Same handle: `logs`, `waitFor*`, `kill` |
47| Default / named sessions | Gone — `cwd`/`env` per launch, or one shell script |
48| `sandbox.terminal(request)` / session terminal | `createTerminal` + `terminal.connect(request)` |
49| xterm `sessionId` | `terminalId` |
50| Interpreter methods on `Sandbox` | `withInterpreter` → `sandbox.interpreter.*` |
51| `gitCheckout` | argv `git` via `exec` |
52| String kill signals | Numeric only |
53| Files, mounts, backups, ports, tunnels, `proxyToSandbox` | Mostly unchanged (ignore session/transport bits on stable pages) |
54 
55Depth: [Migrate](https://developers.cloudflare.com/sandbox/sdk/migrate/index.md) · after port, day-to-day → **`sandbox-next`**
56 
57## Audit
58 
59```sh
60rg 'SANDBOX_TRANSPORT|transport:|setTransport|enableDefaultSession|createSession|getSession|deleteSession|execStream\(|startProcess\(|killProcess\(|sandbox\.terminal\(|sessionId|gitCheckout\(|SandboxTransport|ExecutionSession'
61```
62 
63Also: string `exec(`, `cd` then a later `exec`, bare `createCodeContext` / `runCode` on `Sandbox`.
64 
65## Clarify (ask when needed)
66 
67- OK to cut production with `--containers-rollout=immediate` (live processes/terminals/streams may stop)?
68- Self-deployed bridge? Leave on stable.
69- Python interpreter → **`-python`** image variant?
70- Call sites not covered by the map?
71 
72## Upgrade
73 
74### Package and image
75 
76```sh
77npm install @cloudflare/sandbox@next
78```
79 
80```dockerfile
81FROM cloudflare/sandbox:next
82# Python: cloudflare/sandbox:next-python
83```
84 
85Same prerelease tag on Worker and image when not on floating `next`.
86 
87### Code by area
88 
89Apply replacements from the map. For each area, implement from the doc—not from stable habits:
90 
91| Area | Doc |
92| ---- | --- |
93| Commands / handles / waits | [Processes](https://developers.cloudflare.com/sandbox/index.md) · [Processes API](https://developers.cloudflare.com/sandbox/index.md) |
94| `cwd` / `env` / secrets | [Environment](https://developers.cloudflare.com/sandbox/index.md) · [Outbound traffic](https://developers.cloudflare.com/sandbox/sdk/guides/outbound-traffic/index.md) |
95| Drop sessions | [Migrate](https://developers.cloudflare.com/sandbox/sdk/migrate/index.md) · [Lifecycle](https://developers.cloudflare.com/sandbox/index.md) |
96| Terminals | [Terminals](https://developers.cloudflare.com/sandbox/index.md) |
97| Interpreter | [Interpreter](https://developers.cloudflare.com/sandbox/index.md) |
98| Errors | [Errors](https://developers.cloudflare.com/sandbox/index.md) |
99| Durable job across requests | [Process execution — lifetime / durability](https://developers.cloudflare.com/sandbox/index.md) |
100 
101**Commands (shape):**
102 
103```ts
104// Before (stable)
105const result = await sandbox.exec("npm test");
106 
107// After (@next)
108const process = await sandbox.exec(["/bin/bash", "-lc", "npm test"]);
109const result = await process.output({ encoding: "utf8" });
110```
111 
112```ts
113const server = await sandbox.exec(["/bin/bash", "-lc", "npm run dev"], {
114 cwd: "/workspace/app",
115});
116await server.waitForPort(3000, { timeout: 60_000 });
117await server.kill(); // numeric; default 15
118```
119 
120**Terminals (shape):**
121 
122```ts
123const terminal = await sandbox.createTerminal({ command: ["bash"], cwd: "/workspace" });
124const t = await sandbox.getTerminal(terminal.id);
125if (!t) return new Response("terminal gone", { status: 410 });
126return t.connect(request, { cursor, cols, rows });
127```
128 
129**Interpreter (shape):**
130 
131```ts
132import { Sandbox as BaseSandbox } from "@cloudflare/sandbox";
133import { withInterpreter } from "@cloudflare/sandbox/interpreter";
134 
135export class Sandbox extends BaseSandbox<Env> {
136 interpreter = withInterpreter(this);
137}
138```
139 
140**Git (shape):**
141 
142```ts
143const clone = await sandbox.exec(
144 ["git", "clone", "--depth", "1", "--", repoUrl, "/workspace/repo"],
145 { cwd: "/workspace" },
146);
147const result = await clone.output({ encoding: "utf8" });
148```
149 
150Delete transport settings entirely. Remove session APIs. Isolate users with **separate sandbox IDs**.
151 
152### Deploy cutover
153 
154Staging/branch first. Production is **one** deploy of matching Worker + image:
155 
156```sh
157npx wrangler deploy --containers-rollout=immediate
158```
159 
160Leave `rollout_active_grace_period` at default `0` (or set `0` if raised). After cutover, pre-deploy process/terminal IDs are invalid. Details: [Migrate](https://developers.cloudflare.com/sandbox/sdk/migrate/index.md) · [Container rollouts](https://developers.cloudflare.com/containers/configuration/rollouts/index.md)
161 
162## Validate
163 
1641. Lockfile + Dockerfile on the same `@next` line
1652. Typecheck against `@next`
1663. Smoke argv `exec` + `output({ encoding: "utf8" })`
1674. Smoke long process / terminal / interpreter if used
1685. Errors distinguished: unavailable / interrupted-RPC / stale / local wait
1696. No live secrets in sandbox env
1707. Grep again for removed APIs
1718. Production used `--containers-rollout=immediate`
172 
173Then day-to-day work uses **`sandbox-next`**.
174 
175## Red flags — stop and fix
176 
177- Mixing `@next` Worker with stable image (or reverse)
178- Gradual container rollout for this cutover
179- Treating `await exec` as command completion
180- Assuming `cd` / exports persist across `exec` calls
181- One retry wrapper for every error
182- Inventing `gitCheckout`, process stdin, or undocumented APIs
183- Keeping pre-cutover process/terminal IDs after deploy
184- Forcing production cutover without user agreement
185- Putting live secrets in `setEnvVars` / launch `env`
186 
View all files on GitHub →

Details

License
Apache-2.0
Stars on the repo
★ 2,976
Checked
Source
cloudflare/skills ↗
Creator
cloudflare · 17 listings
View creator

Similar skills

See all →
SkillAPI Interface Designaddyosmani/agent-skills · by addyosmaniGuides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.★ 98.7k GitHub starsAgentVersion-Specific Docs Lookupupstash/context7 · by upstashPulls up-to-date, version-specific library docs and code examples into the prompt so the AI stops inventing old APIs.★ 62.3k GitHub starsSkillAdaptyv Bio Foundry APIK-Dense-AI/scientific-agent-skills · by K-Dense-AIHow to use the Adaptyv Bio Foundry API and Python SDK for protein experiment design, submission, and results retrieval. Use this skill whenever the user mentions Adaptyv, Foundry API, protein binding assays, protein screening experiments, BLI/SPR assays, thermostability assays, or wants to submit protein sequences for experimental characterization. Also trigger when code imports `adaptyv`, `adaptyv_sdk`, or `FoundryClient`, or references `foundry-api-public.adaptyvbio.com`.★ 46k GitHub starsSkill.NET Backend Developerwshobson/agents · by wshobsonMaster C#/.NET backend development patterns for building robust APIs, MCP servers, and enterprise applications. Covers async/await, dependency injection, Entity Framework Core, Dapper, configuration, caching, and testing with xUnit. Use when developing .NET backends, reviewing C# code, or designing API architectures.★ 39.9k GitHub starsSkillGemini Agent API Guidegoogle/skills · by googleGuides the usage of Gemini Interactions API on Gemini Enterprise Agent Platform. Use when the user wants to use the stateful, server-managed Interactions API for multi-turn conversations, background execution, streaming, structured output, and function calling on the Agent Platform.★ 20.9k GitHub starsSkillGemini Notebook Automationteng-lin/notebooklm-py · by teng-linInstall, authenticate, troubleshoot, and operate Gemini Notebook through the notebooklm-py CLI or typed async Python API. Use for notebook and source management, grounded chat and research, and artifact generation or download when the user mentions Gemini Notebook, notebooklm-py, the notebooklm CLI, or its Python API. Do not use for the generic Gemini API or unrelated content creation.★ 19.6k GitHub stars

More from cloudflare

SkillSecurity Audit Reviewercloudflare/security-audit-skill · by cloudflareSecurity guidance and vulnerability review for codebases, APIs, services, CLI tools, libraries, and daemons. Use for security questions, focused reviews, vulnerability research, security audits, or pen tests. Run the complete workflow only for explicit codebase audit or pen-test requests, full/comprehensive/end-to-end reviews, or requested report artifacts.★ 26.1k GitHub starsAgentCloudflare MCP Hubcloudflare/mcp-server-cloudflare · by cloudflareCloudflare's hosted servers for Workers, docs, observability, logs and browser rendering.★ 4.3k GitHub starsSkillCloudflare Agents SDK Buildercloudflare/skills · by cloudflareBuild, debug, or review Cloudflare Agents SDK applications using the agents package.★ 3k GitHub starsSkillBasin Analytics Workflowcloudflare/skills · by cloudflareBuild and troubleshoot Cloudflare Basin analytics workflows with Basin Pipelines, Basin Catalog, and Basin SQL. Use for streaming data into R2 Iceberg tables, managing catalogs, or querying those tables; also use for requests using the former Data Platform, Pipelines, R2 Data Catalog, or R2 SQL names.★ 3k GitHub starsSkillCloudflare Email Configcloudflare/skills · by cloudflareImplement or troubleshoot Cloudflare Email Sending and Email Routing integrations and their delivery configuration.★ 3k GitHub starsSkillCloudflare K2 Stream Buildercloudflare/skills · by cloudflareBuild and troubleshoot Cloudflare K2 or K2 Streams durable logs. Use for stream setup, producing from Workers or HTTP, configuring retention and inputs, and consuming through subscriptions.★ 3k GitHub stars