Skip to content

feat(sandbox): run shell commands in the vendored jiuwenbox engine, continuation of PR#223 - #341

Open
MichaelLing83 wants to merge 28 commits into
openJiuwen-ai:mainfrom
MichaelLing83:pr223-merge-main
Open

MichaelLing83 wants to merge 28 commits into
openJiuwen-ai:mainfrom
MichaelLing83:pr223-merge-main

Conversation

@MichaelLing83

@MichaelLing83 MichaelLing83 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Paired: GitHub #341 ↔ GitCode !237

What type of PR is this?

/kind

What does this PR do / why do we need it:

  • Need to describe clearly

Which issue(s) this PR fixes:

Fixes #

What scenarios were tested, and what were the verification results(Function, performance, reliability, etc.):

  • Need to describe clearly

Self-checklist:(Please check carefully,and mark an x in the [] brackets. We will review your completion status.)

    • Design: Has the solution corresponding to the PR been reviewed by the Maintainer, and have all review comments been replied to and revised
    • Test: Has the code in the PR been fully covered by UT/ST test cases, and have the newly added test cases been uploaded to the repository along with this PR or already uploaded.
    • Verification: Does the PR description contains a detailed description of the verification results regarding the achievement of the expected goals for the Feature, Refactor, and Bugfix to this PR.
    • Interface: Does it involve changes to external interfaces? The corresponding changes have been approved by the interface review organization, and the annotation information for the API has been correctly refreshed.
    • Document: Does it involve modifications to the official website documentation? If so, please submit the materials to the Doc repository in a timely manner.

alanhungyl and others added 18 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>
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>
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>
bubblewrap could not mkdir /run after --remount-ro, so the daemon exited before any command ran.

Co-authored-by: Cursor <cursoragent@cursor.com>
A write-side shutdown is distinct from a full close only on Linux poll, and closing a half-closed socket does not wake a blocked read on macOS. The guide now states the writable workspace, what a command can read and send, and that a detached command keeps running after stop or timeout.
Windows and macOS skip the two exec-close tests that wait for a blocked read to notice the socket close. The sandbox runs only on Linux, and macOS does not wake that read the same way.
Hide account homes, cover credential paths, and stop detached processes when a cgroup can be created. A missing cgroup no longer blocks sandbox startup. The default network reaches public hosts only through a proxy.

Co-authored-by: Cursor <cursoragent@cursor.com>
The private tmpfs that hides host sockets was also hiding a workspace created under /tmp. Re-bind that workspace, and any read-only cover inside it, after the tmpfs. Format the new sandbox tests and drop the lambdas ruff rejects.

Co-authored-by: Cursor <cursoragent@cursor.com>
The signature was the last file ruff format --check still rewrote.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep the sandbox waits and the RSI waits in the trajectory manifest. The refresh matched source and reopened nothing.

Co-authored-by: Cursor <cursoragent@cursor.com>
- 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>
…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>
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>
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>
Port the sandbox settings and their tests to the workdir-layer names
(WorkdirMerge, Source.WORKDIR, NOT_ALLOWED_IN_WORKDIR, load_settings(workdir=)).
- Stop the bundled sandbox from an AgentEngine method, so engine.py no
  longer passes a bare self to a call (layering guard).
- Guard the pwd home lookup with sys.platform so ty passes on win32.
- Move the protected-cwd backend tests into their own module to keep
  test_backend.py under the 2000-line cap.
- Update the supervisor shutdown test to the current rule: shutdown
  leaves a leased replaced child until its lease ends.
- Refresh the trajectory wait manifest.

Co-authored-by: Michael Ling <michael.ling.se@gmail.com>
@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: d34c5a8a7d58e728b24a7a9673cd93fa98bda670

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

@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: d34c5a8a7d58e728b24a7a9673cd93fa98bda670

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

@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: d34c5a8a7d58e728b24a7a9673cd93fa98bda670

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

1 similar comment
@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: d34c5a8a7d58e728b24a7a9673cd93fa98bda670

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

@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: d34c5a8a7d58e728b24a7a9673cd93fa98bda670

任务名称 结果 日志操作
静态检查 ✅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

…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>
@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 374d89d08e9088794d5031ab00d8792231c2e72b

任务名称 结果 日志操作
静态检查 ✅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

…ate registered

The iCode client generates the sandbox id and sends it with the create, so
the id is known before the server answers. A cancel, or any failure before
the sandbox is ready, deletes that id; a 409 (the id belongs to another
sandbox) deletes nothing. A sandbox that failed to start is no longer left
behind in its error phase.

On the server, CreateDelivery records the ref the call registered, and the
route's rollback deletes only that ref through
delete_sandbox(expected=ref). A create refused for an existing id, or
dropped before it registered, no longer deletes another call's sandbox.

Co-authored-by: Michael Ling <michael.ling.se@gmail.com>
@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: f9ed0dc4866cb9affa1fd64e0b9dd047269f2ac9

任务名称 结果 日志操作
静态检查 ✅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

@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: f9ed0dc4866cb9affa1fd64e0b9dd047269f2ac9

任务名称 结果 日志操作
静态检查 ✅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

…server

Each sandbox.url keeps its own cached sandbox ids, so switching away and back
reuses the first server's sandbox instead of sending its ids to another one.
Setting sandbox.url or turning the sandbox off retires the bundled server once
no command leases it. A cancelled writable command no longer waits for the
cache lock, and a cancel also forgets a read-only id a parked server holds.

Co-authored-by: Michael Ling <michael.ling.se@gmail.com>
- concurrent execs restart a dead sandbox once (start epoch) and fail unless
  the restart left it READY
- refuse a host bind exactly onto /tmp, /run or /var/run
- an explicit read-write bind drops only enumerated read-only copies of its
  destination; a protective read-only cover stays and keeps --remount-ro
- close cgroup fds when an exec is cancelled while queued, when
  exec_background is cancelled, and when the daemon's os.pipe fails
- the post-kill drain no longer spins once stdout is at EOF
- cap each daemon and FastPath output stream at 16 MiB with a truncation note;
  FastPath reports timeouts as timeouts, does not run code when it cannot enter
  the workdir, and falls back when the workdir is missing
- Landlock: a rule for a file grants only file rights on that file, so
  /run/guarded-proxy.sock no longer makes /run writable
- seccomp: allow kill(0) (each command has its own session), guard
  rt_sigqueueinfo, rt_tgsigqueueinfo and pidfd_open against pids 1 and 2,
  return ENOSYS for pidfd_send_signal, and add missing x86_64 fallback numbers

Co-authored-by: Michael Ling <michael.ling.se@gmail.com>
@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 555d79a98f3ee9ea4f9d8a7944a3764faa107539

任务名称 结果 日志操作
静态检查 ✅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

- Delete the sandboxes created on each configured sandbox.url when the
  last runtime releases, and return the bundled-server claim when an
  engine shutdown is cancelled before its release starts.
- A DELETE during a cold start waits for the runtime start, so a child
  spawned after the delete began is still cleaned up.
- The guarded proxy watches the origin during an upload and relays an
  early final response (e.g. 413) instead of a 502, lingering briefly so
  the client can read it; tunnels and the in-sandbox bridge move each
  direction independently.
- Engine homes are owned through a file lock and tagged with the host,
  so a shared config volume no longer loses a live home to a pid lookup.
- The server's /health lists hidden_host_paths; an external service that
  does not is refused when a mount would show the config or session dir.
- Windows CI: normalize sandbox paths with posixpath and fake the
  platform in the password-database test.

Co-authored-by: Michael Ling <michael.ling.se@gmail.com>
@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 161a85c3fe8d4d3e90220a2c1bb26215b1347afe

任务名称 结果 日志操作
静态检查 ✅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

…reason first

A bind of the host root makes the sandbox's own root directory a host
directory, so the start fails with a message whose first line said only the
exit code. The client now refuses a / workspace, extra directory or legacy
first cwd before creating a sandbox (a workspace before the bundled server
starts), and the server puts the daemon's last output line into the first
line of its startup error, which is the line the client shows.

Co-authored-by: Michael Ling <michael.ling.se@gmail.com>
After DELETE_START_WAIT_SECONDS, or when the delete is cancelled, a task
finishes the delete once the start ends. The id stays registered in
DELETING until then, so no other create can take it.

Co-authored-by: Michael Ling <michael.ling.se@gmail.com>
…h features in the route

The daemon's bridge relay is now guarded_proxy._tunnel copied verbatim, and
a test compares the two. /health lists hidden_host_paths itself; the bare
model claims no features. Tests cover the startup reason line, the bounded
delete wait and the health route through the client's parser. Tests of the
sandbox server's bind refusal and its supervisor stop run on Linux only,
where the sandbox runs. The workspace-supersede tests move to their own
file, and a few vendored lint findings absent upstream are fixed.

Co-authored-by: Michael Ling <michael.ling.se@gmail.com>
@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 741ea223c1c2f29a62eac8789cd2dcf502ab831e

任务名称 结果 日志操作
静态检查 ✅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

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.

2 participants