Skip to main content

Module sandbox_exec

Module sandbox_exec 

Source
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 (from std::env::args_os) is a __sandbox-exec invocation, apply the requested confinement and execve the wrapped command — returning Some(exit_code) only if we could not (a failure; on success execve replaces the process and this never returns). Returns None for any other invocation so the normal CLI proceeds.