Repository navigation
fix(sandbox): name the command and reason when exec fails - #18511
Conversation
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Not run on a host where What this change shipsInventory (6 items) — 4 justifiedIntent: when a sandboxed
[FIRST-PRINCIPLES-REVIEWED] 6bf88f5 Description read[DESCRIPTION-READ] a4a8eefa6fb3915afc6fde4a134662a27a17d2016586397c532bfda31cf1d37a That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Confirm the one-line FATAL stderr still arrives intact when [DESIGN-REVIEWED] 6bf88f5 Description read[DESCRIPTION-READ] 8f4f0f284df380ded9218a725fa743c34cf62176c19324ef0f2f9a1186bad20c 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 |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
680665e to
016b467
Compare
e3e1312 to
d45d4f8
Compare
|
This branch conflicts with main. Please rebase it on main. |
d45d4f8 to
4c73bd5
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Thanks for the rebase. Reviewed head 4c73bd5d3e4a211a883ff4ad2ba129960d231994, which is now current with main. The conflict is gone: the comment and docstring edits moved to sandbox_unavailable.py, and sandbox.py dropped out of the diff.
The change is right in shape. One sandbox: FATAL line replaces a cut-off traceback, and each reader of launcher stderr keeps its verdict (launcher_refusal returns None, the ACP sandbox-init check sees no failure, the clone probe gets the line as its detail, the worktree handler reads no refusal). Only argv[0] and strerror are printed, so no arguments or environment values leak.
One should-fix remains from the previous round, plus a small nit:
argv[0]is still interpolated raw into the line (inline comment onsandbox_launcher_program.py). A newline in the path lets the line carry a forgedsandbox: BLOCKEDline that_launcher_failure_linereturns as a refusal. Reproduced against this head's_launcher_failure_linelogic.- Nit: a rewrapped docstring line in
sandbox_unavailable.pyruns to 136 columns (inline comment).
Minor, not blocking: launcher_refusal returns transient for any FATAL line containing did not publish. Since the path is now inside a FATAL line, a command path containing that phrase would be classified as a handshake failure. Checking cannot exec before the handshake match would close it.
Maintainer notes: fork CI on this head is still waiting for run approval, and the PR touches the sandbox launcher, so it needs the sensitive-path review from a maintainer before it can merge.
4c73bd5 to
918a1b4
Compare
|
@bolichen97 thanks for the review. All three points are fixed, folded into the PR's two commits (a14fb72 and 918a1b4). The two inline ones are answered in their threads. On the minor point: |
bolichen97
left a comment
There was a problem hiding this comment.
Thanks, both points from the last round are fixed. Reviewed head 918a1b4b75006773b1a73bbec1dc15eb2a112604.
argv[0]escaping:exec_agentnow writes every unprintable character of the command and the reason as its escape, so the FATAL line stays one line understr.splitlines(). Usingstr.isprintable()rather than a control-byte class is the better choice, since it also covers U+2028, U+2029 and U+0085.test_an_unprintable_character_in_the_path_is_written_as_its_escapepins a newline, a terminal escape and U+2028 in one path, and checks thatlauncher_refusal, the ACP sandbox-init check and_launcher_failure_lineall keep their verdict.- Test coverage: that test plus
test_a_non_ascii_path_is_written_as_it_iscover the escaping, andtest_a_path_holding_the_handshake_words_is_still_a_failed_execcovers the handshake ordering inlauncher_refusal, which now matchescannot execbeforedid not publish.
The over-long docstring line is rewrapped, and no line this PR adds goes past 100 columns.
What I verified: I ran test/test_sandbox_launcher_refusal.py and test/test_worktree_create.py locally at this head, and all 136 tests passed. I also read the full diff. I found no new issues.
Maintainer checks still open before this can merge: fork CI on this head is waiting for run approval, so readiness is not passed yet, and the change touches the sandbox launcher, which needs the sensitive-path review from a maintainer.
bolichen97
left a comment
There was a problem hiding this comment.
CI has now run on head 918a1b4b75006773b1a73bbec1dc15eb2a112604. All test, lint and AI review lanes pass. Two checks are red, and only one of them needs a change from you.
- Internal Content Scan (needs a change in this PR). The scan flags 2 added lines under its home directory path rule:
test/test_sandbox_launcher_refusal.pylines 494 and 495, where the non-ASCII fixture path sits under/home/<user>/. Moving the fixture out of a home directory, for example to/opt/zoë/outils/gh, keeps what the test pins (a non-ASCII path written as it is) and should clear the scan. - Sensitive Change Review (not yours to fix). The PR touches
sandbox_launcher_program.pyandsandbox_unavailable.py, which are sensitive paths. This gate cannot pass from a fork by design: a maintainer has to carry the change on a branch of this repository with you kept as co-author and run the real sandbox there. That is on the maintainer side.
PR Readiness is red only because of these two checks.
918a1b4 to
efd17b6
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Re-reviewed at efd17b6. The home-directory fixture from the last round is fixed: the exec-failure test now uses /opt/tools/bin/gh, and Internal Content Scan passes on this head. The exec-failure handling reads correctly: the launcher prints one escaped FATAL line, launcher_refusal and the worktree handler both match LAUNCHER_EXEC_FAILURE_RE before anything else, and a failed exec is reported as the command's own failure, not as a missing sandbox backend. No new findings from me.
Two CI notes. Backend Tests shard 3 fails on test_chat_follow_default_slot_kinds, which was red on main and is fixed there now; this branch is 110 commits behind main, so a rebase should clear it. Shard 2 hit the 120 second timeout in the facade mirror tree scan rather than an assertion; a rebase rerun should show whether that was runner load.
This PR changes the sandbox launcher, which is a sensitive path, so approval stays with a human maintainer.
When the Linux namespace launcher cannot exec its command, exec_agent lets the OSError escape and the child dies with a Python traceback. The exception names no path, and it comes last, after four launcher frames, so the Changes panel, which keeps the first 600 characters of stderr, cuts it off and shows only stack frames. exec_agent catches OSError around both exec branches and exits with "sandbox: FATAL — cannot exec <path> (<reason>)", status 1 like the launcher's other stops. FATAL is already one of LAUNCHER_EXIT_PREFIXES, so launcher_refusal and the ACP sandbox-init check reach the same verdict they reach for the traceback (no sandbox refusal), and the Auto-Improvement clone probe still reports a launcher failure, with the line that names the command as its detail. A command that execs is untouched. Unprintable characters in the path and the reason are written as escapes, so the line stays one line. The line's shape is LAUNCHER_EXEC_FAILURE_RE, defined beside LAUNCHER_EXIT_PREFIXES, and launcher_refusal matches it before it looks for the handshake's "did not publish", which a command's path can also hold. The prefix tuple's comment and launcher_refusal's docstring name the failed exec among the FATAL cases, and the security spec lists it among the lines launcher_refusal reads as no refusal.
The worktree handler reads the sandbox launcher's stderr itself, and to it every "sandbox: " line except a WARNING is a refusal. A git the launcher cannot exec ends with "sandbox: FATAL — cannot exec git (<reason>)", so on a host whose sandbox works, creating a worktree answered 503 "This host has no OS sandbox backend" and audited "sandbox backend unavailable". The reader skips that line, matched with the sandbox's LAUNCHER_EXEC_FAILURE_RE, the pattern launcher_refusal reads, so the failed call comes back as git's own failure and the handler reports it the way it reports any other. The launcher's other FATAL line, the host-trust pre-read, still refuses. The dash is matched as any one token: the launcher inherits the gateway's locale, and where stderr is not UTF-8 its interpreter writes the dash as an escape.
efd17b6 to
6bf88f5
Compare
|
@bolichen97 thanks for the re-review. I rebased onto current Shard 2's timeout was Is there anything else you need from me before a maintainer picks up the sensitive-path step? |
|
|
|
HOLD at I found no defect. This needs a human for two reasons:
What would clear it: a disposition, or a maintainer run, covering the systemd-run path, and the maintainer's sensitive-path review. KiroCrew/src/kiro_crew/sandbox_launcher_program.py Lines 2246 to 2266 in 6bf88f5 — crew-pr-reviewer (r115) |
bolichen97
left a comment
There was a problem hiding this comment.
Approving. The repository maintainer has taken ownership of this sandbox launcher change and accepts it in place of the fork Sensitive Change Review.
Verified on head 6bf88f5:
- Head is a rebase of efd17b6, which was reviewed in full and found good to ship. The patch itself did not change.
- Readiness label is passed and the required PR Readiness check is green. The only failing check is Sensitive Change Review, which this approval covers.
- AI review lanes on this head: Opus, GPT, design and first principles all pass with no blocking findings. UX review was skipped as no user-facing surface changed.
- No requested changes from any reviewer. The linked issue is tier T1.
- Base is main and the branch is mergeable.
Enabling squash auto-merge.
Problem / Motivation
Goal: When a sandboxed command cannot be exec'd, the error the user sees names the command and the reason.
On Linux, a Changes panel call whose
ghorglabbinary the namespace sandbox cannot exec fails with a message made of Python stack frames, cut off mid-frame (... File "<frozen os>", line 612, in e). Neither the reason nor the path appears. Steps and full output are in #18496.Why it matters
The gateway checks a provider binary before it spawns it, so the exec fails only where the sandbox's view differs from the gateway's: a binary or link inside a masked directory such as
~/.docker/bin, or one replaced after the check. That is rare, but when it happens the error is the only clue, and today it carries none. Every other surface that shows the launcher's stderr gets the same traceback, whose last line names no path.Not a goal
sanitize._safe_error_text). With one line from the launcher, the panel shows this failure whole.release/0.9.0has the same three files and the commit applies there cleanly;release/0.8.0keeps its launcher in a template string insandbox.py.What changed (motivation → approach → change)
Symptom. A failed exec inside the namespace sandbox reaches the user as a truncated traceback.
Cause.
exec_agentinsandbox_launcher_program.pylets theOSErrorfrom the exec escape, so Python prints a traceback. The exception names no path (execvsets no filename), and it comes last, after four launcher frames. The panel keeps the first 600 characters, so the exception is cut off (at character 648 in #18496's run).Change.
exec_agentcatchesOSErroraround both exec branches and exits withsandbox: FATAL — cannot exec <path> (<reason>), status 1 like the launcher's other stops. A command that execs is untouched.The prefix is the existing
sandbox: FATAL, not a new one.LAUNCHER_EXIT_PREFIXESis the definition every reader of launcher stderr but the worktree handler keys on, and two tests pin every string in the launcher against it. With FATAL, each reader keeps its verdict:launcher_refusalreturnsNone, as it does for the unreadable-known_hostsFATAL line: the sandbox was built and the command is missing inside it. The ACP sandbox-init check reads no sandbox failure. Both read the traceback the same way.A new prefix such as
sandbox: cannot execfails both pinning tests, and the clone probe would read the exit as git's own, the misreport #8151 was about. Keeping the tail of stderr in the panel instead would help only the panel, and the tail names no path.The prefix tuple's comment and
launcher_refusal's docstring now list the failed exec among the FATAL cases.Second commit. The worktree handler reads launcher stderr itself (
_launcher_failure_line) and takes everysandbox:line but a WARNING as a refusal, so with the first commit alone a git the launcher cannot exec makes worktree creation answer 503 "This host has no OS sandbox backend…", and audit "sandbox backend unavailable", on a host whose sandbox works. It now skips^sandbox: FATAL \S+ cannot exec, so the call fails as git's own, the handler's only other outcome, and creation answers 400 "Not a git repository", as onmain. The unreadable-known_hostsFATAL line still refuses there; routing the reader throughlauncher_refusal, which returnsNonefor it, would not. The dash is any token: under a non-UTF-8 locale the launcher writes it as\u2014. A child printing the line is treated as any failing git. A backport torelease/0.9.0needs both commits.Backwards compatibility
Compatible: a command that execs is untouched, and a failed exec still exits 1; only its stderr changes, from a traceback to one
sandbox: FATALline. Every reader of launcher stderr reaches the verdict it reaches onmain, the worktree handler through the second commit.Removes nothing: the diff adds an exception handler, a message and a line shape the worktree handler skips, and no key, field, path or function is removed or renamed.
Tests
test/test_sandbox_launcher_refusal.py, newTestAFailedExecIsOneLauncherLine(5 tests):os.execvp, ends in the FATAL line naming the path andNo such file or directory;Permission denied);OSErrorwithout an errno still gives a reason;launcher_refusaland the ACP sandbox-init check see no sandbox failure, the clone probe's detail is the line, and the worktree handler sees no refusal.test/test_worktree_create.py, 3 new cases:_run_gitreturns the line as git's own failure, with the dash as UTF-8 or\u2014, and the endpoint answers 400 with no "sandbox backend unavailable" audit.The existing
TestClassifierMatchesTheLauncherpins the new string's prefix. Five breakages of the launcher change each fail at least one test: no handler (4), a new prefix (5),exc.strerroralone (1), the path dropped (3), only the injected exec guarded (1). Four breakages of the worktree skip do too: none (4), every FATAL line (1), the UTF-8 dash only (1),cannotalone (1).Regression, both commits, on
main19190b68e6: 147 test files that read, render or run the launcher, read its stderr, exercise the worktree handler or import the sandbox module: 12,578 passed, 2 failed, 109 skipped, 5 xfailed (unpatchedmain: 12,570 passed, the same 2 failed). Fast Gate, the black gate, isort, flake8 and mypy pass.Manual verification
In an
ubuntu:24.04container with the real namespace sandbox (uid 1000,--network none,docker/seccomp/kirocrew-seccomp.json; backendnamespace), before and after the change:main~/.docker/binsandbox: FATAL — cannot exec /home/ubuntu/.docker/bin/probe (No such file or directory), shown whole... cannot exec /home/ubuntu/tools/absent (No such file or directory)PermissionError... cannot exec /home/ubuntu/tools/noexec (Permission denied)true,false,sh -c 'echo own-message >&2; exit 3'Through the Changes panel's own
_run_json("gh", "api", "user")(real audit, sandbox wrap and spawn, resolver pointed at the masked binary), theSourceProviderErrortext goes from the cut-off traceback to the FATAL line.Worktree creation in the same container, which has no git: 400 "Not a git repository" on
main, the 503 and its audit with the first commit alone, and 400 with no refusal audited with both.Not run: a host where
systemd-runwraps the launcher (the container has none), and macOS, whose Seatbelt path does not use this launcher.Related Issues
Closes #18496.
Pattern harvest
Rule candidate: review-prompt
Pattern: an error surface that keeps the head of a child's stderr loses the cause when the child ends in a traceback (also #10043's tunnel error and #17934's Notes git sync).
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.