跳到正文
cccskills
Cloudflare 官方免费在 GitHub 公开

sandbox-migrate-to-next

Migrate existing Cloudflare Sandbox apps from the stable SDK to the SDK 1.0 preview. Audit removed APIs, update the package and container image together, adapt process and terminal code, and validate the changes before production cutover.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

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.

集成工具Cloudflare
查看安装方法

适用场景

  • Audit existing apps for APIs removed in the preview
  • Update the SDK package and container image together
  • Adapt command execution, terminals, and interpreter code
  • Validate the migration and prepare production cutover

包含的文件(1)

  • SKILL.md7.7 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

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 / setTransportRemove — RPC only
await sandbox.exec("cmd") → buffered resultawait sandbox.exec(argv) → handle, then output / waits
execStream / startProcessSame handle: logs, waitFor*, kill
Default / named sessionsGone — cwd/env per launch, or one shell script
sandbox.terminal(request) / session terminalcreateTerminal + terminal.connect(request)
xterm sessionIdterminalId
Interpreter methods on SandboxwithInterpreter → sandbox.interpreter.*
gitCheckoutargv git via exec
String kill signalsNumeric only
Files, mounts, backups, ports, tunnels, proxyToSandboxMostly 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:

AreaDoc
Commands / handles / waitsProcesses · Processes API
cwd / env / secretsEnvironment · Outbound traffic
Drop sessionsMigrate · Lifecycle
TerminalsTerminals
InterpreterInterpreter
ErrorsErrors
Durable job across requestsProcess 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

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

agents-sdk

Cloudflare 官方免费

Build, debug, and review agent applications on Cloudflare using the agents package. The skill guides implementation of persistent state, scheduled tasks, streaming chat, and integrations, consulting official documentation for the relevant APIs and configuration.

中文简介正在准备中。当前显示英语简介。

  • Build an agent that saves and synchronizes its state
  • Add scheduled tasks and background workflows
  • Implement streaming chat with saved messages
cloudflare/skills31482026年10月20日 更新

basin

Cloudflare 官方免费

Build and troubleshoot Cloudflare Basin workflows that collect and transform events, store them in R2 tables, manage table metadata, and query data with SQL. Covers Basin Pipelines, Basin Catalog, and Basin SQL.

中文简介正在准备中。当前显示英语简介。

  • Collect and transform events into R2 tables
  • Manage Iceberg table metadata and maintenance
  • Analyze stored events with SQL
cloudflare/skills31482026年10月20日 更新

cf-cli

Cloudflare 官方免费

Use Cloudflare’s official command-line tool to manage DNS and storage resources and develop or deploy Workers. The skill covers finding commands, checking request details, previewing changes, authentication, and choosing between cf and Wrangler.

中文简介正在准备中。当前显示英语简介。

  • Finding commands for DNS and storage operations
  • Developing and deploying Workers
  • Checking authentication and account profiles
cloudflare/skills31482026年10月20日 更新

cloudflare

Cloudflare 官方免费

Choose Cloudflare products for applications, AI agents, storage, networking, and security. This skill connects project requirements to suitable services, explains how they fit together, and identifies product-specific skills or documentation for implementation.

中文简介正在准备中。当前显示英语简介。

  • Choosing Cloudflare services for a new application
  • Comparing file storage and database options
  • Planning document search and AI agent infrastructure
cloudflare/skills31482026年10月20日 更新

cloudflare-email-service

Cloudflare 官方免费

Integrate transactional email sending and incoming email routing with Cloudflare. The skill covers Workers and external applications, domain setup, message processing, and troubleshooting delivery issues such as authentication problems or unverified forwarding destinations.

中文简介正在准备中。当前显示英语简介。

  • Sending transactional emails from Workers or external apps
  • Processing and forwarding incoming emails
  • Setting up sending domains and bindings
cloudflare/skills31482026年10月20日 更新

cloudflare-one

Cloudflare 官方免费

Plan, configure, and troubleshoot Cloudflare One deployments for secure application access and traffic filtering. Review identity, devices, routes, and logs, then develop changes with validation steps, phased rollout, and rollback plans.

中文简介正在准备中。当前显示英语简介。

  • Design secure access to internal applications
  • Investigate blocked connections using logs
  • Review traffic inspection and data loss prevention rules
cloudflare/skills31482026年10月20日 更新

查看 cloudflare 的全部技能

报告此技能的问题