Skip to content

subprocess_sandbox

diapason.security.subprocess_sandbox

Subprocess sandbox — secure process execution with environment isolation.

SandboxResult dataclass

Result of a sandboxed subprocess execution.

build_safe_env(passthrough=None, extra=None)

Build a sanitized environment dict.

Only copies safe vars from current env, plus any in passthrough list. Extra vars are added directly.

kill_process_tree(pid)

Kill a process and all its children (best effort).

run_sandboxed(command, *, timeout=30.0, working_dir=None, env_passthrough=None, env_extra=None, max_output_bytes=102400)

Execute a command in a sandboxed subprocess.

Features: - Clean environment (only safe vars passed through) - Timeout enforcement with process tree kill - Output truncation - New process group for clean cleanup