run-untrusted-code
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRun untrusted code (Box)
运行不受信任的代码(Box)
Use this right before executing code you generated or fetched when running it locally would be risky: shell scripts, scraped snippets, dependency installs, anything with side effects. Pattern: create → run → delete, so nothing touches the host.
在本地运行可能有风险时,请于执行由你生成或获取的代码之前使用此工具:shell 脚本、抓取的代码片段、依赖安装,以及任何可能产生副作用的内容。模式:创建 → 运行 → 删除,确保任何内容都不会触及主机。
Why Box
为什么使用 Box
- Isolation — a separate VM; the host filesystem and network are never exposed.
- Disposable & cheap — when done; per-second billing, a run costs cents.
box delete - Real machine — generated code that needs , subprocesses, or Docker actually works.
pip install
Prefer another tool for: thousands of tiny <500 ms runs (E2B/Modal microVMs).
- 隔离——使用独立的 VM;不会暴露主机文件系统和网络。
- 一次性且低成本——完成后执行 ;按秒计费,一次运行只需几分钱。
box delete - 真实机器——生成的代码如果需要 、subprocess 或 Docker,也能正常运行。
pip install
以下场景更适合使用其他工具:数千次耗时小于 500 ms 的运行(E2B/Modal microVMs)。
Prereqs
前置条件
curl -fsSL https://box.ascii.dev/install | shbox login "$BOX_API_KEY" --jsoncurl -fsSL https://box.ascii.dev/install | shbox login "$BOX_API_KEY" --jsonRecipe
操作步骤
bash
box_id="$(box new --json | jq -r 'select(.event == "ready") | .id')"
trap 'box delete "$box_id" --json' EXIT # never leak a VM
box ssh "$box_id" -- "mkdir -p /run && cat > /run/main.sh" < ./main.sh
box ssh "$box_id" -- "cd /run && timeout 120 bash main.sh"Always wrap in and delete in a trap/finally.
timeoutbash
box_id="$(box new --json | jq -r 'select(.event == "ready") | .id')"
trap 'box delete "$box_id" --json' EXIT # never leak a VM
box ssh "$box_id" -- "mkdir -p /run && cat > /run/main.sh" < ./main.sh
box ssh "$box_id" -- "cd /run && timeout 120 bash main.sh"始终使用 包裹运行,并通过 trap/finally 删除 VM。
timeoutLimits
限制
EU-only; disk-level snapshots; 100 active VMs soft cap.
仅限欧盟区域;支持磁盘级快照;100 个活跃 VM 的软上限。