Skip to content

feat(sandbox): run shell commands in the vendored jiuwenbox engine - #223

Open
alanhungyl wants to merge 16 commits into
openJiuwen-ai:mainfrom
alanhungyl:feat/sandbox
Open

alanhungyl wants to merge 16 commits into
openJiuwen-ai:mainfrom
alanhungyl:feat/sandbox

Conversation

@alanhungyl

@alanhungyl alanhungyl commented Nov 9, 2026 •

Copy link
Copy Markdown

Paired: GitHub #223 ↔ GitCode !160

Summary

  • Shell commands can run inside the vendored jiuwenbox engine on Linux. The default stays off, a project settings file cannot turn it on, and an invalid sandbox.enabled does not fall back to the host.
  • The bundled server starts with an in-memory bearer token the sandbox cannot see, and the launcher is started with -P from the interpreter prefix so a project package cannot shadow it.
  • The wheel ships the engine inside the package. It does not depend on a jiuwenbox release from PyPI.

Test plan

  • Mocked client, backend, and supervisor tests, including the token, launcher argv, cwd cache, 404 refresh, cancel /stop, and error_message on a sandbox that does not become ready
  • Shell path: sandbox off stays on the host; sandbox on does not use the host executor or an fsatrace prefix; an invalid sandbox.enabled returns an error
  • test_wait_manifest_matches_source
  • Reviewer, Linux with bubblewrap: an enabled command runs in the sandbox, a command outside the writable root is read-only, and a closed server URL returns an error without a host-side side effect

alanhungyl and others added 2 commits November 9, 2026 16:16
Shell is the only tool that can enter the sandbox. The jiuwenbox package
is copied unchanged into third_party/jiuwenbox and installed as an editable
path dependency (jiuwenbox==0.1.0). iCode does not import it at startup.

When sandbox.enabled is set, ShellTools._run returns before the host PTY
or pipe and calls run_shell. An empty sandbox.url starts
python -m jiuwenbox.server.launcher on 127.0.0.1; a filled URL connects to
that server and does not start another. The client uses the existing HTTP
API (health, create, start, exec). The workspace directory is appended as
a read-write bind mount. Approval and the command filter still run first.

A dead server, a timeout, or a non-Linux host returns a tool error and
does not run the command on the host. The default is off, so the previous
host path is unchanged. Project YAML cannot override the three settings.
The settings panel does not show them yet.

Swarm handlers, SysOperation, and the openjiuwen providers are not ported.
Filesystem tools, background jobs, and live PTY output are not wired.
etcd, Conch, the inference proxy, MCP routes, and the jiuwenbox CLI are
copied with the engine and left unused.

Tests cover the mocked client, backend, and supervisor, the shell bypass,
and the setting defaults.

Co-authored-by: Cursor <cursoragent@cursor.com>
Resolve the three conflicts with current main: pass sandbox settings through packs._create_shell, drop the tracked zh-Hans MO, and keep the catalog oracle without a pinned message count. Point the shell sandbox tests at the pack assembly and the renamed execute parameters.

Co-authored-by: Cursor <cursoragent@cursor.com>
@CLAassistant

CLAassistant commented Nov 9, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@openjiuwen-ci-bot

Copy link
Copy Markdown

Hi @alanhungyl, thanks for your contribution!

This pull request is currently waiting for the CLA Assistant check to pass before the CI process can continue.

Please follow the signing link shown by CLA Assistant on this PR. If you have already signed the CLA but the check is still failing, please make sure that all email addresses used in your commits are added to and verified on your GitHub account.

After updating your email settings or signing the CLA, please click Recheck in the CLA Assistant comment/check so the status can be refreshed.

Once the CLA Assistant check passes, CI will continue automatically.

@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 4c134733d5c98242ad76e2af4c6a7d3918493589

🤖 正在生成合并请求摘要,请稍候…

@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 4c134733d5c98242ad76e2af4c6a7d3918493589

🤖 AI 代码检视正在进行中,请稍候…

@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 4c134733d5c98242ad76e2af4c6a7d3918493589

⚠️ 本次变更过大(74 个可审文件、25143 行,预估需 21 轮分片审查),已超出 AI 代码评审的处理范围,本次跳过。建议拆分为更小的 PR 以获得有效评审。

1 similar comment
@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 4c134733d5c98242ad76e2af4c6a7d3918493589

⚠️ 本次变更过大(74 个可审文件、25143 行,预估需 21 轮分片审查),已超出 AI 代码评审的处理范围,本次跳过。建议拆分为更小的 PR 以获得有效评审。

@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 4c134733d5c98242ad76e2af4c6a7d3918493589

任务名称 结果 日志操作
静态检查 ✅SUCCESS 点此跳转
禁用词扫描 ✅SUCCESS 点此跳转
防投毒检查 ✅SUCCESS 点此跳转
开源合规检查 ❌FAILED 点此跳转
UT测试 ✅SUCCESS 点此跳转
ST测试 N/A N/A
build 编译包 N/A N/A
ruff codecheck ✅SUCCESS N/A
issue关联检查 N/A N/A
pr size检查 N/A N/A

The bundled server now authenticates with a token the sandbox cannot see, the launcher cannot be shadowed by a project package, and the wheel ships the engine instead of depending on a missing release.

Co-authored-by: Cursor <cursoragent@cursor.com>
@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 79c87c99135cf8cc4f5b21c9cfbe4a2b860764fc

任务名称 结果 日志操作
静态检查 ✅SUCCESS 点此跳转
禁用词扫描 ✅SUCCESS 点此跳转
防投毒检查 ✅SUCCESS 点此跳转
开源合规检查 ❌FAILED 点此跳转
UT测试 ✅SUCCESS 点此跳转
ST测试 N/A N/A
build 编译包 N/A N/A
ruff codecheck ✅SUCCESS N/A
issue关联检查 N/A N/A
pr size检查 N/A N/A

The writable mount is the workspace, and the bundled server no longer leaves its token, listen URL, or control socket where the sandbox can use them.

Co-authored-by: Cursor <cursoragent@cursor.com>
@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 4460a13b0e20a32f1cc72f3cab31162ff777360a

任务名称 结果 日志操作
静态检查 ✅SUCCESS 点此跳转
禁用词扫描 ✅SUCCESS 点此跳转
防投毒检查 ✅SUCCESS 点此跳转
开源合规检查 ❌FAILED 点此跳转
UT测试 ✅SUCCESS 点此跳转
ST测试 N/A N/A
build 编译包 N/A N/A
ruff codecheck ✅SUCCESS N/A
issue关联检查 N/A N/A
pr size检查 N/A N/A

bubblewrap could not mkdir /run after --remount-ro, so the daemon exited before any command ran.

Co-authored-by: Cursor <cursoragent@cursor.com>
@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 49bc62478dc918dbb1be16a724d985bbe3721449

任务名称 结果 日志操作
静态检查 ✅SUCCESS 点此跳转
禁用词扫描 ✅SUCCESS 点此跳转
防投毒检查 ✅SUCCESS 点此跳转
开源合规检查 ❌FAILED 点此跳转
UT测试 ✅SUCCESS 点此跳转
ST测试 N/A N/A
build 编译包 N/A N/A
ruff codecheck ✅SUCCESS N/A
issue关联检查 N/A N/A
pr size检查 N/A N/A

- Stop a cancelled exec on the server: bearer auth is plain ASGI middleware, so the exec route sees the client disconnect again.

- Clean up every process an exec started, including setsid descendants, when no cgroup exists: each command runs under a per-command subreaper shim, and the process group is always killed.

- Apply sandbox.network on reload like the other sandbox settings; a replaced server is stopped only after its last running command.

- Key the workspace sandbox by its full mount set, keep a replaced read-only sandbox until its running execs finish, and send the physical workdir.

- Narrow the jiuwenswarm scan to real dependencies and register sandbox.network in DEFERRED_KEYS.

Co-authored-by: Cursor <cursoragent@cursor.com>
@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: b2151b45166001581cf10b2dab2de764575c0ed5

任务名称 结果 日志操作
静态检查 ✅SUCCESS 点此跳转
禁用词扫描 ✅SUCCESS 点此跳转
防投毒检查 ✅SUCCESS 点此跳转
开源合规检查 ❌FAILED 点此跳转
UT测试 ✅SUCCESS 点此跳转
ST测试 N/A N/A
build 编译包 N/A N/A
ruff codecheck ✅SUCCESS N/A
issue关联检查 N/A N/A
pr size检查 N/A N/A

…isk cleanup

- Sweep processes a dead shim or fastpath worker left in the sandbox PID namespace. The sweep runs only when bwrap marks a private PID namespace (JIUWENBOX_PRIVATE_PID_NAMESPACE, set only with --unshare-pid).

- Retire a cancelled read-only sandbox so the last in-flight exec deletes it.

- Without a cgroup, stop the whole sandbox once when its writable binds drop below the disk floor.

Co-authored-by: Cursor <cursoragent@cursor.com>
@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 1e4d66ec5e66bfac15d13477bdb86226141b8b89
Stale: GitHub PR head has moved on; preserving this CI result without changing ci-running.

任务名称 结果 日志操作
静态检查 ✅SUCCESS 点此跳转
禁用词扫描 ✅SUCCESS 点此跳转
防投毒检查 ✅SUCCESS 点此跳转
开源合规检查 ❌FAILED 点此跳转
UT测试 ✅SUCCESS 点此跳转
ST测试 N/A N/A
build 编译包 N/A N/A
ruff codecheck ✅SUCCESS N/A
issue关联检查 N/A N/A
pr size检查 N/A N/A

A command cwd outside the workspace is no longer mounted, account control directories stay read-only, and each command joins its cgroup through a passed file descriptor.

Co-authored-by: Cursor <cursoragent@cursor.com>
@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 7c513f873e92807f655b8bf1b6a09f1b8b9db1d2

任务名称 结果 日志操作
静态检查 ✅SUCCESS 点此跳转
禁用词扫描 ✅SUCCESS 点此跳转
防投毒检查 ✅SUCCESS 点此跳转
开源合规检查 ❌FAILED 点此跳转
UT测试 ✅SUCCESS 点此跳转
ST测试 N/A N/A
build 编译包 N/A N/A
ruff codecheck ✅SUCCESS N/A
issue关联检查 N/A N/A
pr size检查 N/A N/A

alanhungyl and others added 2 commits November 20, 2026 10:47
Starting in the home directory was rejected because the read-only engine-directory cover is a reserved path. Successful commands were run twice when stderr looked like an IPC failure, a kept proxy connection answered the next site with the first, and a half-close cut slow responses at two seconds. Cancelled creates stayed READY, and closing one shared manager deleted the other's files and signaled a server that still had a lease.

Co-authored-by: Cursor <cursoragent@cursor.com>
…oses

The in-sandbox forwarder stopped the response direction two seconds after the client shut its write side, so a slow download came back empty.

Co-authored-by: Cursor <cursoragent@cursor.com>
@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: e93cf3fc31a5e5cd2d1d88cba50538fc4636c425

任务名称 结果 日志操作
静态检查 ✅SUCCESS 点此跳转
禁用词扫描 ✅SUCCESS 点此跳转
防投毒检查 ✅SUCCESS 点此跳转
开源合规检查 ❌FAILED 点此跳转
UT测试 ✅SUCCESS 点此跳转
ST测试 N/A N/A
build 编译包 N/A N/A
ruff codecheck ✅SUCCESS N/A
issue关联检查 N/A N/A
pr size检查 N/A N/A

MichaelLing83 added a commit to MichaelLing83/openJiuwen-iCode that referenced this pull request Nov 24, 2026
…lid points

- Process exit no longer orphans the bundled server. The last live
  runtime's release (an explicit RuntimeHold each engine acquires when it
  takes events, injected by assembly) stops every bundled server: a leased
  one gets a bounded wait for its lease, then is stopped anyway, and each
  server is closed exactly once. A network change still waits for leases.
- A lease release runs on its own task, so a cancel while the gate is busy
  no longer skips the decrement and strands the retired server.
- On Linux the launcher gets SIGTERM when iCode dies, even by SIGKILL
  (PR_SET_PDEATHSIG, armed only when iCode passes JIUWENBOX_PARENT_PID).
- SandboxManager forgets state and policy files it deleted, so reusing an
  id in another manager no longer has the old manager unlink them.
- Compliance: copyright headers on the three proxy modules; LICENSE,
  README.OpenSource and README.md for third_party/jiuwenbox; uvicorn
  without [standard] (drops uvloop, httptools, watchfiles, websockets);
  fastapi and annotated-doc in NOTICE.
- fastapi and uvicorn are lazy-only base distributions; Smart Test maps
  the sandbox tests that import the vendored engine.

Co-authored-by: Michael Ling <michael.ling.se@gmail.com>
@0x7c13

0x7c13 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

复查了 #341 的 f9ed0dc。上一轮“取消冷启动后遗留多余 READY 沙箱”的 P1 可以关闭了。相同操作连续跑了三轮,每轮都只剩客户端持有的 1 个 READY。当前建议合并前优先处理前 5 项,其余 8 项按触发范围列在后面。
建议合并前优先处理

  1. 外部沙箱服务在客户端正常退出后会积累沙箱。 两个独立客户端进程先后连接同一个外部服务,各执行一次命令并正常退出。第一次退出后服务端还有 1 个 READY,第二次退出后有 2 个,两次都没有收到 DELETE。默认空闲回收关闭,用户正常重启 iCode 就能触发。同一进程切换 A → B → A 也会丢失旧沙箱,因为缓存只按工作区索引。建议记录每个沙箱所属的服务,并在最后一个使用者退出时向该服务回收。runtime_hold.py L42 · backend.py L477
  2. 冷启动期间,DELETE 可能先删掉登记,稍后启动的子进程却无人回收。 当 DELETE 先于创建请求的断连通知完成,创建任务仍可能启动子进程,随后在等待就绪时被取消。回滚查不到原登记就返回了。用真实 HTTP 路由、SandboxManager 和替代 bwrap 的普通子进程,连续两次得到 DELETE 204、manager 列表为空、操作系统进程状态仍为 running,已排除 zombie。这个时序比上一轮的 READY 问题窄,评为 P2。建议让删除等待对应的创建停止分配资源,并按创建实例确认清理归属。sandbox_manager.py L693 · sandbox.py L195
  3. 明文代理会把源站在上传中途返回的 413 改成 502。 实测客户端只发出部分正文时,源站已返回完整的 413 并关闭连接。代理继续等待请求体,客户端发出剩余正文后只收到 502 Bad Gateway。上传超限因此会被报告成网关故障,调用方也可能错误重试。建议在上传期间处理源站提前到达的最终响应,并覆盖没有 Expect: 100-continue 的场景。guarded_proxy.py L727
  4. CONNECT 隧道一侧写满后,反方向已经到达的数据也停住。 两个方向共用一个循环,其中一次 sendall 阻塞就无法再读另一端。实测上传过程中,下游暂停读取并立即回了 5 字节,正在读取的客户端也收不到,直到下游重新读取上传内容。如果对端需要收到回应才会继续读,连接会一直耗到超时。建议让两个转发方向独立推进。宿主隧道已用真实 socket 复现,沙箱内转发也使用相同写法。guarded_proxy.py L822 · sandbox_daemon.py L710
  5. 新增测试会稳定导致 Windows CI 失败。 Windows 实现明确使用 Path.home(),测试却在所有平台要求得到 POSIX pwd 返回的 /srv/pw-home。CI 实际得到 Windows runner 的家目录。建议分别验证 POSIX 优先使用 pwd 和 Windows 回退到 Path.home()。test_sensitive_binds.py L495 · Windows 失败日志
    其他正确性问题
  6. 中断 engine 关闭会漏掉沙箱使用计数。 两个 engine 都完成 prepare 后,在第一个等待 workflow 排空时取消 shutdown,再正常关闭第二个,计数仍为 1,内置服务的 shutdown 调用次数为 0。重试第一个 engine 的关闭才恢复,但 ACP 已先从会话表中移除了它。建议让关闭流程被中断后仍能完成释放。engine.py L585
  7. 命令在线程池中排队时取消,会泄漏宿主文件描述符。 描述符在入队前分配,关闭责任却在 worker 中。用单 worker 线程池复现时,被取消的 worker 一次都没执行,取消完成后描述符仍然打开。建议明确资源交接点,由提交方回收尚未被 worker 接手的描述符。process.py L3584
  8. 停止已运行的可写 Shell 会等待其他工作区的冷启动。 取消路径重新获取全局缓存锁,只为检查只读沙箱 ID。实测另一任务持锁时,再次取消也无法返回,直到锁释放。建议让可写命令直接跳过这段只读清理。backend.py L746
  9. 工作区恰好是 /tmp 时,命令写入无法按文档约定回到宿主。 生成的参数先执行 --bind /tmp /tmp,随后用 --tmpfs /tmp 覆盖。恢复逻辑只重绑严格子路径,所以 /tmp/project 正常,/tmp 本身被遮住。已验证到参数层。建议支持这个根目录,或在创建时明确拒绝。process.py L329
  10. Shell 的大输出会先全部积累在 daemon 内存中,再撞上宿主的 256 MiB 响应帧上限。 大量构建日志可能占用大量内存,最后连已采集的结果也无法返回。建议在采集端限额,截断后继续排空管道。此项依据源码,本轮未做大内存压力测试。sandbox_daemon.py L1198
  11. vendored Python FastPath 会误报超时,也会吞掉工作目录错误。 用实际 worker 验证,真正超时的命令返回 124 和 Command timed out,上层却得到 timed_out=False。传入不存在的工作目录,命令也能成功执行并返回 0。影响满足 FastPath 条件且没有命令 cgroup 的 Python exec,普通 iCode Bash 通常走另一条路径。sandbox_daemon.py L2328 · process.py L3283
  12. 不同主机或 PID 命名空间共用配置目录时,启动清理可能删除仍在使用的引擎目录。 目前只用目录名里的 PID 查询本机进程表,查不到就递归删除。共享 HOME 或配置卷时,本机无法据此判断另一实例是否已退出。临时目录测试已验证删除分支,未部署真实跨主机环境。建议使用主机本地运行目录,或在回收时校验主机与实例归属。supervisor.py L155
  13. 连接旧版外部服务时,客户端无法保证配置和会话目录按文档所述被隐藏。 健康检查只验证 status=ok,旧服务会忽略新的 hidden_host_paths 字段。工作区包含这些目录时,客户端仍允许继续执行。建议在依赖目录隐藏时确认服务端能力,或明确报出版本不兼容。此项已核对新旧策略模型,未做跨版本部署测试。backend.py L349 · backend.py L880

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants