Communitygithub.com

cloudflare/sandbox-next

在 Cloudflare Containers 上建構或維護使用 @cloudflare/sandbox@next (SDK 1.0 預覽版) 的 Sandbox 應用程式。在移植穩定版應用程式時請使用 sandbox-migrate-to-next。

sandbox-next 是什麼?

這個 AI 助手技能專為使用「@cloudflare/sandbox@next」這個 SDK 1.0 預覽版的開發者設計,提供在 Cloudflare Containers 上建立與管理隔離 Linux 環境的完整指南。它涵蓋了 Worker 與 Dockerfile 的建置、process execution API、互動式終端機、檔案掛載及環境變數設定等功能。技能的核心文件強調了三道關卡:第一,確認專案使用的 npm 相依性與容器映像檔屬於預覽線 (next line),若仍使用穩定版則必須切換;第二,嚴格遵循 API 合約,例如 exec() 回傳的是 process handle 而非完成結果,且不支援隱含 shell;第三,根據任務需求導向官方預覽文件 (1.0 preview) 中的對應頁面。此技能明確禁止使用已被移除的穩定版 API(如 gitCheckout、string exec 完成式),並建議優先參考本機安裝的 @next 類型定義,以確保與最新 API 保持一致。總而言之,此技能是開發者在使用 Cloudflare Workers 驅動隔離容器時的關鍵參考指南,能有效避免版本混淆與 API 誤用。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/cloudflare/skills/tree/main/skills/sandbox-next

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Sandbox SDK — @next (1.0 預覽版)

在 Cloudflare Containers 上由 Workers 驅動的隔離 Linux 環境。

優先參考預覽文件與已安裝的 @next 類型定義,而非憑記憶。 API 會變動;此技能是閘門、合約與檢索地圖——並非完整手冊。

我們建議新專案使用此線路。仍使用預設套件的應用程式請參照 sandbox-stable。僅在要求時,透過 sandbox-migrate-to-next 進行移植。

1. 閘門 — 確認套件線路

在撰寫程式碼前,檢查應用程式:

檢查項目必須符合
npm 相依性@cloudflare/sandbox@next(或其他預覽標籤)
容器映像檔同一線路(例如 cloudflare/sandbox:next、next-python)
若發現…動作
預設 @cloudflare/sandbox(無 @next)停止。 載入 sandbox-stable。不要使用此技能的 API。
使用者想要從 stable 移植到 @next停止。 載入 sandbox-migrate-to-next。
僅自行部署的 bridgeBridge 尚未在 1.0 預覽線路上。將 bridge 保留在 stable 套件 + 映像檔上。Bridge (stable)

切勿將 @next Worker 套件與 stable 容器映像檔混合(或反之亦然)。

技能安裝:Agent 設定 · cloudflare/skills

2. 合約 — 不可協商的條件

  • sandbox.exec(argv) 接受一個 argv 列表,並在程序啟動時解析。它回傳一個 handle,而非完成的命令結果。
  • 使用 handle 方法收集結果:output()、logs()、waitForExit()、waitForPort()、waitForLog()、kill(signal?)。
  • 無隱含 shell。Shell 語法需要明確的 shell,例如 ["/bin/bash", "-lc", script]。
  • 每個啟動都是獨立的。一個 exec 中的 cd / export 對下一個不可見。請為每個啟動傳遞 cwd 和 env,或使用一個 shell 指令碼。
  • Process handle 沒有 stdin。互動式使用請使用終端機(createTerminal + connect)。
  • 本機等待 timeout / AbortSignal 僅取消等待。它們不會終止程序。請使用 kill 或 exec 的遠端 timeout。
  • getProcess / listProcesses / getTerminal / listTerminals 不會啟動容器;當沒有容器運行時,它們回傳 null / []。
  • Process 與 terminal ID 屬於目前的容器,而非永遠屬於某個 sandbox ID。對於必須在容器替換後仍持續的工作,請儲存完整的工作資訊(argv、cwd、env、應用程式狀態),而不僅僅是 ID。
  • 僅在 setEnvVars / 啟動 env 中放置非機密設定。即時憑證保留在 Worker 中;當 sandbox 呼叫外部 API 時,請使用出站處理器。
  • 請勿發明已移除的穩定 API(核心上的 gitCheckout、字串 exec 完成、session 執行、sandbox.terminal(request))。
  • 請勿對每個錯誤使用一個重試迴圈(請參閱 Errors 文件)。

最小範例:

import { getSandbox, proxyToSandbox, Sandbox } from "@cloudflare/sandbox";

export { Sandbox };

const sandbox = getSandbox(env.Sandbox, "user-123");
const process = await sandbox.exec(["python3", "-c", "print(2 + 2)"]);
const result = await process.output({ encoding: "utf8" });
// result.stdout, result.exitCode

任務特定 API 文件:references/api-quick-ref.md

範例索引(next 分支):references/examples.md

3. 檢索 — 開啟對應的文件

在實作前請先擷取頁面。已安裝的 @next 類型定義優於猜測。

你需要…開啟
方向確認/選擇預覽版1.0 預覽版概覽
第一個 Worker、wrangler、Dockerfile開始使用
exec、handle、就緒狀態、永續性程序執行
Process API 簽章Processes API
Sandbox ID 與容器/休眠/銷毀的關係生命週期
cwd / env / setEnvVars環境
互動式 PTY / 瀏覽器終端機終端機 · Terminals API
Python/JS 程式碼直譯器直譯器 · Interpreter API
擴充功能模型擴充功能
錯誤類別與復原錯誤 · Errors API
常見失敗疑難排解
API 中心API 參考
檔案、掛載、備份、連接埠、通道、proxyToSandbox共用表面的主要文件(忽略 stable-only 的 session/transport/sandbox.terminal):檔案 · 儲存 / 掛載 · 連接埠 · 通道 · 備份 · 出站流量 · 暴露服務 · 生產環境
範例應用程式next 上的範例
仍在使用 stable 套件sandbox-stable · 主要 Sandbox 文件
移植現有的 stable 應用程式sandbox-migrate-to-next · 移植指南

4. 出貨前檢查

  • Lockfile 與 Dockerfile 應使用相同的 @next 線路
  • 使用已安裝的 @next 類型進行型別檢查
  • 不要在 sandbox 環境中存放即時機密
  • 當使用特定 URL 模式時,生產預覽主機名稱需要在自訂網域上設定萬用字元 DNS

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-migrate-to-next

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/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.

相關技能