Repository navigation
fix(cli): run sandboxes without contacting axisd - #108
Open
johayang-amd wants to merge 11 commits into
Open
johayang-amd wants to merge 11 commits into
johayang-amd wants to merge 11 commits into
Conversation
`axis run` first asked axisd to create the sandbox and fell back to running it in-process only when the connect failed. On Windows, axisd listens on loopback TCP and a refused connect takes about two seconds, so every `axis run` without axisd paid that wait. With axisd running, `axis run` handed the sandbox to it, printed no output, dropped the command's exit status and waited for Ctrl+C; GAS and the Linux e2e pass a dead --socket to avoid that. `axis run` now always runs the sandbox in-process and exits with the command's status. axisd-managed sandboxes stay available through `axis create`, `list`, `exec` and `destroy`. --socket is still accepted and ignored by `run`, so existing callers keep working.
This was referenced Nov 12, 2026
johayang-amd
added a commit
that referenced
this pull request
Nov 13, 2026
… once Review of the tmpdir claim found that SIGTERM left the command's children running and that a run killed with SIGKILL blocked an immediate retry. - wait() takes the child, so after the SIGTERM handler dropped a pending wait(), destroy() found no child and only disarmed the parent-death monitor. Native and MXC sandboxes now remember the process group while wait() holds the child, and destroy() kills it. - The parent-death monitor inherited the workspace lock and outlives a killed AXIS for up to about a second. It now closes every inherited descriptor except its pipe. - A flock error other than "held" or "unsupported" now fails the launch instead of starting without the claim. - MXC claims the tmpdir after the run_as_user workspace checks, as the native path does, so it never removes a leftover through a workspace it then refuses. - The daemon path of `axis run` is left as on main; #108 removes it.
# Conflicts: # README.md
axis run no longer contacts axisd, so the two-second connect wait the launch notes describe is gone.
ltsabadz
requested changes
Nov 18, 2026
ltsabadz
left a comment
Collaborator
There was a problem hiding this comment.
Thanks! Tested on Linux, everything works.
Since axis run now never uses axisd, two things that only axisd did are gone:
- macOS timeout.
timeout_secis no longer enforced on macOS. Please add a deadline toMacosSandbox::wait, here or in a follow-up before merge. - GPU.
axis run --policy gpu-agentnow silently runs without the GPU worker. Please either refusegpu.enabledinaxis runor change the README example toaxis create.
Nit: two comments in e2e/windows/test_mxc_strict_proxy.ps1 (lines 138-139 and 193) still say axis run talks to axisd.
Now that axis run never goes through axisd, the standalone path has to do what axisd did for it. - Ctrl+C or SIGTERM without a terminal left the command running and axis hanging until it exited: the Linux backends move the child into a blocking wait task, so destroy() after the dropped wait killed nothing. They now remember that pid and kill its process group. axis run exits with 128 + the signal number instead of 0. - macOS ignored timeout_sec, and its blocking wait starved the signal branch. It now polls with a deadline like Windows MXC, and kills the process group when not attached to a terminal. - axis run refuses gpu.enabled: only axisd starts the HIP Remote GPU worker. The README GPU example uses axis create. - A failing inline proxy is logged instead of dropped. - The Linux e2e asserts that axis run never connects to the axisd socket (the old check also passed on main without an axisd token), that SIGINT stops the sandboxed process group, and that GPU policies are refused.
Collaborator
Author
|
Thanks for the careful review. All of it is addressed in a6749f6 (merged with current
I also corrected the e2e claim in the description: it only held because my machine had an axisd token. |
johayang-amd
added a commit
that referenced
this pull request
Nov 20, 2026
… once Review of the tmpdir claim found that SIGTERM left the command's children running and that a run killed with SIGKILL blocked an immediate retry. - wait() takes the child, so after the SIGTERM handler dropped a pending wait(), destroy() found no child and only disarmed the parent-death monitor. Native and MXC sandboxes now remember the process group while wait() holds the child, and destroy() kills it. - The parent-death monitor inherited the workspace lock and outlives a killed AXIS for up to about a second. It now closes every inherited descriptor except its pipe. - A flock error other than "held" or "unsupported" now fails the launch instead of starting without the claim. - MXC claims the tmpdir after the run_as_user workspace checks, as the native path does, so it never removes a leftover through a workspace it then refuses. - The daemon path of `axis run` is left as on main; #108 removes it.
ltsabadz
previously approved these changes
Nov 20, 2026
ltsabadz
left a comment
Collaborator
There was a problem hiding this comment.
Thanks, looks good to merge!
ltsabadz
pushed a commit
that referenced
this pull request
Nov 20, 2026
* fix(sandbox): recover the workspace tmpdir after a killed run
AXIS creates {tmpdir} (<workspace>/.axis-tmp) exclusively and removes it
when the sandbox stops. A non-interactive `axis run` that gets SIGTERM, as
a caller's timeout sends, ended without that cleanup, and so does one that
gets SIGKILL. The tmpdir stayed, and every later run in that workspace
failed with "cannot create exclusive tmpdir ... File exists" until someone
removed it by hand.
`axis run` now stops its sandbox on SIGTERM in every mode, as it already
did on a terminal: the command is killed, the tmpdir removed, and AXIS
exits 143. The handler is registered before the sandbox starts.
Each Linux sandbox that uses {tmpdir} also holds an exclusive flock on
its workspace directory from before the tmpdir is created until after it
is removed. The kernel releases it when that AXIS process ends, however
it ends. A run that gets the lock and still finds a tmpdir knows no live
sandbox owns it, and removes it when it is a real directory owned by the
uid the tmpdir is created for; a link or another owner's directory is
left, and the exclusive create still refuses it. A run that does not get
the lock fails as before: two sandboxes in one workspace still cannot
share a tmpdir. Where flock is unsupported nothing is removed.
Co-authored-by: Cursor <[email protected]>
* fix(sandbox): stop the whole sandbox on SIGTERM and free the claim at once
Review of the tmpdir claim found that SIGTERM left the command's children
running and that a run killed with SIGKILL blocked an immediate retry.
- wait() takes the child, so after the SIGTERM handler dropped a pending
wait(), destroy() found no child and only disarmed the parent-death
monitor. Native and MXC sandboxes now remember the process group while
wait() holds the child, and destroy() kills it.
- The parent-death monitor inherited the workspace lock and outlives a
killed AXIS for up to about a second. It now closes every inherited
descriptor except its pipe.
- A flock error other than "held" or "unsupported" now fails the launch
instead of starting without the claim.
- MXC claims the tmpdir after the run_as_user workspace checks, as the
native path does, so it never removes a leftover through a workspace it
then refuses.
- The daemon path of `axis run` is left as on main; #108 removes it.
* fix(sandbox): reclaim the tmpdir through the locked workspace descriptor
Review found three ways the leftover removal could reach the wrong
directory. After #95 the claim runs before the run_as_user workspace
checks, and it removed the leftover by path, so a workspace about to be
refused could already have lost a .axis-tmp behind a link. On a network
filesystem the lock may be local to one host, so another host's live
tmpdir looked like a leftover.
The claim now opens the workspace once and does everything through that
descriptor: the lock, the filesystem check, and the removal, which
follows no link. For run_as_user the open refuses a symlink in any
component, as the run_as_user setup does. On NFS, SMB, FUSE, 9P and
similar filesystems, or when the type is unknown, a leftover is left in
place and the exclusive create refuses it, as before this change.
axis run now registers its SIGTERM handler before creating the sandbox,
since MXC creates the tmpdir there. The parent-death monitor reuses
close_child_fd_range. A native-backend test covers the leftover and a
second sandbox, and the close-on-exec test now checks that a spawned
command does not keep the lock. The isolation contract describes the
tmpdir's lifecycle.
Co-authored-by: Cursor <[email protected]>
---------
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]> # Conflicts: # crates/axis-cli/src/main.rs # crates/axis-sandbox/src/linux/mod.rs # crates/axis-sandbox/src/linux/mxc.rs # crates/axis-sandbox/src/macos/mod.rs
ltsabadz
previously approved these changes
Nov 24, 2026
ltsabadz
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the updates!
Approving with two more minor comments (up to you whether you want to fix them here or not).
A Ctrl+C that arrived while axis run was still creating or starting the sandbox ended AXIS with the default SIGINT action, before tokio::select! listened for it. The tmpdir that create had already made stayed behind in the workspace. Outside a terminal, the Ctrl+C handler is now registered next to the SIGTERM one, before Sandbox::create, so it stops and destroys the sandbox whenever it arrives. Interactive runs still install no handler, so TUIs keep the terminal. On macOS, a command that exited normally left whatever it started in the background running, while Linux kills the whole process group. wait() and try_wait() now check with waitid(WNOWAIT) whether the child has exited, kill its process group while it is still unreaped (so its pid and group id cannot have been reused), and only then reap it. Co-authored-by: Cursor <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
axis runwithout axisd waited about two seconds: it first tried axisd on loopback TCP, and Windows retries a refused loopback connect before failing. That wait was most of the Windows launch time measured in feat(windows): move the ProcessContainer backend to MXC 1.x #90.axis runhanded the sandbox to it, showed no output, dropped the command's exit status and waited for Ctrl+C. GAS (tool_plane/axis.js) and the Linux e2e pass a dead--socketto avoid that.axis runnever uses axisd, the standalone path has to do what axisd did for it: stop the command on Ctrl+C, enforcetimeout_secon macOS, and not silently drop the GPU worker (review by @ltsabadz).Technical Details
run_commandincrates/axis-cli/src/main.rskeeps only the in-process path:axis runalways runs the sandbox itself and exits with the command's status. The daemon branch and the "daemon not running, using standalone mode" message are removed.--socketis still accepted and ignored byrun, so callers that pass a dead socket keep working. axisd-managed sandboxes stay available throughaxis create,list,execanddestroy.axishanging until the command exited. On Linux,destroy()after a droppedwait()now kills the process group through thewaited_process_groupthat fix(sandbox): recover the workspace tmpdir after a killed run #107 added to the native and MXC backends; this PR first added the same fix and now uses fix(sandbox): recover the workspace tmpdir after a killed run #107's. Outside a terminal,axis runexits 130 on Ctrl+C (it used to exit 0) and, through fix(sandbox): recover the workspace tmpdir after a killed run #107's handler, 143 on SIGTERM. Both handlers are registered before the sandbox is created, so a signal that arrives while it is still being created or started also stops it and removes its tmpdir (review by @ltsabadz). With a terminal, behavior is unchanged: no Ctrl+C handler is installed, the signal endsaxisand the parent-death guard kills the group.MacosSandbox::waitignoredtimeout_sec, and its blockingchild.wait()also starved the Ctrl+C branch. It now pollstry_wait()with a deadline, like Windows MXC, and kills the sandbox on timeout. Outside a terminal the child gets its own process group, so timeout anddestroy()kill descendants too. When the command exits normally,wait()andtry_wait()also kill its group before reaping it, so nothing it left in the background keeps running, as on Linux (review by @ltsabadz). The group is only signalled while the child is unreaped (checked withwaitid(WNOWAIT)), so a reused pid is never hit.axis-sandboxgainslibcon macOS (already inCargo.lock).axis runnow refuses a policy withgpu.enabled: trueand points toaxis create.AXIS: proxy exited: ...) instead of dropped.axis runno longer claims to auto-start the daemon, and--socketsaysrunignores it.axis rundoes not use axisd, that Ctrl+C or SIGTERM also stops the sandboxed processes, and the GPU example now usesaxisd+axis create.docs/setup-and-install.mddrops "standalone" from theAXIS_INFERENCE_ENDPOINTnote.docs/windows-mxc-1.md(added by feat(windows): move the ProcessContainer backend to MXC 1.x #90) no longer describes the two-second axisd connect wait. Two comments ine2e/windows/test_mxc_strict_proxy.ps1no longer sayaxis runtalks to axisd.e2e/linux/test_sandbox.sh:mainwhenever there was no axisd token, as in CI, becausemainconnected, failed to read the token, and fell back to running the command itself.axis runmust stop both a foreground and a background process in the sandbox and exit 130.axis run --policy gpu-agentmust exit 125 and point toaxis create.wait()enforcestimeout_sec,destroy()after a droppedwait()kills the process group, andwait()after a normal exit kills a background process the command left.Security impact: none that weakens isolation. The sandbox is created by the same in-process path
axis runalready used whenever axisd was absent, with the same policy checks. The new kills target only the sandbox's own process group, recorded at launch.gpu.enablednow fails closed inaxis runinstead of running without the GPU worker.Test Plan
53c6918:cargo fmt --all -- --check,cargo clippy --locked --all-targets -- -D warnings,cargo testforaxis-cliandaxis-sandbox, andbash scripts/test_security_tier0.sh; clippy foraarch64-apple-darwin(axis-sandbox) andx86_64-pc-windows-msvc(axis-cli) with-D warnings;bash e2e/linux/test_sandbox.shon a Linux host. For the early Ctrl+C, release builds of86f62d6and53c6918on the same Linux host: SIGINT to a non-interactiveaxis run -- sh -c 'exec sleep 300'2 to 15 ms after start (while the sandbox is being created and started), 40 runs per build on axis_native and on MXC, counting runs that leave.axis-tmpor thesleep.maind49a156(which brings fix(sandbox): recover the workspace tmpdir after a killed run #107 and feat(proxy): forward absolute-form HTTP and drop loopback NO_PROXY #115) at86f62d6:cargo fmt --all -- --check,cargo clippy --all-targets -- -D warningsandcargo testforaxis-cliandaxis-sandbox;bash e2e/linux/test_sandbox.shwithlxc-execnext toaxis; and by hand, SIGINT and SIGTERM to a non-interactiveaxis runon axis_native and MXC.badf91e(includesmain24e3a5d), every step in DEVELOPMENT.md "Local Checks" that applies:cargo fmt --all -- --check,cargo fmt --manifest-path gui/linux/Cargo.toml -- --check,cargo clippy --locked --all-targets -- -D warnings,cargo test --locked, andbash scripts/test_security_tier0.sh.Cargo.tomlchanged:cargo audit0.22.2 andcargo deny --locked check advisories licenses sources0.20.2, on both lockfiles.python3 -m unittest discover -s scripts -p 'test_*.py',python3 scripts/verify_workflow_structure.py .andbash scripts/check_linux_mxc_packaging.sh.cargo build --locked --release:bash e2e/linux/test_sandbox.shwithlxc-execat the pinnedMXC_REFnext toaxis,bash e2e/linux/test_e2e_daemon.sh,e2e/agents/test_agents.sh --platform linux(axis_native, block, no resource limits), andAXIS_TEST_SECCOMP_NOTIFY_ATTRIBUTION=1 cargo test --locked -p axis-sandbox gated_seccomp_notify_.mainbuild: the newtest_sandbox.shchecks, with and without an axisd token. The new Linux unit test was also run with thedestroy()fix reverted.axis runon axis_native and on MXC (--policy minimal), and Ctrl+C through a pty on axis_native.cargo clippy --locked --target aarch64-apple-darwin -p axis-sandbox --all-targets -- -D warnings(cross-checked from Linux). The macOS unit tests run in CI (Test (macOS native)).cargo xwin clippy -p axis-cli --all-targets -D warningsin the first round. Later rounds change only the signal handling inaxis runand an e2e comment, which the Windows CI jobs build.axis run -- cmd.exe /c exit 0on Windows 11 26100 (themainWindows executor), andaxis run -- /bin/truewithprovider: axis_nativeon Linux, formainand this change, runs interleaved on the same host. Windows was measured againstmain547b8ca in the first round. Linux was measured again this round againstmain24e3a5d.Test Result
53c6918: fmt, clippy (Linux, macOS and Windows targets) and Tier 0 are clean.axis-cli: 8 passed.axis-sandbox: 560 passed, 6 ignored, andblock_mode_sandbox_denies_ip_sockets_preserves_unix_and_omits_proxy_envfails on the WSL2 host as it does onmainthere (Python cannot start inside its sandbox) and passes on the other Linux host.test_sandbox.sh: 24 passed, 0 failed, 0 skipped. The new macOS unit test runs in CI (Test (macOS native)); it was not run on a Mac by hand..axis-tmpout of 40 (all runs exited 130, none left thesleep):86f62d653c6918waitidcall per macOS poll, so it was not rerun.86f62d6: fmt and clippy are clean, theaxis-cliandaxis-sandboxtests pass, andtest_sandbox.shhas 24 passed, 0 failed, 0 skipped. By hand, SIGTERM exits 143 and SIGINT exits 130 on both backends, with the background process gone and.axis-tmpremoved.cargo test: 1047 passed, 0 failed, 6 ignored. Tier 0 passed.cargo auditandcargo denyare clean on both lockfiles (one existing allowed warning, RUSTSEC-2024-0449). Script unit tests: 185 passed, 3 skipped. The workflow verifier and the packaging checks pass.test_sandbox.sh24 passed, 0 failed, 0 skipped.test_e2e_daemon.sh19 passed, 0 failed, 0 skipped.test_agents.sh39 passed, 0 failed; 3 skipped becausecodex,openclawandironclaware not installed. The gated seccomp notify tests: 2 passed.mainbuild: "axis run did not connect to the axisd socket" fails with or without a token. Without a token, the old exit-status check still passes; with a token,axis runhangs until the 15 s timeout. The SIGINT check fails:axis runexits 0 only after the 60 s sleep ends. The GPU check fails. With thedestroy()fix reverted, the new unit test fails.axisand the sandboxed process, as before.Test (macOS native)). Not run: a macOSaxis runby hand.main