Skip to main content

apply

Function apply 

Source
pub fn apply(profile: &Profile) -> Result<(), Error>
Expand description

STAGE 2 โ€” worker, the first statement of main().

Applies profile to the current process. On Linux the process must already have been cloned with the flags returned by prepare; this configures those namespaces and establishes the remaining sandbox. See the crate docs for the required single-threaded, run-first ordering. Returns Error if any required primitive fails โ€” the worker should then exit with EXIT_SANDBOX_FAILED.

Failure does not roll back restrictions already applied. Do not initialize the worker or retry in the partially confined process after an error. Landlock is supplementary on Linux: its absence or failure can leave the mount-based filesystem boundary in force without returning an error.

In debug builds, becomes a no-op when DISABLE_ENV is set (see its docs).

ยงExample

In a worker entry point launched with the matching prepare configuration:

if let Err(error) = sandbox::apply(&sandbox::profiles::tpm_worker().build()) {
    eprintln!("sandbox failed: {error}");
    std::process::exit(sandbox::EXIT_SANDBOX_FAILED);
}
// Join Mesh and initialize the worker only after confinement succeeds.