sandbox-next
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSandbox SDK — @next
(1.0 preview)
@nextSandbox SDK — @next
(1.0预览版)
@nextIsolated Linux environments on Cloudflare Containers, driven from Workers.
Prefer preview docs and installed types over memory. APIs change; this skill is a gate, a contract, and a retrieval map—not a full manual.
@nextWe recommend new projects on this line. Apps still on the default package use . Port only when asked, via .
sandbox-stablesandbox-migrate-to-next基于Cloudflare Containers构建的隔离Linux环境,由Workers驱动。
优先参考预览版文档和已安装的类型定义,而非记忆内容。 API会发生变更;本技能是一个入口、一份约定和检索指南——并非完整手册。
@next我们推荐新项目使用该版本线。仍在使用默认包的应用请使用**。仅在要求时才进行迁移,通过**完成。
sandbox-stablesandbox-migrate-to-next1. Gate — confirm the package line
1. 入口——确认包版本线
Before writing code, inspect the app:
| Check | Must match |
|---|---|
| npm dependency | |
| Container image | Same line (e.g. |
| If you find… | Action |
|---|---|
Default | Stop. Load |
User wants to port stable → | Stop. Load |
| Self-deployed bridge only | Bridge is not on the 1.0 preview line yet. Keep bridge on stable package + image. Bridge (stable) |
Never mix an Worker package with a stable container image (or the reverse).
@nextSkills install: Agent setup · cloudflare/skills
编写代码前,检查应用:
| 检查项 | 必须匹配 |
|---|---|
| npm依赖 | |
| 容器镜像 | 同一版本线(例如 |
| 如果发现… | 操作 |
|---|---|
默认 | 停止。加载** |
用户希望将稳定版迁移至 | 停止。加载** |
| 仅自行部署的bridge | Bridge目前尚未纳入1.0预览版版本线。请继续将Bridge与稳定版包和镜像配合使用。Bridge(稳定版) |
切勿将 Worker包与稳定版容器镜像混用(反之亦然)。
@next技能安装:Agent设置 · cloudflare/skills
2. Contract — non-negotiables
2. 约定——不可协商规则
- takes an argv list and resolves when the process starts. It returns a handle, not a finished command result.
sandbox.exec(argv) - Collect results with handle methods: ,
output(),logs(),waitForExit(),waitForPort(),waitForLog().kill(signal?) - No implicit shell. Shell syntax needs an explicit shell, e.g. .
["/bin/bash", "-lc", script] - Each launch is independent. A /
cdin oneexportis not visible to the next. Passexecandcwdper launch, or one shell script.env - Process handles have no stdin. Interactive use → terminals (+
createTerminal).connect - Local wait /
timeoutcancel the wait only. They do not kill the process. UseAbortSignalorkill’s remoteexec.timeout - /
getProcess/listProcesses/getTerminaldo not start a container; they returnlistTerminals/nullwhen none is up.[] - Process and terminal IDs belong to the current container, not forever to a sandbox ID. For work that must survive replace, store the full job (argv, cwd, env, app state)—not only an id.
- Non-secret config only in / launch
setEnvVars. Live credentials stay in the Worker; use outbound handlers when the sandbox calls external APIs.env - Do not invent removed stable APIs (on core, string-
gitCheckoutcompletion, session execution,exec).sandbox.terminal(request) - Do not use one retry loop for every error (see Errors docs).
Minimal shape:
ts
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.exitCodeOptional non-exhaustive cheatsheet (process/terminal/interpreter only): references/api-quick-ref.md
Examples index ( branch): references/examples.md
Examples index (
next- 接收一个argv列表,并在进程启动时完成解析。它返回一个句柄,而非命令执行完成的结果。
sandbox.exec(argv) - 通过句柄方法收集结果:,
output(),logs(),waitForExit(),waitForPort(),waitForLog()。kill(signal?) - 无隐式Shell。Shell语法需要显式指定Shell,例如。
["/bin/bash", "-lc", script] - 每次启动都是独立的。在一个中执行的
exec/cd对下一个export不可见。可在每次启动时传入exec和cwd,或使用一个Shell脚本。env - 进程句柄无标准输入。交互式使用请使用终端(+
createTerminal)。connect - 本地等待的/
timeout仅取消等待操作,不会终止进程。请使用AbortSignal或kill的远程exec。timeout - /
getProcess/listProcesses/getTerminal不会启动容器;当无容器运行时,它们会返回listTerminals/null。[] - 进程和终端ID属于当前容器,并非永久绑定到sandbox ID。对于必须在替换后仍能运行的任务,请存储完整的作业信息(argv、cwd、env、应用状态)——而非仅存储ID。
- 仅将非机密配置放入/启动
setEnvVars中。敏感凭证请保留在Worker中;当sandbox调用外部API时,使用出站处理程序。env - 请勿使用已移除的稳定版API(核心包中的、字符串形式的
gitCheckout完成、会话执行、exec)。sandbox.terminal(request) - 请勿对所有错误使用同一重试循环(请参阅错误文档)。
最简示例:
ts
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可选的非详尽速查表(仅包含进程/终端/解释器):references/api-quick-ref.md
示例索引(分支):references/examples.md
示例索引(
next3. Retrieve — open the doc for the task
3. 检索——针对任务打开对应文档
Fetch the page before implementing. Installed types win over guesses.
@next| You need to… | Open |
|---|---|
| Orient / choose preview | 1.0 preview overview |
| First Worker, wrangler, Dockerfile | Get started |
| Process execution |
| Process API signatures | Processes API |
| Sandbox ID vs container vs sleep/destroy | Lifecycle |
| Environment |
| Interactive PTY / browser terminal | Terminals · Terminals API |
| Python/JS code interpreter | Interpreter · Interpreter API |
| Extensions model | Extensions |
| Error classes and recovery | Errors · Errors API |
| Common failures | Troubleshooting |
| API hub | API reference |
Files, mounts, backups, ports, tunnels, | Main docs for shared surfaces (ignore stable-only session/transport/ |
| Example apps | examples on |
| Still on stable package | |
| Porting an existing stable app | |
实现前请查阅对应页面。已安装的类型定义优先于猜测内容。
@next| 你需要… | 打开链接 |
|---|---|
| 了解概况/选择预览版 | 1.0预览版概述 |
| 首个Worker、wrangler、Dockerfile | 快速开始 |
| 进程执行 |
| 进程API签名 | 进程API |
| Sandbox ID vs 容器 vs 休眠/销毁 | 生命周期 |
| 环境配置 |
| 交互式PTY/浏览器终端 | 终端 · 终端API |
| Python/JS代码解释器 | 解释器 · 解释器API |
| 扩展模型 | 扩展 |
| 错误类与恢复 | 错误处理 · 错误API |
| 常见故障 | 故障排查 |
| API中心 | API参考 |
文件、挂载、备份、端口、隧道、 | 共享功能的主文档(忽略稳定版专属的会话/传输/ |
| 示例应用 | next分支上的示例 |
| 仍在使用稳定版包 | |
| 迁移现有稳定版应用 | |
4. Before you ship
4. 发布前检查
- Lockfile and Dockerfile on the same line
@next - Typecheck against installed types
@next - No live secrets in sandbox env
- Production preview hostnames need wildcard DNS on a custom domain when using those URL patterns
- Lockfile和Dockerfile使用同一版本线
@next - 基于已安装的类型定义进行类型检查
@next - sandbox环境中无敏感凭证
- 使用特定URL模式时,生产预览主机名需要在自定义域名上配置通配符DNS