TCB Sandbox Skill
Operate tcb-remote-workspace safely and consistently through @tcb-sandbox/cli.
Runtime Assumptions
This skill assumes the following tcb-sandbox runtime behavior:
- - one sandbox instance is affinitized to one session
- one instance may handle concurrent tool requests within that same session
- idle instances may freeze and later wake on incoming requests
- instances rotate and are destroyed after TTL expiration
When troubleshooting, consider lifecycle transitions (freeze/wake/rotate) as first-class causes of transient behavior.
When To Use This Skill
Use this skill when a user asks to do any of the following against a TRW workspace:
- - inspect workspace health or capabilities
- read/write/edit/search files via TRW tools
- run session-scoped shell commands
- create/send-input/read-output/resize/kill session PTY processes
- manage session secrets
- upload/download binary files
- discover or open preview ports
- snapshot and restore workspace state
Use direct local shell/file operations instead when the user explicitly asks to operate only on the local machine and not on TRW.
Preconditions
Before any operation, confirm all required runtime inputs exist:
- 1. CLI is installed (
tcb-sandbox command is available) - endpoint is available (
TCB_SANDBOX_ENDPOINT or --endpoint) - session is available for non-health commands (
TCB_SANDBOX_SESSION_ID or --session-id)
If any precondition is missing, stop and request the missing input with a concrete example command.
First-Run Bootstrap
Use this bootstrap sequence when the environment may be fresh.
Step A: Detect CLI availability
CODEBLOCK0
If command is missing, install CLI:
CODEBLOCK1
Then re-run:
CODEBLOCK2
Step B: Detect minimum runtime config
Do not read arbitrary local environment variables. Only use explicit user-provided values or the two declared runtime variables:
Optional extra headers can be passed only when required by gateway policy:
If either value is missing, stop and ask user to pass explicit flags (--endpoint, --session-id) or set only those exact variables.
Step C: First connectivity smoke test
CODEBLOCK3
Only continue to tool/file/preview actions after health passes.
Safety Rules
Always follow these rules:
- 1. Never print plaintext secrets unless the user explicitly requests secret retrieval.
- Prefer top-level secret tools (
secrets_set/get/list/delete) and avoid plaintext exposure in shell history. - Do not assume session reuse across users; session id is the security boundary.
- For mutating operations (
write, edit, bash, files upload, secrets-store set/delete, pty-service create/send_input/resize/kill), restate intent before execution. - For destructive actions, log a high-risk notice and execute directly.
- Keep logs concise and redact sensitive headers (
Authorization, Token, Cookie, session-like headers). - Never request or read unrelated local credentials; only handle secrets explicitly named and approved by the user for TRW session use.
High-Risk Operation Notice Template
Before running bash, any secrets-store mutation/retrieval command, or PTY lifecycle operations (pty-service create/send_input/resize/kill), emit a high-risk notice in this format:
INLINECODE26
Do not require any interactive confirmation step. Continue execution after logging the notice.
Standard Execution Flow
Run operations in this order unless the user asks otherwise.
1) Connectivity and readiness
CODEBLOCK4
If not ready, report readiness failure and stop.
2) Capability discovery
CODEBLOCK5
If /api/docs is temporarily unavailable, CLI fallback docs are acceptable for read-only planning, but warn that runtime behavior may differ.
3) Session-scoped operation
For all non-health operations, include session id:
CODEBLOCK6
4) Result reporting
Return:
- - what command was executed
- whether it succeeded
- key output fields only
- next recommended step
Capability-First Flow (Updated)
When the task involves session abilities (secrets, binary transfer, preview, PTY, git snapshot, MCP, CLI wrappers, or skills), always run the metadata workflow before executing. Authoritative copy also ships in MCP instructions and .workspace-info.md (see repo src/capability-agent-guide.ts).
Mandatory order (do not skip describe)
- 1.
capability-list — discover ids. Add --reveal-paths when you need absolute paths for capability-register or to read skill files under packagePath. - INLINECODE36 — read
executionBy, executionVia, actions, and route/schema hints. Never guess how to run the capability. - Install/register branch (only for new custom capabilities)
-
capability-install <id> ... —
instruction only; nothing is installed server-side and
the capability list does not change yet.
- Run returned steps in the sandbox (usually
bash).
-
capability-register <id> ... with final
--command /
--server-name+
--command /
--package-path.
-
capability-list again immediately after successful register — refresh what exists in the session so you do not “forget” the new capability.
- Call
capability-describe again if needed (e.g. on the new id from the refreshed list).
Skip steps 3 entirely when a built-in or already-registered capability already satisfies the task.
Alternative (stdio MCP servers only) — session mcporter CRUD:
-
List keys: list-mcp-servers →
available_mcp_servers.
-
Add: add-mcp-servers --data '{“serverName”:”…”,”command”:”…”}' or
--server-name <name> --command <cmd>.
Same server name already present = no overwrite (幂等).
-
Delete: remove-mcp-servers --server-name <name> or
--data '{“serverNames”:[“a”,”b”]}'. Built-in server names
cloudbase /
memory cannot be removed.
-
Update: remove-mcp-servers then
add-mcp-servers with new
command/
args/
env.
-
Discover & call server tools: mcporter 'list <server> --schema --output json' for tool schemas;
mcporter “call '<server>.<tool>(param: \”value\”)”' for invocation.
- If your MCP client
only exposes
capability_* tools, use
capability-register /
capability-remove (kind=mcp) and
read .mcporter/mcporter.json instead.
- 4. Execute using the route from describe
-
executionBy=capability +
executionVia=capability_invoke → native only:
capability-invoke <id> <action> --parameters '{…}'. Native ids:
secrets-store,
files-transfer,
preview-service,
pty-service,
git-archive.
-
executionVia=bash →
bash '<command>'.
-
executionVia=bash+mcporter →
mcporter “call '<server>.<tool>(...)”'.
-
executionBy=caller +
executionVia=caller_defined (skills) →
read the skill
entryFile under
packagePath and follow it on the
agent side; the remote workspace does not auto-run skill logic.
Failure and fallback
- - If
capability_invoke returns not executed by capability_invoke: stop invoking; re-run capability_describe and follow sandbox/caller routing. - If the ability is missing from
capability_list: use bash / read / grep / glob and PATH discovery (generic tools are intentionally not all listed as capabilities).
Thin MCP / HTTP tool surfaces
- - Most non-native capabilities are metadata-only; execution follows
capability_describe hints, not capability_invoke. - When top-level tools (
secrets_*, preview_*, files_*, pty_*) exist, prefer them for UX parity with HTTP; when they are not exposed, capability_invoke on native ids is the supported path (same handlers underneath).
Command Playbooks
Health
CODEBLOCK7
Docs and tool discovery
CODEBLOCK8
Core tools (read / write / edit / bash / grep / glob / ls / batch)
CODEBLOCK9
Git Push
Push a workspace snapshot to a remote git repository.
CODEBLOCK10
Workspace Snapshot / Restore
Snapshot and restore workspace state via S3. Requires SNAPSHOTS3* env vars on the server.
CODEBLOCK11
Session mcporter (add / remove / list MCP servers)
CODEBLOCK12
Capability management
CODEBLOCK13
Secrets (primary via CLI subcommands)
Set:
CODEBLOCK14
Get (plaintext — only when user explicitly asks):
CODEBLOCK15
List keys (metadata only, no plaintext):
CODEBLOCK16
Delete:
CODEBLOCK17
Binary files
CODEBLOCK18
PTY
PTY subcommands call top-level PTY tools.
CODEBLOCK19
Preview
Preview subcommands call top-level preview tools.
CODEBLOCK20
Standard Tools Quick Map
Use this quick map to pick the right tool fast.
- -
read: read a text file from workspace - INLINECODE98 : create or overwrite a text file
- INLINECODE99 : apply targeted string-level edits to existing text
- INLINECODE100 : search file content by pattern
- INLINECODE101 : search files by name/path patterns
- INLINECODE102 : inspect directory structure
- INLINECODE103 : run shell commands in session workspace
- INLINECODE104 : execute multiple tool calls with one request
INLINECODE105 mode note:
- - default mode is
execute when mode is omitted - pass
mode=dry_run explicitly to request simulated execution with risk summary, decision, and file-level changeSet - Background processes are NOT reliably preserved after a
bash call returns (orphan processes may be reaped). For long-running servers, prefer pty create --command '<cmd>' or bash 'tmux new-session -d -s <name> "<cmd>"'. Subshell syntax (cmd > /tmp/log 2>&1 &) can work for simple cases but is fragile. Do NOT use nohup.
Selection rule:
- - if task is content lookup, start with
read or INLINECODE115 - if task is structure discovery, use
ls or INLINECODE117 - if task mutates text, choose
edit first and write only when full overwrite is intended - if task needs runtime state (build, test, start service), use INLINECODE120
Case Study: Secrets Lifecycle
Goal:
- - store API key safely, validate availability, rotate value, and remove stale key
Commands:
CODEBLOCK21
Reporting checklist:
- - key name(s) affected
- action type (
set/rotate/delete) - whether plaintext was intentionally exposed
- follow-up recommendation (for example, restart service to reload env)
Case Study: Preview Bring-Up and Diagnosis
Goal:
- - start a service, discover exposed ports, return stable preview URL, and diagnose failures
Commands:
CODEBLOCK22
Troubleshooting hints:
- - no port found: check whether app started successfully and is listening on INLINECODE124
- unexpected port: inspect app logs and runtime config (
PORT, framework defaults) - preview unreachable: verify session id consistency between start command and preview query
Task Templates
Use these templates for common user intents.
Template 1: Read then edit a remote file
Goal:
- - inspect a file and then apply a targeted content update
Commands:
CODEBLOCK23
Report format:
- - target path
- before/after key delta
- verification result
Template 2: Upload artifact and verify checksum/size
Goal:
- - ship a local file into session workspace and verify transfer
Commands:
CODEBLOCK24
Report format:
- - remote path
- file size
- checksum
Template 3: Start service and return preview URL
Goal:
- - run service in workspace and provide reachable preview URL
Commands:
CODEBLOCK25
Report format:
- - detected port(s)
- chosen port and reason
- final preview URL
Error Handling Matrix
Missing endpoint
Symptom:
Action:
- - ask user for
--endpoint or INLINECODE128
Missing session for session-scoped command
Symptom:
Action:
- - ask user for
--session-id or INLINECODE131
401/403 class authorization errors
Action:
- - verify session id value and gateway header mapping
- verify optional extra headers (
TCB_SANDBOX_HEADERS_JSON) when custom gateway policies are enabled
408/timeout
Action:
- - retry with larger INLINECODE133
- split large tool actions into smaller steps
Tool call failure (HTTP problem details)
Action:
- - surface
detail exactly from RFC 9457 response - propose one concrete retry strategy based on the failed tool
Output Contract
When running in automation context:
- - prefer INLINECODE135
- include only structured fields required by downstream steps
- for failed requests, parse and forward
error_code, retryable, retry_after, and INLINECODE139
When running in interactive context:
- - keep
pretty output - summarize key result and next step in plain language
Non-Goals
This skill does not:
- - bypass TRW security boundaries
- persist long-term credentials outside session-scoped secret management
- guarantee behavior outside documented TRW endpoints
TCB 沙箱技能
通过 @tcb-sandbox/cli 安全且一致地操作 tcb-remote-workspace。
运行时假设
本技能假设 tcb-sandbox 运行时行为如下:
- - 一个沙箱实例与一个会话绑定
- 一个实例可在同一会话内处理并发工具请求
- 空闲实例可能冻结,并在收到请求后唤醒
- 实例在 TTL 过期后轮换并销毁
排查问题时,应将生命周期转换(冻结/唤醒/轮换)视为瞬态行为的主要原因。
何时使用本技能
当用户要求对 TRW 工作空间执行以下任何操作时,使用本技能:
- - 检查工作空间健康状态或能力
- 通过 TRW 工具读取/写入/编辑/搜索文件
- 运行会话范围的 shell 命令
- 创建/发送输入/读取输出/调整大小/终止会话 PTY 进程
- 管理会话密钥
- 上传/下载二进制文件
- 发现或打开预览端口
- 快照和恢复工作空间状态
当用户明确要求仅操作本地机器而非 TRW 时,改用直接的本地 shell/文件操作。
前置条件
在任何操作之前,确认所有必需的运行时输入存在:
- 1. CLI 已安装(tcb-sandbox 命令可用)
- 端点可用(TCBSANDBOXENDPOINT 或 --endpoint)
- 非健康检查命令需要会话可用(TCBSANDBOXSESSION_ID 或 --session-id)
如果缺少任何前置条件,停止并请求缺失的输入,附带具体命令示例。
首次运行引导
当环境可能是全新的时,使用此引导序列。
步骤 A:检测 CLI 可用性
bash
tcb-sandbox --version
如果命令缺失,安装 CLI:
bash
pnpm add -g @tcb-sandbox/cli@0.3.9
然后重新运行:
bash
tcb-sandbox --version
步骤 B:检测最小运行时配置
不要读取任意的本地环境变量。仅使用用户明确提供的值或两个声明的运行时变量:
- - TCBSANDBOXENDPOINT
- TCBSANDBOXSESSION_ID
仅在网关策略要求时,可传递可选的额外头部:
如果任一值缺失,停止并要求用户传递显式标志(--endpoint、--session-id)或仅设置这些确切的变量。
步骤 C:首次连通性冒烟测试
bash
tcb-sandbox --endpoint $TCBSANDBOXENDPOINT health
仅在健康检查通过后,才继续执行工具/文件/预览操作。
安全规则
始终遵循以下规则:
- 1. 除非用户明确请求密钥检索,否则绝不打印明文密钥。
- 优先使用顶层密钥工具(secretsset/get/list/delete),避免在 shell 历史中暴露明文。
- 不要假设会话跨用户重用;会话 ID 是安全边界。
- 对于变更操作(write、edit、bash、files upload、secrets-store set/delete、pty-service create/sendinput/resize/kill),在执行前重申意图。
- 对于破坏性操作,记录高风险通知并直接执行。
- 保持日志简洁,并编辑敏感头部(Authorization、Token、Cookie、类似会话的头部)。
- 绝不请求或读取无关的本地凭据;仅处理用户明确命名并批准用于 TRW 会话的密钥。
高风险操作通知模板
在运行 bash、任何 secrets-store 变更/检索命令或 PTY 生命周期操作(pty-service create/send_input/resize/kill)之前,按以下格式发出高风险通知:
高风险操作通知:<确切命令意图>,目标会话=<会话ID>,预期影响=<变更内容>。
不需要任何交互式确认步骤。记录通知后继续执行。
标准执行流程
除非用户另有要求,否则按此顺序运行操作。
1) 连通性和就绪状态
bash
tcb-sandbox --endpoint $TCBSANDBOXENDPOINT health
如果未就绪,报告就绪失败并停止。
2) 能力发现
bash
tcb-sandbox --endpoint $TCBSANDBOXENDPOINT docs
tcb-sandbox --endpoint $TCBSANDBOXENDPOINT docs
如果 /api/docs 暂时不可用,CLI 回退文档可用于只读规划,但需警告运行时行为可能不同。
3) 会话范围操作
对于所有非健康检查操作,包含会话 ID:
bash
tcb-sandbox --endpoint $TCBSANDBOXENDPOINT --session-id $TCBSANDBOXSESSION_ID
4) 结果报告
返回:
能力优先流程(已更新)
当任务涉及会话能力(密钥、二进制传输、预览、PTY、Git 快照、MCP、CLI 包装器或技能)时,始终在执行前运行元数据工作流。权威副本也随 MCP instructions 和 .workspace-info.md 提供(参见仓库 src/capability-agent-guide.ts)。
强制顺序(不要跳过描述)
- 1. capability-list — 发现 ID。当需要 capability-register 或读取 packagePath 下的技能文件的绝对路径时,添加 --reveal-paths。
- capability-describe — 读取 executionBy、executionVia、actions 以及路由/模式提示。绝不要猜测如何运行能力。
- 安装/注册分支(仅针对新的自定义能力)
- capability-install
... — 仅指令;服务端不安装任何内容,能力列表暂时不变。
- 在沙箱中运行返回的步骤(通常为 bash)。
- 使用最终的 --command / --server-name+--command / --package-path 运行 capability-register ...。
- 成功注册后立即再次运行 capability-list — 刷新会话中存在的内容,以免“忘记”新能力。
- 如果需要,再次调用 capability-describe(例如,针对刷新列表中的新 ID)。
当内置或已注册的能力已满足任务时,完全跳过步骤 3。
替代方案(仅 stdio MCP 服务器)— 会话 mcporter CRUD:
- 列出密钥: list-mcp-servers → availablemcpservers。
- 添加: add-mcp-servers --data {serverName:…,command:…} 或 --server-name --command 。相同的服务器名称已存在 = 不覆盖(幂等)。
- 删除: remove-mcp-servers --server-name 或 --data {serverNames:[a,b]}。内置服务器名称 cloudbase / memory 无法移除。
- 更新: remove-mcp-servers 然后使用新的 command/args/env 运行 add-mcp-servers。
- 发现并调用服务器工具: 使用 mcporter list --schema --output json 获取工具模式;使用 mcporter call .(param: \value\) 进行调用。
- 如果您的 MCP 客户端仅暴露 capability_* 工具,请改用 capability-register / capability-remove(kind=mcp)并读取 .mcporter/mcporter.json。
- 4. 使用 describe 中的路由执行
- executionBy=capability + executionVia=capability_invoke → 仅原生:capability-invoke --parameters {…}。原生 ID:secrets-store、files-transfer、preview-service、pty-service、git-archive。
- executionVia=bash → bash 。
- executionVia=bash+mcporter → mcporter call .(...)。
- executionBy=caller + executionVia=caller_defined(技能)→ 读取 packagePath 下的技能 entryFile,并在