opencomputer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseYou have access to the CLI for managing OpenComputer cloud sandboxes. Use it to create sandboxes, execute commands, manage checkpoints, and more.
oc你可以使用 CLI来管理OpenComputer云沙箱,可用于创建沙箱、执行命令、管理检查点等操作。
ocFirst-time setup (run this BEFORE any other oc
command)
oc首次设置(在执行任何其他oc
命令前运行)
ocBefore running any sandbox command, make sure the user is set up. Do these checks in order, only fixing what's broken:
在运行任何沙箱命令前,请确保用户已完成设置。按顺序执行以下检查,仅修复存在问题的部分:
1. Is the oc
CLI installed?
oc1. 是否已安装oc
CLI?
ocbash
which ocIf it returns a path → installed, skip to step 2.
If it returns nothing / non-zero exit → install it with the official one-liner:
bash
curl -fsSL https://raw.githubusercontent.com/diggerhq/opencomputer/main/scripts/install.sh | bashThis installs to . If is not on the user's PATH, tell them to add to their shell rc file, and use the full path for the rest of this session.
oc~/.local/bin/oc~/.local/binexport PATH="$HOME/.local/bin:$PATH"~/.local/bin/ocbash
which oc如果返回路径 → 已安装,跳至步骤2。
如果无返回/退出码非零 → 使用官方单行命令安装:
bash
curl -fsSL https://raw.githubusercontent.com/diggerhq/opencomputer/main/scripts/install.sh | bash此命令会将安装至。如果不在用户的PATH中,请告知用户将添加到其shell配置文件中,并在本次会话中使用完整路径。
oc~/.local/bin/oc~/.local/binexport PATH="$HOME/.local/bin:$PATH"~/.local/bin/oc2. Is the user logged in (API key configured)?
2. 用户是否已登录(API密钥已配置)?
bash
oc config showIf is shown (even masked) → logged in, you're done.
API KeyIf no API key is set, OR a sandbox command fails with an auth error (, "unauthorized", "missing API key"):
401- Open the OpenComputer dashboard in the user's browser so they can create a key:
- macOS:
open https://app.opencomputer.dev - Linux:
xdg-open https://app.opencomputer.dev
- macOS:
- Tell the user (in chat) to:
- Sign in / sign up at the page that just opened
- Create an API key
- Run this command in their terminal once they have the key:
bash
oc config set api-key YOUR_API_KEY
- Wait for the user to confirm they've set the key before proceeding.
Do not prompt them for the key in the chat — they should paste it into their own terminal so it never leaves their machine.
bash
oc config show如果显示(即使是掩码形式)→ 已登录,设置完成。
API Key如果未设置API密钥,或沙箱命令因认证错误失败(、"unauthorized"、"missing API key"):
401- 在用户浏览器中打开OpenComputer控制台,以便他们创建密钥:
- macOS:
open https://app.opencomputer.dev - Linux:
xdg-open https://app.opencomputer.dev
- macOS:
- 在聊天中告知用户:
- 在打开的页面登录/注册
- 创建一个API密钥
- 获取密钥后在终端中运行以下命令:
bash
oc config set api-key YOUR_API_KEY
- 等待用户确认已设置密钥后再继续操作。
请勿在聊天中提示用户输入密钥——他们应将密钥粘贴到自己的终端中,确保密钥不会离开本地设备。
CLI Reference
CLI参考文档
Sandbox Lifecycle
沙箱生命周期
bash
undefinedbash
undefinedCreate a sandbox (returns sandbox ID)
Create a sandbox (returns sandbox ID)
oc sandbox create --timeout 300 --cpu 1 --memory 512
oc sandbox create --env KEY=VALUE --env KEY2=VALUE2
oc sandbox create --secret-store my-secrets --metadata project=demo
oc create # shortcut
oc sandbox create --timeout 300 --cpu 1 --memory 512
oc sandbox create --env KEY=VALUE --env KEY2=VALUE2
oc sandbox create --secret-store my-secrets --metadata project=demo
oc create # shortcut
List running sandboxes
List running sandboxes
oc sandbox list
oc ls # shortcut
oc sandbox list
oc ls # shortcut
Get sandbox details
Get sandbox details
oc sandbox get <sandbox-id>
oc sandbox get <sandbox-id>
Kill a sandbox
Kill a sandbox
oc sandbox kill <sandbox-id>
oc sandbox kill <sandbox-id>
Hibernate (saves state to S3, can wake later)
Hibernate (saves state to S3, can wake later)
oc sandbox hibernate <sandbox-id>
oc sandbox hibernate <sandbox-id>
Wake a hibernated sandbox
Wake a hibernated sandbox
oc sandbox wake <sandbox-id> --timeout 300
oc sandbox wake <sandbox-id> --timeout 300
Update timeout
Update timeout
oc sandbox set-timeout <sandbox-id> <seconds>
undefinedoc sandbox set-timeout <sandbox-id> <seconds>
undefinedExecute Commands
执行命令
oc exec--wait--json--detachbash
undefinedoc exec--wait--json--detachbash
undefinedStream live (default)
Stream live (default)
oc exec <sandbox-id> -- echo hello
oc exec <sandbox-id> --cwd /app -- npm install
oc exec <sandbox-id> --timeout 120 -- make build
oc exec <sandbox-id> --env NODE_ENV=production -- node server.js
oc exec <sandbox-id> -- echo hello
oc exec <sandbox-id> --cwd /app -- npm install
oc exec <sandbox-id> --timeout 120 -- make build
oc exec <sandbox-id> --env NODE_ENV=production -- node server.js
Buffered + JSON envelope (exitCode, stdout, stderr) — required for scripting
Buffered + JSON envelope (exitCode, stdout, stderr) — required for scripting
oc exec <sandbox-id> --wait --json -- whoami
oc exec <sandbox-id> --wait --json -- whoami
Fire-and-forget; prints the session id so you can re-attach later
Fire-and-forget; prints the session id so you can re-attach later
oc exec <sandbox-id> --detach -- long-running-job
oc exec <sandbox-id> --detach -- long-running-job
Manage exec sessions
Manage exec sessions
oc exec list <sandbox-id>
oc exec attach <sandbox-id> <session-id>
oc exec kill <sandbox-id> <session-id>
undefinedoc exec list <sandbox-id>
oc exec attach <sandbox-id> <session-id>
oc exec kill <sandbox-id> <session-id>
undefinedCheckpoints
检查点
Checkpoints snapshot a running sandbox. You can restore to a checkpoint (in-place revert) or spawn new sandboxes from one (fork).
bash
undefined检查点会对运行中的沙箱进行快照。你可以恢复到某个检查点(原地回滚)或从检查点生成新沙箱(分叉)。
bash
undefinedCreate a checkpoint
Create a checkpoint
oc checkpoint create <sandbox-id> --name "after-setup"
oc checkpoint create <sandbox-id> --name "after-setup"
List checkpoints
List checkpoints
oc checkpoint list <sandbox-id>
oc checkpoint list <sandbox-id>
Restore sandbox to a checkpoint (in-place revert)
Restore sandbox to a checkpoint (in-place revert)
oc checkpoint restore <sandbox-id> <checkpoint-id>
oc checkpoint restore <sandbox-id> <checkpoint-id>
Spawn a new sandbox from a checkpoint (fork)
Spawn a new sandbox from a checkpoint (fork)
oc checkpoint spawn <checkpoint-id> --timeout 300
oc checkpoint spawn <checkpoint-id> --timeout 300
Delete a checkpoint
Delete a checkpoint
oc checkpoint delete <sandbox-id> <checkpoint-id>
undefinedoc checkpoint delete <sandbox-id> <checkpoint-id>
undefinedCheckpoint Patches
检查点补丁
Patches are scripts applied when sandboxes are spawned from a checkpoint. Use them to customize forked environments.
bash
undefined补丁是从检查点生成沙箱时应用的脚本,用于自定义分叉环境。
bash
undefinedCreate a patch (reads script from file)
Create a patch (reads script from file)
oc patch create <checkpoint-id> --script ./setup.sh --description "Install deps"
oc patch create <checkpoint-id> --script ./setup.sh --description "Install deps"
Create a patch from stdin
Create a patch from stdin
echo "apt install -y curl" | oc patch create <checkpoint-id> --script -
echo "apt install -y curl" | oc patch create <checkpoint-id> --script -
List patches
List patches
oc patch list <checkpoint-id>
oc patch list <checkpoint-id>
Delete a patch
Delete a patch
oc patch delete <checkpoint-id> <patch-id>
undefinedoc patch delete <checkpoint-id> <patch-id>
undefinedPreview URLs
预览URL
Expose a sandbox port via a public URL.
bash
undefined通过公共URL暴露沙箱端口。
bash
undefinedCreate a preview URL
Create a preview URL
oc preview create <sandbox-id> --port 3000
oc preview create <sandbox-id> --port 8080 --domain myapp.example.com
oc preview create <sandbox-id> --port 3000
oc preview create <sandbox-id> --port 8080 --domain myapp.example.com
List preview URLs
List preview URLs
oc preview list <sandbox-id>
oc preview list <sandbox-id>
Delete a preview URL
Delete a preview URL
oc preview delete <sandbox-id> <port>
undefinedoc preview delete <sandbox-id> <port>
undefinedInteractive Shell
交互式Shell
bash
undefinedbash
undefinedOpen an interactive terminal session
Open an interactive terminal session
oc shell <sandbox-id>
oc shell <sandbox-id> --shell /bin/zsh
undefinedoc shell <sandbox-id>
oc shell <sandbox-id> --shell /bin/zsh
undefinedGlobal Flags
全局标志
All commands support:
- — output as JSON instead of tables
--json - — override API key
--api-key <key> - — override API URL
--api-url <url>
所有命令均支持:
- — 以JSON格式输出而非表格形式
--json - — 覆盖API密钥
--api-key <key> - — 覆盖API URL
--api-url <url>
Workflow Patterns
工作流模式
Create and use a sandbox
创建并使用沙箱
bash
ID=$(oc create --json | jq -r '.sandboxID')
oc exec $ID --wait -- apt update
oc exec $ID --wait -- apt install -y nodejs
oc exec $ID -- node -e "console.log('hello')"
oc sandbox kill $IDbash
ID=$(oc create --json | jq -r '.sandboxID')
oc exec $ID --wait -- apt update
oc exec $ID --wait -- apt install -y nodejs
oc exec $ID -- node -e "console.log('hello')"
oc sandbox kill $IDCheckpoint workflow (setup once, fork many)
检查点工作流(一次设置,多次分叉)
bash
undefinedbash
undefinedCreate base environment
Create base environment
ID=$(oc create --json | jq -r '.sandboxID')
oc exec $ID --wait -- apt update
oc exec $ID --wait -- apt install -y python3 pip
oc exec $ID --wait -- pip install flask
ID=$(oc create --json | jq -r '.sandboxID')
oc exec $ID --wait -- apt update
oc exec $ID --wait -- apt install -y python3 pip
oc exec $ID --wait -- pip install flask
Checkpoint it
Checkpoint it
CP=$(oc checkpoint create $ID --name "python-flask" --json | jq -r '.id')
CP=$(oc checkpoint create $ID --name "python-flask" --json | jq -r '.id')
Wait for checkpoint to be ready
Wait for checkpoint to be ready
oc checkpoint list $ID
oc checkpoint list $ID
Spawn copies from the checkpoint
Spawn copies from the checkpoint
FORK1=$(oc checkpoint spawn $CP --json | jq -r '.sandboxID')
FORK2=$(oc checkpoint spawn $CP --json | jq -r '.sandboxID')
undefinedFORK1=$(oc checkpoint spawn $CP --json | jq -r '.sandboxID')
FORK2=$(oc checkpoint spawn $CP --json | jq -r '.sandboxID')
undefinedAdd a patch to customize forks
添加补丁自定义分叉环境
bash
oc patch create $CP --script ./inject-config.sh --description "Add app config"bash
oc patch create $CP --script ./inject-config.sh --description "Add app config"All future spawns from $CP will run inject-config.sh on boot
All future spawns from $CP will run inject-config.sh on boot
undefinedundefinedImportant Notes
重要注意事项
- Always use and parse with
--jsonwhen you need to extract IDs or fields programmatically.jq - Sandbox IDs look like . Checkpoint IDs are UUIDs.
sb-xxxxxxxx - Checkpoints take a few seconds to become . Poll with
readyif needed.oc checkpoint list - Use to clean up sandboxes when done.
oc sandbox kill - The command exits with the remote process exit code.
oc exec
- 当需要以编程方式提取ID或字段时,请始终使用并通过
--json解析。jq - 沙箱ID格式为,检查点ID为UUID。
sb-xxxxxxxx - 检查点需要几秒时间变为状态,必要时可使用
ready轮询。oc checkpoint list - 使用完毕后请用清理沙箱。
oc sandbox kill - 命令会以远程进程的退出码退出。
oc exec