Communitygithub.com

cloudflare/sandbox-stable

在 Cloudflare Containers 上建置或維護隔離的 Linux 環境,由 Workers 驅動,使用穩定的 @cloudflare/sandbox 套件。若需預覽應用程式請使用 sandbox-next,從穩定版遷移至預覽版則使用 sandbox-migrate-to-next。

sandbox-stable 是什麼?

這個技能提供開發者使用 Cloudflare Sandbox 穩定套件(@cloudflare/sandbox)的完整指南。它定義了在建置或維護隔離的 Linux 容器應用程式時,必須遵守的閘道(gate)、合約(contract)和檢索地圖(retrieval map)。技能的核心是強制檢查 Worker 套件版本和容器映像是否都對應到「穩定」發行線,避免意外混用預覽(@next)API。它列出了不可協商的 API 用法:使用 exec() 執行完整命令,對於長時間運行的程序則使用穩定的命令 API(startProcess、execStream),而非 @next 的單一控制代碼模型。此外,它也提供豐富的連結目錄,方便開發者根據任務(如檔案管理、工作階段、隧道、瀏覽器終端機)直接查閱官方文件。最後,技能也包含清理已棄用 API 的步驟,以及當團隊準備好遷移至 1.0 時,應使用 sandbox-migrate-to-next 技能,而非強制轉換。

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

在你喜歡的 AI 中提問

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

說明文件

Sandbox SDK — 穩定套件

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

優先參考主要 Sandbox 文件以及已安裝的穩定型別,而非依賴記憶。 此技能是一個閘道、一份合約,以及一張檢索地圖,而非完整的手冊。

此行是目前穩定的預設 npm 套件。主要 Sandbox 文件 對此有詳細說明。現有的應用程式可以繼續留在這裡並持續發布。

我們建議新的專案使用 @cloudflare/sandbox@next 搭配 sandbox-next。在可行時,請規劃使用 sandbox-migrate-to-next 進行遷移,以便在 1.0 成為穩定版本時做好準備。除非使用者要求,否則請勿強制進行此移植。

1. 閘道 — 確認套件線路

在編寫程式碼之前,請檢查應用程式:

檢查項目必須符合
npm 依賴預設 @cloudflare/sandbox(非 @next / 預覽標籤)
容器映像對應的穩定映像(非 cloudflare/sandbox:next)
如果您發現…採取行動
@cloudflare/sandbox@next 或 next 映像停止。 載入 sandbox-next。
使用者想要移植到 1.0 / @next停止。 載入 sandbox-migrate-to-next。請勿在穩定套件上部分套用預覽 API。
僅清理已棄用的穩定 API留在原地;請使用 2026 年棄用指南。這並非遷移至 @next。

切勿將穩定的 Worker 套件與 @next 容器映像(或反之)混合使用。

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

2. 合約 — 不可協商的事項

  • await sandbox.exec(command) 接受一個命令字串,並在命令完成時解析,回傳已緩衝的 stdout / stderr / exitCode(以及相關欄位)。
  • 長時間運行和串流處理工作使用穩定的命令 API(startProcess、execStream 以及相關輔助函式),而非 @next 的單一控制代碼模型。請開啟命令文件;請勿在穩定版本上自行發明 @next 的 output() 控制代碼。
  • 工作階段 (Sessions) 可以跨命令保留工作目錄和環境(預設工作階段 / enableDefaultSession、createSession)。當狀態需要在呼叫之間傳遞時,請參閱工作階段文件。
  • 互動式瀏覽器終端機通常使用穩定的 sandbox.terminal(request) 以及工作階段/xterm 輔助函式,除非套件是 @next,否則請勿使用預覽的 createTerminal。
  • 使用隧道或大型/二進位串流時,優先使用 RPC 傳輸。HTTP/WebSocket 傳輸已棄用(請參閱下方的清理指南)。
  • 檔案、掛載點、連接埠、隧道、備份、生命週期和直譯器:請使用主要文件查閱簽章;信任已安裝的穩定型別。
  • 非機密設定放在 Sandbox 環境中;即時憑證放在 Worker 中。當程序呼叫外部 API 時,請使用輸出處理常式 (outbound handlers)。
  • 生產環境的預覽主機名稱在使用那些 URL 模式時,需要自訂網域的萬用 DNS。
  • 在依賴仍然穩定時,請不要套用 @next 的 argv/process.output() API。
  • 自行部署的 bridge 請保持在穩定套件和映像上。Bridge

最小範例:

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

export { Sandbox };

const sandbox = getSandbox(env.Sandbox, "user-123");
const result = await sandbox.exec('python3 -c "print(2 + 2)"');
// result.stdout, result.exitCode, result.success

3. 檢索 — 為任務開啟文件

在實作之前請先擷取頁面。已安裝的穩定型別優先於猜測。

您需要…開啟
入門導覽Sandbox 概覽
第一個 Worker、範本、Docker開始使用
exec、串流、背景程序命令 API · 執行命令 · 背景程序 · 串流輸出
工作階段 / 跨命令的 Shell 狀態工作階段概念 · 工作階段 API
getSandbox 選項、睡眠、銷毀生命週期 API · Sandbox 選項
環境變數環境變數
檔案檔案 API · 管理檔案 · 檔案監控
儲存桶 / 掛載點儲存 API · 掛載儲存桶
備份備份 API · 備份與還原
連接埠、預覽 URL、暴露服務連接埠 API · 暴露服務
隧道隧道 API
Proxy / Workers 連線Proxy 請求 · Workers 連線
瀏覽器 / PTY 終端機終端機 API · 終端機概念 · 瀏覽器終端機
程式碼直譯器直譯器 API · 程式碼執行
Sandbox 中的 GitGit 工作流程
機密 / 對外流量對外流量
WebSocketWebSocket 連線
Docker-in-DockerDocker in Docker
生產部署生產部署
容器概念容器
操作指南索引指南
API 索引API 參考
保持在穩定版的已棄用 API2026 年棄用指南
自行部署的 bridgeBridge · Bridge HTTP API
範例(穩定版/main)GitHub 上的範例
在 1.0 預覽上進行新工作sandbox-next · 1.0 預覽
將現有應用程式移植到 @nextsandbox-migrate-to-next · 遷移

清理已棄用的 API(保持在穩定版)

先更新套件和對應的映像,然後再依照指南進行。典型的搜尋:

rg 'SANDBOX_TRANSPORT|transport:|exposePort\(|enableDefaultSession|execStream\(|readFileStream|writeFileStream'

此路徑不會將您切換到 @next。

4. 發布前檢查

  • Worker 套件和容器映像位於相同的穩定線路
  • 根據已安裝的穩定型別進行型別檢查
  • Sandbox 環境中無即時機密
  • 如果使用已棄用的傳輸/輔助函式,請完成或追蹤 2026 年棄用 清理工作
  • 當團隊準備好升級到 1.0 時,請使用 sandbox-migrate-to-next — 請勿在未經提示的情況下強制轉換

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

相關技能