sandbox-migrate-to-next

작성자: cloudflare

Cloudflare Sandbox 앱을 안정적인 @cloudflare/sandbox에서 @cloudflare/sandbox@next(Sandbox SDK 1.0 미리보기)로 포팅할 때, 또는 사용자가 다음을 요청할 때 사용합니다…

npx skills add https://github.com/cloudflare/skills --skill sandbox-migrate-to-next

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 worksandbox-stable. Deprecated-API cleanup without moving to @next2026 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 SandboxwithInterpretersandbox.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

cloudflare의 다른 스킬

dependabot-review
cloudflare
Dependabot PR을 분석하여 각 업데이트된 패키지에서 실제로 변경된 사항과 해당 변경 사항이 이 저장소에 영향을 미치는지 확인합니다. 변경된 API/메서드 등을 보고합니다.
module-registry
cloudflare
workerd에서 모듈 레지스트리를 작업할 때 로드 — 모듈 해석, 컴파일, 평가, 등록을 읽기, 수정, 디버깅, 검토하는 경우…
reproduce
cloudflare
cloudflare/agents GitHub 이슈를 재현하기 위해 최소한의 Agents/Worker 프로젝트를 스캐폴딩하고 임시 Cloudflare 계정에 배포한 후 보고합니다…
local-explorer
cloudflare
로컬 탐색기 또는 로컬 API에 제품/리소스를 추가하는 방법. 새로운 로컬 API나 UI 라우트를 구현할 때 사용합니다.
open-pr
cloudflare
클라우드플레어/에이전트 GitHub 이슈와 재현 결과를 바탕으로 수정 PR을 한 번에 생성합니다 — 브랜치 생성, 변경, 테스트, 푸시, 그리고 이슈에 연결된 PR 열기까지 수행합니다.
write-endpoints
cloudflare
chanfana를 사용한 OpenAPI 엔드포인트 구축을 위한 종합 가이드 - 스키마 정의, 요청 검증, CRUD 작업, D1 데이터베이스 통합 등
agents-sdk
cloudflare
Cloudflare Workers에서 Agents SDK를 사용하여 AI 에이전트를 구축하세요. 상태 저장 에이전트, 지속 가능한 워크플로우, 실시간 WebSocket 앱, 예약된 작업 등을 생성할 때 로드하세요.
changelog
cloudflare
Cloudflare 문서 사이트의 제품 변경 로그 항목을 생성, 업데이트 및 검토합니다. 변경 로그 MDX 파일을 생성하거나 기존 파일을 편집할 때 로드합니다.