Communityコーディング&開発github.com

cloudflare/sandbox-migrate-to-next

Cloudflare Sandbox アプリを安定版 @cloudflare/sandbox から @cloudflare/sandbox@next (SDK 1.0 プレビュー) に移行します。すでにプレビュー版を使用しているアプリには sandbox-next を使用してください。

sandbox-migrate-to-next とは?

このスキルは、Cloudflare Sandbox の既存の安定版アプリケーションを、SDK 1.0 プレビュー版(@next)に移行するための包括的なガイドです。移行手順をステップバイステップで提供し、コードベースの監査、パッケージとイメージのアップグレード、コード置換、デプロイ、検証までをカバーします。特に、containers の即時ロールアウト、プロセスハンドルの変更(exec の戻り値がバッファからハンドルに)、セッションAPIの削除、ターミナルとインタプリタの新しいAPIなど、破壊的変更に重点を置いています。このスキルは、Claude Code や Cursor などの AI エージェント向けに設計されており、開発者が移行プロセスを効率的に進められるよう支援します。移行後は sandbox-next スキルを使って日常的な開発を行うことが推奨されています。

対応~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/cloudflare/skills/tree/main/skills/sandbox-migrate-to-next

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

安定版 → Sandbox SDK 1.0 プレビュー (@next) への移行

移行を実行します。 手順は順番に従ってください。詳細はドキュメントにあります。手順で詳細が必要な場合は、リンク先のページを参照してください。

ヒューマンガイド: 移行 · 1.0 プレビュー

新しいプロジェクト は @next (sandbox-next) で開始し、このスキルは使用しません。 日々の安定版作業 → sandbox-stable。非推奨APIのクリーンアップを @next に移行せずに行う場合は、必要に応じてまず 2026年非推奨ガイド を参照してください。

既存のアプリは、1.0 が安定版リリースになったときに備えて、可能なときに移行してください。ユーザーの同意なしに本番環境の切り替えを強制しないでください。

インストール済みの @next の型と移行ドキュメントをメモリより優先してください。

ワークフロー

  1. 確認 ハードルールと置換マップ
  2. 監査 コードベース、ヒットとターゲット形状をリストアップ
  3. 確認 ユーザーと相談(切り替え、ブリッジ、 Python イメージ、不明確なサイト)
  4. アップグレード パッケージ、イメージ、コード
  5. 検証

ユーザーの判断が必要なステップの後は停止します。

ハードルール

  • Worker パッケージとコンテナイメージは 同じ @next ラインである必要があります。
  • 本番環境の切り替えは 即時 コンテナロールアウトを使用します。安定版と @next の制御プロトコルは互換性がなく、段階的ロールアウトは壊れた混合ウィンドウを残します。進行中のコンテナ作業は停止する可能性があります。
  • 切り替え後、await sandbox.exec(...) はプロセスが 開始 したことを意味し、コマンドが 終了 したことは意味しません。
  • 引数 (argv) はそのままです(暗黙のシェルはありません)。シェル構文には明示的なシェルバイナリが必要です。
  • プロセスハンドルには stdin がありません → インタラクティブ入力のための端末。
  • 観測 (Observation) の timeout / AbortSignal は 待機のみ をキャンセルし、プロセスはキャンセルしません。
  • すべてのエラーに対して単一のリトライループはありません。
  • API をでっち上げないでください(コア上の gitCheckout、プロセス stdin、文字列実行完了ヘルパー)。
  • 自己デプロイのブリッジは 安定版 のままにします(まだプレビューラインの一部ではありません)。

置換マップ

安定版@next
SANDBOX_TRANSPORT / transport / setTransport削除 — RPC のみ
await sandbox.exec("cmd") → バッファリングされた結果await sandbox.exec(argv) → ハンドル、その後 output / 待機
execStream / startProcess同じハンドル: logs、waitFor*、kill
デフォルト / 名前付きセッション削除 — cwd/env は起動ごと、または1つのシェルスクリプト
sandbox.terminal(request) / セッション端末createTerminal + terminal.connect(request)
xterm の sessionIdterminalId
Sandbox のインタプリタメソッドwithInterpreter → sandbox.interpreter.*
gitCheckoutexec 経由の git 引数
文字列の kill シグナル数値のみ
ファイル、マウント、バックアップ、ポート、トンネル、proxyToSandboxほとんど変更なし(安定版のページではセッション/トランスポート部分を無視)

詳細: 移行 · 移行後、日々の作業 → sandbox-next

監査

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

また: 文字列 exec(、cd の後続の exec、Sandbox 上の裸の createCodeContext / runCode。

確認(必要なときに質問)

  • --containers-rollout=immediate で本番環境を切り替えてもよいですか?(実行中のプロセス/端末/ストリームが停止する可能性があります)
  • 自己デプロイのブリッジ?安定版のままにします。
  • Python インタプリタ → -python イメージバリアント?
  • マップでカバーされていない呼び出しサイト?

アップグレード

パッケージとイメージ

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

浮動 next ではない場合、Worker とイメージで同じプレリリースタグを使用します。

コードエリアごと

マップの置換を適用します。各エリアについて、安定版の習慣ではなくドキュメントから実装します:

エリアドキュメント
コマンド / ハンドル / 待機プロセス · プロセスAPI
cwd / env / シークレット環境 · アウトバウンドトラフィック
セッションの削除移行 · ライフサイクル
端末端末
インタプリタインタプリタ
エラーエラー
リクエスト間の永続的なジョブプロセス実行 — ライフタイム / 耐久性

コマンド(形状):

// 以前(安定版)
const result = await sandbox.exec("npm test");

// 以後(@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(); // 数値、デフォルト15

端末(形状):

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

インタプリタ(形状):

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

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

Git(形状):

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

トランスポート設定を完全に削除します。セッションAPIを削除します。別々のサンドボックスIDでユーザーを分離します。

デプロイ切り替え

最初にステージング/ブランチ。本番環境は、一致する Worker + イメージの 1回 のデプロイです:

npx wrangler deploy --containers-rollout=immediate

rollout_active_grace_period はデフォルトの 0 のままにします(または引き上げられている場合は 0 に設定します)。切り替え後、デプロイ前のプロセス/端末IDは無効になります。詳細: 移行 · コンテナロールアウト

検証

  1. ロックファイル + Dockerfile が同じ @next ラインにあること
  2. @next に対して型チェック
  3. 引数 exec + output({ encoding: "utf8" }) のスモークテスト
  4. 使用されている場合、長時間プロセス / 端末 / インタプリタのスモークテスト
  5. エラーの区別: 利用不可 / 中断RPC / 古い / ローカル待機
  6. サンドボックス環境にライブシークレットがないこと
  7. 削除されたAPIをもう一度grep
  8. 本番環境で --containers-rollout=immediate が使用されたこと

その後、日々の作業では sandbox-next を使用します。

レッドフラグ — 停止して修正

  • @next Worker と安定版イメージの混在(またはその逆)
  • この切り替えでの段階的コンテナロールアウト
  • await exec をコマンド完了として扱うこと
  • cd / エクスポートが exec 呼び出し間で永続化すると仮定すること
  • すべてのエラーに対する1つのリトライラッパー
  • gitCheckout、プロセス stdin、または文書化されていないAPIをでっち上げること
  • デプロイ後の切り替え前のプロセス/端末IDを保持すること
  • ユーザーの同意なしに本番環境の切り替えを強制すること
  • ライブシークレットを setEnvVars / 起動 env に配置すること

Individual skills in this repo

This repo contains 15 individual skills — each has its own dedicated page.

cloudflare/agents-sdk

Build AI agents on Cloudflare Workers using the Agents SDK. Load when creating stateful agents, durable workflows, real-time WebSocket apps, scheduled tasks, MCP servers, chat applications, voice agents, or browser automation. Covers Agent class, state management, callable RPC, Workflows, durable execution, queues, retries, observability, and React hooks. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.

cloudflare/building-ai-agent-on-cloudflare

Builds AI agents on Cloudflare using the Agents SDK with state management, real-time WebSockets, scheduled tasks, tool integration, and chat capabilities. Generates production-ready agent code deployed to Workers. Use when: user wants to "build an agent", "AI agent", "chat agent", "stateful agent", mentions "Agents SDK", needs "real-time AI", "WebSocket AI", or asks about agent "state management", "scheduled tasks", or "tool calling". Biases towards retrieval from Cloudflare docs over pre-trained knowledge.

cloudflare/building-mcp-server-on-cloudflare

Builds remote MCP (Model Context Protocol) servers on Cloudflare Workers with tools, OAuth authentication, and production deployment. Generates server code, configures auth providers, and deploys to Workers. Use when: user wants to "build MCP server", "create MCP tools", "remote MCP", "deploy MCP", add "OAuth to MCP", or mentions Model Context Protocol on Cloudflare. Also triggers on "MCP authentication" or "MCP deployment". Biases towards retrieval from Cloudflare docs over pre-trained knowledge.

cloudflare/cloudflare

Comprehensive Cloudflare platform skill covering Workers, Pages, storage (KV, D1, R2), AI (Workers AI, Vectorize, Agents SDK), feature flags (Flagship), networking (Tunnel, Spectrum), security (WAF, DDoS), and infrastructure-as-code (Terraform, Pulumi). Use for any Cloudflare development task. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.

cloudflare/cloudflare-email-service

Send and receive transactional emails with Cloudflare Email Service (Email Sending + Email Routing). Use when building email sending (Workers binding or REST API), email routing, Agents SDK email handling, or integrating email into any app — Workers, Node.js, Python, Go, etc. Also use for email deliverability, SPF/DKIM/DMARC, wrangler email setup, MCP email tools, or when a coding agent needs to send emails. Even for simple requests like "add email to my Worker" — this skill has critical config details.

cloudflare/cloudflare-one

Design, configure, troubleshoot, or review Cloudflare One Zero Trust and SASE deployments. Use cloudflare-one-migrations for migration planning from other vendors.

cloudflare/durable-objects

Create and review Cloudflare Durable Objects. Use when building stateful coordination (chat rooms, multiplayer games, booking systems), implementing RPC methods, SQLite storage, alarms, WebSockets, or reviewing DO code for best practices. Covers Workers integration, wrangler config, and testing with Vitest. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.

cloudflare/sandbox-next

Build or maintain Cloudflare Sandbox apps on @cloudflare/sandbox@next (SDK 1.0 preview). Use sandbox-migrate-to-next when porting a stable app.

cloudflare/sandbox-sdk

Build sandboxed applications for secure code execution. Load when building AI code execution, code interpreters, CI/CD systems, interactive dev environments, or executing untrusted code. Covers Sandbox SDK lifecycle, commands, files, code interpreter, and preview URLs. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.

cloudflare/sandbox-stable

Build or maintain Cloudflare Sandbox apps on the stable @cloudflare/sandbox package. Use sandbox-next for preview apps and sandbox-migrate-to-next for stable-to-preview migrations.

cloudflare/skills

Build, migrate, and deploy Next.js apps on Cloudflare Workers with vinext. Use when starting a Next.js project on Cloudflare, moving an existing app to Workers, choosing between vinext and OpenNext, or setting up vinext for Workers. For setup, migration, or deployment, install vinext's upstream skills with `npx skills add cloudflare/vinext` if missing, then read and follow the applicable skill and docs.

cloudflare/turnstile-spin

Set up, repair, or migrate to Cloudflare Turnstile bot verification in an existing frontend and backend, including server-side Siteverify.

cloudflare/web-perf

Analyzes web performance using Chrome DevTools MCP. Measures Core Web Vitals (LCP, INP, CLS) and supplementary metrics (FCP, TBT, Speed Index), identifies render-blocking resources, network dependency chains, layout shifts, caching issues, and accessibility gaps. Use when asked to audit, profile, debug, or optimize page load performance, Lighthouse scores, or site speed. Biases towards retrieval from current documentation over pre-trained knowledge.

cloudflare/workers-best-practices

Reviews and authors Cloudflare Workers code against production best practices. Load when writing new Workers, reviewing Worker code, configuring wrangler.jsonc, or checking for common Workers anti-patterns (streaming, floating promises, global state, secrets, bindings, observability). Biases towards retrieval from Cloudflare docs over pre-trained knowledge.

cloudflare/wrangler

Cloudflare Workers CLI for deploying, developing, and managing Workers, KV, R2, D1, Vectorize, Hyperdrive, Workers AI, Containers, Queues, Workflows, Pipelines, and Secrets Store. Load before running wrangler commands to ensure correct syntax and best practices. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.

関連スキル