Repository navigation
fix(sandbox): keep the scratch window when the host empties the stand-in roots - #31730
Conversation
Sensitive Change ReviewSensitive files changed:
How to clear this check:
Only the author's comment counts this way. A reviewer can instead |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns. Each mask's bind keeps the tmpfs alive on its own, and the windows sit inside stand-ins the host cannot see, so logind removing an entry on the host can no longer detach a window. A refused tmpfs falls back to the old host root. [DESIGN-REVIEWED] 661c438 Description read[DESCRIPTION-READ] bc86fd9077f0a4d0198e3d1487ba5155099ac75c97b618a82410daaaae2be8a8 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Every item addresses the scratch-window loss reported in #31716. The fix removes the cause, which is stand-ins living on host-shared roots, and every stand-in create goes through the one staged path. What this change shipsInventory (6 items) — 6 justifiedIntent: a sandboxed Linux agent keeps its scratch directory and
Sibling count: [FIRST-PRINCIPLES-REVIEWED] 661c438 Description read[DESCRIPTION-READ] 586ac6a8173e17c64b32541a835406a495256e6f314b429a9cb878a878bc2804 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
|
Both backend reds on this head are main's, not this PR's: |
014d0b0 to
691d093
Compare
|
macOS Backend Tests (5, 7) on 014d0b0 were this PR's: the new stage opened its pin with |
691d093 to
2afccdb
Compare
|
Backend Tests (Windows) (7) on 691d093 was this PR's: |
…-in roots The namespace launcher created every mask stand-in directly under a host-shared root (/run/user/$UID or /dev/shm). On a host where the user has no login session, systemd-logind's RemoveIPC=yes deletes the uid's /dev/shm entries at the next session close, directories included. Deleting a stand-in removed the private-window mount points inside it, which detached the scratch window in the running sandbox, so $TMPDIR vanished and every create under it failed with ENOENT. The launcher now mounts a tmpfs on one stage directory in its own mount namespace and creates every stand-in inside it through a descriptor on the tmpfs root. Once the masks are placed it detaches the stage and removes the empty host directory. A refused tmpfs mount keeps the old host-root behaviour with a warning.
2afccdb to
661c438
Compare
|
Rebased: main moved in .github/workflows/, docs/system-specs/modules/ and src/kiro_crew/ (same-directory overlap only, no shared file) since this head's CI ran (7c364bc -> current origin/main). The previous head's CI run was cancelled after two Windows shards sat queued on their runner for over two hours. Head is now 661c438; the sandbox-related tests pass locally and CI is re-running. |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved for the on-call. Review lanes pass on 661c438, no conflict, no open change request.
…-in roots (#31730) The namespace launcher created every mask stand-in directly under a host-shared root (/run/user/$UID or /dev/shm). On a host where the user has no login session, systemd-logind's RemoveIPC=yes deletes the uid's /dev/shm entries at the next session close, directories included. Deleting a stand-in removed the private-window mount points inside it, which detached the scratch window in the running sandbox, so $TMPDIR vanished and every create under it failed with ENOENT. The launcher now mounts a tmpfs on one stage directory in its own mount namespace and creates every stand-in inside it through a descriptor on the tmpfs root. Once the masks are placed it detaches the stage and removes the empty host directory. A refused tmpfs mount keeps the old host-root behaviour with a warning. Co-authored-by: w <w@k.local> (cherry picked from commit 782fcbd) Originally authored on main by Bolin Chen (bolichen97); authored here with the public identity because the commit guard refuses the original address.
…-in roots (#31730) The namespace launcher created every mask stand-in directly under a host-shared root (/run/user/$UID or /dev/shm). On a host where the user has no login session, systemd-logind's RemoveIPC=yes deletes the uid's /dev/shm entries at the next session close, directories included. Deleting a stand-in removed the private-window mount points inside it, which detached the scratch window in the running sandbox, so $TMPDIR vanished and every create under it failed with ENOENT. The launcher now mounts a tmpfs on one stage directory in its own mount namespace and creates every stand-in inside it through a descriptor on the tmpfs root. Once the masks are placed it detaches the stage and removes the empty host directory. A refused tmpfs mount keeps the old host-root behaviour with a warning. Co-authored-by: w <w@k.local> (cherry picked from commit 782fcbd) Originally authored on main by Bolin Chen (bolichen97); authored here with the public identity because the commit guard refuses the original address.
Problem / Motivation
Goal: A sandboxed agent on Linux keeps its scratch directory and
$TMPDIRfor its whole run, even when the host cleans up the user's shared temp roots.On a host where the user has no logind session or linger, every running sandbox can lose its scratch window at the same moment. From then on every shell command fails. On the Claude Code backend it reads
task output swap refused (tasks dir moved or linked), and the gateway log showsENOENT ... mkdir '<scratch>/<session>/claude-<uid>'.Why it matters
Every sandboxed session on such a host breaks mid-task, dashboard chats and background runtimes alike, and keeps breaking every few minutes when a cron session opens and closes. The agent's work in progress is cut off, and nothing in the product says why.
Not a goal
/run/user/$UID, then/dev/shm).What changed (motivation → approach → change)
The launcher creates the empty stand-ins it binds over hidden directories under a host-shared root (
/run/user/$UID, else/dev/shm). The scratch root is one of those masks, and the spawn's scratch directory is mounted back inside its stand-in as a private window. WithRemoveIPC=yes(the default), systemd-logind deletes the uid's/dev/shmentries when the user's last session closes, directories included. Deleting the stand-in removes the window's mount point, which detaches the window inside the running sandbox.stage_stand_ins_privatelymounts a tmpfs on one stage directory in its own mount namespace and creates every stand-in through a descriptor on that tmpfs rootretire_stand_in_stagedetaches the stage and removes its empty host directory; the masks keep the tmpfs aliveThe host never sees a stand-in, so nothing it deletes can reach a window. The new real-sandbox test runs in the namespace-sandbox CI job (
ci.yml), anddocs/system-specs/modules/security.mddescribes the stage.Backwards compatibility
Compatible: every mask, seal and window is placed exactly as before, from the same plan; only where the empty stand-ins live changes, and a host that refuses the tmpfs keeps the old location.
Removes nothing: no path, record, key or function is taken away; the stand-ins move off the host, which only stops leaving
kirocrew_sb_*entries there.Tests
test/test_stand_in_stage_real_sandbox.py: under the real sandbox (every tier), the test deletes every entry the launcher could have left on the host roots for the child's pid, children first, the way logind does. The child must still create a directory in its window and read back what it wrote before. The test also asserts that no such host entries exist.test/test_sandbox_stand_in_private_stage.py: the stage mounts anosuid,nodevtmpfs and stand-ins land in it; retire detaches it and removes the host directory; a refused tmpfs, a stage that is not a fresh mount, and a host root that vanishes after the mount all keep the host root without ending the launch; a stage that will not detach stays with a warning.test/test_sandbox_launcher_program.py,test/test_sandbox_mount_checked.py: the stage order, the stand-in and mount counts, and the stage's checked raw tmpfs mount.test/test_sandbox_launcher_symlinked_protected_name.pycounts the stage's two opens as launcher-created directories, not protected names.Proof: PROVEN test/test_sandbox_launcher_program.py::test_the_mount_count_covers_every_site, test/test_sandbox_launcher_program.py::test_the_stand_in_count_covers_every_create, test/test_sandbox_launcher_program.py::test_a_replaced_stand_in_root_moves_the_stand_ins_and_keeps_every_mask[create-1], test/test_sandbox_launcher_program.py::test_a_replaced_stand_in_root_moves_the_stand_ins_and_keeps_every_mask[create-2], test/test_sandbox_launcher_program.py::test_a_replaced_stand_in_root_moves_the_stand_ins_and_keeps_every_mask[create-3] (head 661c438)
Manual verification
The real-sandbox test is the end-to-end check. It runs only where unprivileged user namespaces are allowed, so it runs in the namespace-sandbox CI job and not on the author's host.
Related Issues
Closes #31716
Sibling sweep
Swept: git grep -n "stand_in_roots|tempfile.mkdtemp(dir=root" -- src/
Siblings: none -- every stand-in is created through _on_stand_in_root in src/kiro_crew/sandbox_launcher_program.py, which this PR stages
Pattern harvest
Not generalizable: the only host-shared mount source in the product is the launcher's stand-in root, which this PR moves into the sandbox's own namespace.
Checklist