procjail — Process sandboxing for untrusted code execution
Why
Security scanners execute potentially malicious packages, snippets, and transforms, so an isolation boundary is mandatory.
procjail gives you one shared runtime for Linux process containment with multiple strategy levels (unshare, bubblewrap, firejail, rlimits fallback), letting you keep the same API while adapting to host capability.
It also standardizes process I/O and teardown so scanners can focus on findings instead of child-process mechanics.
Quick Start
use ;
use Path;
Features
- Multi-strategy containment:
unshare,bubblewrap,firejail,rlimits-only. - Uniform spawn/communicate/teardown API via
SandboxedProcess. - Builder-driven hardening (
max_memory,max_cpu_seconds, file descriptor and process limits, mounts, env policy). - Probe helpers for host capability detection and strategy selection.
- Watchdog-aware timeout behavior and usage reporting (
ResourceUsage).
TOML Configuration
You can load a SandboxConfig directly from a TOML file using SandboxConfig::load(path).
Example sandbox.toml:
= 268435456
= 30
= 64
= 52428800
= 32
= false
= "/usr/bin/node"
= ["--experimental-vm-modules"]
= ["HOME", "PATH", "NODE_PATH"]
= []
= []
= true
= "strip-secrets"
= 60
= false
= []
= []
Loading in Rust:
use SandboxConfig;
let config = load.unwrap;
API Overview
SandboxConfig/SandboxConfigBuilder: all runtime controls.SandboxedProcess: spawn child, send/recv JSON lines, wait, collect usage.ResourceUsage: post-run resource metrics.Strategy: containment variant metadata and capability checks.probe_capabilities,available_strategy: pick the best strategy for host runtime.quick_spawn: convenience helper for ephemeral harness runs.- Traits:
SandboxRunner,SandboxedIOfor pluggable sandbox backends.
Examples
1) Detect available containment and print strategy capabilities
use detect_capabilities;
2) Use capability defaults with a quick spawn
use quick_spawn;
use Path;
3) Implement a custom sandbox runner for testing
use Result;
use ;
use VecDeque;
use Path;
;
Traits
procjail defines SandboxRunner and SandboxedIO. Use SandboxRunner if you need alternate backends (containers, VMs, remote executors) and implement SandboxedIO for your transport.
Related Crates
License
MIT, Corum Collective LLC
Docs: https://docs.rs/procjail
Santh ecosystem: https://santh.io