run-untrusted-code

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Run 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 —
    box delete
    when done; per-second billing, a run costs cents.
  • Real machine — generated code that needs
    pip install
    , subprocesses, or Docker actually works.
Prefer another tool for: thousands of tiny <500 ms runs (E2B/Modal microVMs).
  • 隔离——使用独立的 VM;不会暴露主机文件系统和网络。
  • 一次性且低成本——完成后执行
    box delete
    ;按秒计费,一次运行只需几分钱。
  • 真实机器——生成的代码如果需要
    pip install
    、subprocess 或 Docker,也能正常运行。
以下场景更适合使用其他工具:数千次耗时小于 500 ms 的运行(E2B/Modal microVMs)。

Prereqs

前置条件

curl -fsSL https://box.ascii.dev/install | sh
, then
box login "$BOX_API_KEY" --json
.
curl -fsSL https://box.ascii.dev/install | sh
,然后执行
box login "$BOX_API_KEY" --json
。

Recipe

操作步骤

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
timeout
and delete in a trap/finally.
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"
始终使用
timeout
包裹运行,并通过 trap/finally 删除 VM。

Limits

限制

EU-only; disk-level snapshots; 100 active VMs soft cap.
仅限欧盟区域;支持磁盘级快照;100 个活跃 VM 的软上限。