Skip to content

fix(cli): run sandboxes without contacting axisd - #108

Open
johayang-amd wants to merge 11 commits into
mainfrom
fix/run-standalone
Open

johayang-amd wants to merge 11 commits into
mainfrom
fix/run-standalone

Conversation

@johayang-amd

@johayang-amd johayang-amd commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

  • On Windows, every axis run without 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.
  • With axisd running, axis run handed 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 --socket to avoid that.
  • Once axis run never uses axisd, the standalone path has to do what axisd did for it: stop the command on Ctrl+C, enforce timeout_sec on macOS, and not silently drop the GPU worker (review by @ltsabadz).

Technical Details

  • run_command in crates/axis-cli/src/main.rs keeps only the in-process path: axis run always 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.
  • --socket is still accepted and ignored by run, so callers that pass a dead socket keep working. axisd-managed sandboxes stay available through axis create, list, exec and destroy.
  • Stopping without a terminal: Ctrl+C or SIGTERM left the command running and axis hanging until the command exited. On Linux, destroy() after a dropped wait() now kills the process group through the waited_process_group that 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 run exits 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 ends axis and the parent-death guard kills the group.
  • macOS: MacosSandbox::wait ignored timeout_sec, and its blocking child.wait() also starved the Ctrl+C branch. It now polls try_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 and destroy() kill descendants too. When the command exits normally, wait() and try_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 with waitid(WNOWAIT)), so a reused pid is never hit. axis-sandbox gains libc on macOS (already in Cargo.lock).
  • GPU: only axisd starts the HIP Remote GPU worker, so axis run now refuses a policy with gpu.enabled: true and points to axis create.
  • A failing inline proxy is now reported (AXIS: proxy exited: ...) instead of dropped.
  • CLI help: axis run no longer claims to auto-start the daemon, and --socket says run ignores it.
  • Docs: README says axis run does not use axisd, that Ctrl+C or SIGTERM also stops the sandboxed processes, and the GPU example now uses axisd + axis create. docs/setup-and-install.md drops "standalone" from the AXIS_INFERENCE_ENDPOINT note. 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 in e2e/windows/test_mxc_strict_proxy.ps1 no longer say axis run talks to axisd.
  • e2e/linux/test_sandbox.sh:
    • A socket that accepts and never answers stands in for axisd. The test records every connection and requires none, as well as the command's exit status. Checking the exit status alone also passed on main whenever there was no axisd token, as in CI, because main connected, failed to read the token, and fell back to running the command itself.
    • SIGINT to a non-interactive axis run must stop both a foreground and a background process in the sandbox and exit 130.
    • axis run --policy gpu-agent must exit 125 and point to axis create.
  • Unit tests: on macOS, wait() enforces timeout_sec, destroy() after a dropped wait() kills the process group, and wait() 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 run already 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.enabled now fails closed in axis run instead of running without the GPU worker.

Test Plan

  • Early Ctrl+C and macOS background processes, at 53c6918: cargo fmt --all -- --check, cargo clippy --locked --all-targets -- -D warnings, cargo test for axis-cli and axis-sandbox, and bash scripts/test_security_tier0.sh; clippy for aarch64-apple-darwin (axis-sandbox) and x86_64-pc-windows-msvc (axis-cli) with -D warnings; bash e2e/linux/test_sandbox.sh on a Linux host. For the early Ctrl+C, release builds of 86f62d6 and 53c6918 on the same Linux host: SIGINT to a non-interactive axis 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-tmp or the sleep.
  • After merging main d49a156 (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) at 86f62d6: cargo fmt --all -- --check, cargo clippy --all-targets -- -D warnings and cargo test for axis-cli and axis-sandbox; bash e2e/linux/test_sandbox.sh with lxc-exec next to axis; and by hand, SIGINT and SIGTERM to a non-interactive axis run on axis_native and MXC.
  • Linux (WSL2 Ubuntu, kernel 6.18), at badf91e (includes main 24e3a5d), 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, and bash scripts/test_security_tier0.sh.
    • Because a Cargo.toml changed: cargo audit 0.22.2 and cargo deny --locked check advisories licenses sources 0.20.2, on both lockfiles.
    • Because README changed: python3 -m unittest discover -s scripts -p 'test_*.py', python3 scripts/verify_workflow_structure.py . and bash scripts/check_linux_mxc_packaging.sh.
    • Because the launch path and the Linux backends changed, after cargo build --locked --release: bash e2e/linux/test_sandbox.sh with lxc-exec at the pinned MXC_REF next to axis, bash e2e/linux/test_e2e_daemon.sh, e2e/agents/test_agents.sh --platform linux (axis_native, block, no resource limits), and AXIS_TEST_SECCOMP_NOTIFY_ATTRIBUTION=1 cargo test --locked -p axis-sandbox gated_seccomp_notify_.
    • Against a main build: the new test_sandbox.sh checks, with and without an axisd token. The new Linux unit test was also run with the destroy() fix reverted.
    • By hand: SIGINT and SIGTERM to a non-interactive axis run on axis_native and on MXC (--policy minimal), and Ctrl+C through a pty on axis_native.
  • macOS: 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)).
  • Windows: cargo xwin clippy -p axis-cli --all-targets -D warnings in the first round. Later rounds change only the signal handling in axis run and an e2e comment, which the Windows CI jobs build.
  • Launch benchmark, 20 runs after 2 warm-up runs, median / p90: axis run -- cmd.exe /c exit 0 on Windows 11 26100 (the main Windows executor), and axis run -- /bin/true with provider: axis_native on Linux, for main and this change, runs interleaved on the same host. Windows was measured against main 547b8ca in the first round. Linux was measured again this round against main 24e3a5d.

Test Result

  • At 53c6918: fmt, clippy (Linux, macOS and Windows targets) and Tier 0 are clean. axis-cli: 8 passed. axis-sandbox: 560 passed, 6 ignored, and block_mode_sandbox_denies_ip_sockets_preserves_unix_and_omits_proxy_env fails on the WSL2 host as it does on main there (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.
  • Early Ctrl+C, runs that left .axis-tmp out of 40 (all runs exited 130, none left the sleep):
Backend 86f62d6 53c6918
axis_native 2 0
MXC 4 0
  • The launch benchmark below is from earlier rounds. This round only moves the Ctrl+C registration ahead of the create and adds one waitid call per macOS poll, so it was not rerun.
  • After the merge at 86f62d6: fmt and clippy are clean, the axis-cli and axis-sandbox tests pass, and test_sandbox.sh has 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-tmp removed.
  • Linux: fmt (workspace and GUI) and clippy are clean. cargo test: 1047 passed, 0 failed, 6 ignored. Tier 0 passed. cargo audit and cargo deny are 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.
  • Linux e2e: test_sandbox.sh 24 passed, 0 failed, 0 skipped. test_e2e_daemon.sh 19 passed, 0 failed, 0 skipped. test_agents.sh 39 passed, 0 failed; 3 skipped because codex, openclaw and ironclaw are not installed. The gated seccomp notify tests: 2 passed.
  • main build: "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 run hangs until the 15 s timeout. The SIGINT check fails: axis run exits 0 only after the 60 s sleep ends. The GPU check fails. With the destroy() fix reverted, the new unit test fails.
  • By hand: SIGINT exits 130 and SIGTERM exits 143 within about 20 ms on both backends, with no sandboxed process left. Through a pty, Ctrl+C ends axis and the sandboxed process, as before.
  • macOS cross-check is clean. The two new macOS unit tests pass in CI (Test (macOS native)). Not run: a macOS axis run by hand.
  • Launch latency:
Host Case main This change
Windows block, no axisd 2548 / 2627 ms 483 / 560 ms
Windows allow, no axisd 2574 / 2784 ms 512 / 580 ms
Windows block, axisd running (any axisd; only its presence matters) waits for Ctrl+C 450 / 478 ms, exit status kept
Linux block, no axisd 18.7 / 19.9 ms 18.5 / 19.7 ms

`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.
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.

@ltsabadz ltsabadz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Tested on Linux, everything works.

Since axis run now never uses axisd, two things that only axisd did are gone:

  • macOS timeout. timeout_sec is no longer enforced on macOS. Please add a deadline to MacosSandbox::wait, here or in a follow-up before merge.
  • GPU. axis run --policy gpu-agent now silently runs without the GPU worker. Please either refuse gpu.enabled in axis run or change the README example to axis create.

Nit: two comments in e2e/windows/test_mxc_strict_proxy.ps1 (lines 138-139 and 193) still say axis run talks to axisd.

Comment thread crates/axis-cli/src/main.rs Resolved
Comment thread e2e/linux/test_sandbox.sh Resolved
Comment thread crates/axis-cli/src/main.rs Resolved
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.
@johayang-amd

Copy link
Copy Markdown
Collaborator Author

Thanks for the careful review. All of it is addressed in a6749f6 (merged with current main in badf91e):

  • macOS timeout: MacosSandbox::wait now polls with a timeout_sec deadline, like Windows MXC. Its old blocking wait also kept the Ctrl+C branch from ever running on macOS.
  • GPU: axis run refuses gpu.enabled and points to axis create; the README example now uses axisd + axis create.
  • Windows e2e comments: fixed.

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
ltsabadz previously approved these changes Nov 20, 2026

@ltsabadz ltsabadz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
ltsabadz previously approved these changes Nov 24, 2026

@ltsabadz ltsabadz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates!

Approving with two more minor comments (up to you whether you want to fix them here or not).

Comment thread crates/axis-sandbox/src/macos/mod.rs Resolved
Comment thread crates/axis-cli/src/main.rs Resolved
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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants