Expand description
The hidden mermaid __sandbox-exec re-exec launcher.
The exec tool spawns mermaid __sandbox-exec [flags] -- <program> <args…>
instead of running a command directly when OS confinement is requested. This
process asks the platform backend (crate::runtime::enforce) to enforce
the requested sandbox — network denial (--no-network) and/or filesystem
write-confinement (repeatable --confine-writes <dir>) — from ordinary
single-threaded code, then runs the real command. On Linux the seccomp /
Landlock restrictions are installed on this process and survive execve;
on macOS the command is exec’d under /usr/bin/sandbox-exec instead. Either
way the command and everything it spawns inherit the restriction, and any
enforcement failure exits 126 — never an unconfined run.
Applying from a fresh process (rather than a pre_exec closure in the
parent) side-steps the async-signal-safety hazard of the post-fork
context, and makes the whole path directly testable
(mermaid __sandbox-exec --no-network -- sh -c 'curl …').
Constants§
- SANDBOX_
EXEC_ SUBCOMMAND - Marker subcommand that routes an invocation to this launcher.
Functions§
- maybe_
dispatch - If
args(fromstd::env::args_os) is a__sandbox-execinvocation, apply the requested confinement andexecvethe wrapped command — returningSome(exit_code)only if we could not (a failure; on successexecvereplaces the process and this never returns). ReturnsNonefor any other invocation so the normal CLI proceeds.