Communitygithub.com

cloudflare/sandbox-stable

在稳定的 @cloudflare/sandbox 包上构建或维护 Cloudflare Sandbox 应用。预览应用请使用 sandbox-next,稳定版向预览版迁移请使用 sandbox-migrate-to-next。

sandbox-stable 是什么?

该技能专门用于在 Cloudflare Workers 环境中使用稳定版 @cloudflare/sandbox 包构建或维护沙箱应用。它作为一个严格的入口契约和检索地图,确保开发者正确使用稳定 API,避免与预览版(@next)API 混淆。技能详细说明了如何确认当前应用使用的是稳定包和容器镜像,并提供了何时切换到预览版或执行迁移的明确准则。它涵盖了从执行命令、会话管理、文件操作到生产部署的全方位指南,并强制要求开发者查阅官方文档而非依赖记忆。对于仍在使用稳定包但需清理废弃 API 的情况,技能也提供了专门的清理路径。适用于 Cloudflare Workers 和 Cloudflare Containers 平台。

兼容平台~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 的单句柄模型。打开 Commands 文档;不要在稳定包上发明 @next 的 output() 句柄。
  • 会话可以跨命令保留工作目录和环境(默认会话 / enableDefaultSession、createSession)。当状态需要跨调用传递时,参阅 Sessions 文档。
  • 交互式浏览器终端通常使用稳定包上的 sandbox.terminal(request) 以及会话/xterm 辅助函数——除非包是 @next,否则不要使用预览的 createTerminal。
  • 在使用隧道或大型/二进制流式处理时,优先选择 RPC 传输。HTTP/WebSocket 传输已弃用(见下方的清理指南)。
  • 文件、挂载、端口、隧道、备份、生命周期和解释器:使用主文档获取签名;信任已安装的稳定类型。
  • 非秘密配置放在沙箱环境变量中;实时凭据放在 Worker 中。当进程调用外部 API 时使用出站处理器。
  • 生产预览主机名在使用那些 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、流式、后台进程Commands API · 执行命令 · 后台进程 · 流式输出
会话 / 跨命令的 shell 状态Sessions 概念 · Sessions API
getSandbox 选项、休眠、销毁Lifecycle API · Sandbox 选项
环境变量环境变量
文件Files API · 管理文件 · 文件监控
存储桶 / 挂载Storage API · 挂载存储桶
备份Backups API · 备份与恢复
端口、预览 URL、暴露Ports API · 暴露服务
隧道Tunnels API
代理 / Workers 连接代理请求 · Workers 连接
浏览器 / PTY 终端Terminal API · Terminal 概念 · 浏览器终端
代码解释器Interpreter API · 代码执行
沙箱中的 GitGit 工作流
密钥 / 出口流量出站流量
WebSocketWebSocket 连接
Docker-in-DockerDocker in Docker
生产部署生产部署
Containers 概念Containers
操作指南索引指南
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 包和容器镜像处于相同的稳定版本线
  • 根据已安装的稳定类型进行类型检查
  • 沙箱环境中没有实时密钥
  • 如果使用了已弃用的传输/辅助函数,完成或追踪 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.

相关技能