Skip to main content

tighten

Function tighten 

Source
pub fn tighten(restrictions: &Restrictions) -> Result<(), Error>
Expand description

STAGE 3 (optional) — worker, after its own initialization.

Stacks the additive-only restrictions onto the already-applied sandbox. Unlike apply, it may run multi-threaded: Linux synchronizes syscall filters across all threads with seccomp TSYNC. Returns Error if synchronization fails or is unsupported, with no thread-local fallback. The worker should then exit with EXIT_SANDBOX_FAILED; restrictions installed before the failure remain in effect.

In debug builds, becomes a no-op when DISABLE_ENV is set.

§Example

After successful apply and worker initialization:

let restrictions = sandbox::Restrictions::none()
    .syscalls(&["execve", "socket", "connect"])
    .build();
if let Err(error) = sandbox::tighten(&restrictions) {
    eprintln!("sandbox tightening failed: {error}");
    std::process::exit(sandbox::EXIT_SANDBOX_FAILED);
}