Sandbox Migrate To Next
CloudflareOfficialPublished by Cloudflare
- Skill
- Workflow
- Cloud and DevOps
- Apache-2.0
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured procedure for migrating existing Cloudflare Sandbox applications from the stable SDK to the 1.0 preview (@next) version. It covers code refactoring, package updates, container image configuration, and the required deployment strategy for production cutover. The workflow emphasizes safety by requiring user confirmation before production changes and provides a clear mapping of deprecated stable APIs to their new @next counterparts.
What it does
- Audits existing codebases for deprecated stable SDK patterns.
- Provides a comprehensive mapping of stable APIs to @next equivalents.
- Guides the update of package dependencies and Dockerfile images.
- Outlines the necessary code changes for process execution, terminal handling, and interpreter usage.
- Defines the required deployment strategy using immediate container rollouts.
- Includes a validation checklist to ensure the migration is successful.
When to use it
- When you are ready to migrate an existing stable Cloudflare Sandbox application to the 1.0 preview.
- When you need to ensure your application is prepared for the upcoming 1.0 stable release.
- When you need to refactor code that relies on deprecated stable SDK features like transport settings or session management.
Advantages
- Ensures alignment between Worker packages and container images.
- Prevents common pitfalls like gradual rollouts during breaking changes.
- Provides clear, actionable steps for complex refactors like process handling.
- Reduces risk by requiring explicit user approval for production cutovers.
Usage examples
- “Help me migrate my current Cloudflare Sandbox project to the 1.0 preview.”
- The agent will initiate the audit process, list the necessary code changes based on the replacement map, and guide you through the package and image updates.
- “How do I update my exec calls for the new SDK?”
- The agent will provide the new pattern for using process handles and the .output() method instead of the previous buffered result approach.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/cloudflare/sandbox-migrate-to-next/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip sandbox-migrate-to-next.zip -d .agents/skills
Documentation by Cloudflare
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
Review hard rules and the replacement map
Audit the codebase; list hits and target shapes
Clarify with the user (cutover, bridge, Python image, unclear sites)
Upgrade package, image, and code
Validate
Stop after any step that needs a user decision.
Hard rules
Worker package and container image must be the same
@nextline.Production cutover uses immediate container rollout. Stable and
@nextcontrol 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/AbortSignalcancel the wait only, not the process.No single retry loop for every error.
Do not invent APIs (
gitCheckouton 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 →
-pythonimage variant?Call sites not covered by the map?
Upgrade
Package and image
npm install @cloudflare/sandbox@nextFROM cloudflare/sandbox:next
# Python: cloudflare/sandbox:next-pythonSame 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 15Terminals (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=immediateLeave 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
Lockfile + Dockerfile on the same
@nextlineTypecheck against
@nextSmoke argv
exec+output({ encoding: "utf8" })Smoke long process / terminal / interpreter if used
Errors distinguished: unavailable / interrupted-RPC / stale / local wait
No live secrets in sandbox env
Grep again for removed APIs
Production used
--containers-rollout=immediate
Then day-to-day work uses sandbox-next.
Red flags — stop and fix
Mixing
@nextWorker with stable image (or reverse)Gradual container rollout for this cutover
Treating
await execas command completionAssuming
cd/ exports persist acrossexeccallsOne retry wrapper for every error
Inventing
gitCheckout, process stdin, or undocumented APIsKeeping pre-cutover process/terminal IDs after deploy
Forcing production cutover without user agreement
Putting live secrets in
setEnvVars/ launchenv
Skill feedback
If the user reports that this skill gave incorrect or outdated guidance, or is missing information, read references/skill-feedback.md.
Files
- ATTRIBUTION.mdAdded by AutoGineer882 B
- LICENSELicence file added by AutoGineer11.1 KiB
- SKILL.md7.9 KiB
- references/skill-feedback.md2.8 KiB
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Python, Needs Node.js
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- Cloudflare
- Publisher
- Cloudflare (Official)
- Source
- cloudflare/skills · skills/sandbox-migrate-to-next · commit 6eb6c78
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Cloudflare or Cloudflare.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download sandbox-migrate-to-next.zip