Skip to content

fix(sandbox): BOTMUX_SANDBOX=0 不再关掉 bot 自己开的沙盒 - #2600

Merged
deepcoldy merged 2 commits into
masterfrom
fix/sandbox-env-zero-keeps-bot-sandbox
Oct 30, 2026
Merged

deepcoldy merged 2 commits into
masterfrom
fix/sandbox-env-zero-keeps-bot-sandbox

Conversation

@deepcoldy

@deepcoldy deepcoldy commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

改了什么

修 #2599:BOTMUX_SANDBOX=0 / false 会把自己开了 sandbox 的 bot 的沙盒关掉,与 resolveSandboxMode 注释和 docs/file-sandbox.md 的描述相反。

resolveSandboxMode(src/adapters/cli/sandbox-mode.ts)改成:

  1. BOTMUX_SANDBOX 取激活值 1 / oncall / scratch → 强制所有 bot 用该模式(不变);
  2. 旧字段 readIsolation: true → oncall(不变);
  3. bot 自己的 sandbox 配置。

未设、空、0、false 都是「不强制」,落到 2、3;其它取值仍报错拒绝启动(不变)。worker spawn、零注入/回复交付判定、默认 worktree 闸门、会话群标题等都走这一个解析器,一处修复全部生效。

文档:docs/file-sandbox.md、文档站 sandbox.md(中英)写清优先级,说明这个环境变量只能全局强制开、不能全局关。

对老用户的影响

  • 没设 BOTMUX_SANDBOX,或设成 1 / oncall / scratch 的部署:行为不变。
  • daemon 环境里设了 BOTMUX_SANDBOX=0 / false 的部署:自己开了 sandbox(或旧 readIsolation)的 bot,新会话会按配置进沙盒(以前被静默关掉)。没开沙盒的 bot 不受影响。这是修 bug,按文档本来就该如此;在不具备 bwrap 的机器上,这类 bot 新会话会像其它开了沙盒的 bot 一样报错拒绝启动,而不是无隔离运行。
  • 已在跑的会话不受影响(沙盒在 spawn 时决定)。
  • 本机 fleet:所有 daemon / supervisor 进程环境里都没有 BOTMUX_SANDBOX,受益面和风险面都为零。

测试

  • test/sandbox-mode.test.ts:0 / false / 空 / 未设 × sandbox: true|oncall|scratch|false × readIsolation 全组合;激活值仍强制;非法值仍抛错。修复前在 master 上复现失败(expected 'off' to be 'oncall'),修复后通过。
  • test/reply-delivery.test.ts:原用例断言「BOTMUX_SANDBOX=0 + cfg scratch → 按 off 解析」,正是本 bug 的行为,改为按 scratch 解析(cursor 回落 send)。
  • test/identity-spawn-matrix.test.ts:原 cell 1/5 靠 BOTMUX_SANDBOX=0 关掉 sandbox:true,改为 sandbox:off;新增 cell 6(BOTMUX_SANDBOX=0 + sandbox:true → oncall,真 bwrap argv 带 --unshare-net,模型 single)与 cell 7(同前但保留网络 → oncall 且 loopback 可达,模型 proven;旧代码在这格解析成 off、模型同为 proven,没有专属格时回归不可见)。
  • 变异:把 resolveSandboxMode 改回「env 非空即短路」,sandbox-mode 与 reply-delivery 的新断言变红,真 bwrap 矩阵 cell 6、cell 7 同时变红(其余 6 格绿)。

既有问题(不在本 PR 范围)

daemon 侧若干历史守卫用 process.env.BOTMUX_SANDBOX === '1'(sandboxEnabled())判断「是否全局强制沙盒」,不认文档同样支持的 oncall / scratch:worker 实际进了沙盒、这些闸门却按未开处理(/adopt 不拒、回复卡仍建等)。master 上即存在,本 PR 未改这些判定点,另见 #2609。

bun run build                                   # 通过(含 tsc)
bunx vitest run test/sandbox-mode.test.ts test/reply-delivery.test.ts   # 80 passed
bunx vitest run <其余 17 个引用 BOTMUX_SANDBOX / resolveSandboxMode 的测试文件>
  # 1738 passed,1 failed:codex-profiles「denied access」以 root 运行时 chmod 不生效,与本改动无关
isolate-run -- bunx vitest run test/identity-spawn-matrix.test.ts test/identity-decision-wiring.test.ts
  # 12 passed,1 failed:cell 3(未改动)在 isolate-run 的网络环境里连不上 loopback,master 上同样失败

Fixes #2599

🤖 Generated with Claude Code

env 只在取激活值(1/oncall/scratch)时强制所有 bot;未设、空、0、false
都按 bot 自己的 sandbox 配置走,非法值仍报错。文档写清优先级。

Fixes #2599

Co-Authored-By: Claude Opus 5.5 <[email protected]>
按复审意见:
- identity-spawn-matrix 新增 cell 7:BOTMUX_SANDBOX=0 + sandbox:true
  + network:true → oncall 且 loopback 可达 → proven。旧实现在此格解析为
  off、模型同为 proven,没有专属断言时回归不可见。
- identity-decision-report 文件头不再把 worker/frozen 分叉描述成
  「BOTMUX_SANDBOX=0 forced the spawn off」(修复后该组合不可能 force off)。
- identity-decision-wiring 与 docs/execution-identity.md 的矩阵格数
  同步为七格。

变异(解析器回退旧的非空短路):cell 6、cell 7 同时变红,其余 6 格绿。

Co-Authored-By: Claude Code <[email protected]>
@deepcoldy

deepcoldy commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner Author

合后核验(落地提交 42432fe):

未做:发版、部署。

补充:master 上包含本次改动的 0946357(#2615)CI run 41078884029 完整跑完,全部通过(build、test 1–4/4 与汇总 test、bun-test、bun-binary / musl / darwin)。

@github-actions

Copy link
Copy Markdown

@deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。

这次运行覆盖 3400614…0946357b3(9 个提交),同批合入的还有 #2542 #2611 #2578 #2590 #2612 #2594 #2548 #2615,失败不一定由本 PR 引起。

用例 跑道 状态 失败信息
Gemini basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, the main content area displays a topic conversation. I am looking for a specific text bubble from "Gemini" containing the string "ACK-e2e-gemini-179337940473…

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

🚀 Released in v3.56.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BOTMUX_SANDBOX=0 会关掉 bot 自己开的沙盒,与注释和文档相反

1 participant