pub struct SandboxEnforcer {
pub config: SandboxConfig,
}Expand description
The enforcer that guards the sandboxed arena.
Validates commands, paths, and environment variables before any subprocess is allowed to enter the containment ring.
Fields§
§config: SandboxConfigThe containment ring configuration.
Implementations§
Source§impl SandboxEnforcer
impl SandboxEnforcer
Sourcepub fn new(config: SandboxConfig) -> Self
pub fn new(config: SandboxConfig) -> Self
Create a new enforcer with the given containment ring configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a new enforcer with default containment ring settings.
Sourcepub fn validate_command(&self, command: &str) -> Result<(), SandboxViolation>
pub fn validate_command(&self, command: &str) -> Result<(), SandboxViolation>
Pre-execution validation: check a command before it enters the arena.
Detects denied command prefixes, path traversal attempts, and
shell injection patterns (backticks, $(), pipes to sensitive commands).
Sourcepub fn validate_path(&self, path: &Path) -> Result<(), SandboxViolation>
pub fn validate_path(&self, path: &Path) -> Result<(), SandboxViolation>
Validate whether a path is accessible within the containment ring.
Canonicalizes the path, then checks denied paths first (deny always wins), followed by allowed paths. A fighter cannot reach outside its arena.
Sourcepub fn sanitize_environment(&self) -> Vec<(String, String)>
pub fn sanitize_environment(&self) -> Vec<(String, String)>
Build a clean environment — only variables that survive the containment ring.
Starts with an empty environment, then includes only variables from the allowlist that exist in the current process environment. Any variable matching a denylist pattern is filtered out, even if it appears on the allowlist.
Sourcepub fn build_command(&self, command: &str) -> Result<Command, SandboxViolation>
pub fn build_command(&self, command: &str) -> Result<Command, SandboxViolation>
Build a sandboxed tokio::process::Command ready to enter the arena.
Validates the command, sets a sanitized environment via env_clear() +
individual env() calls, and configures the working directory.
Trait Implementations§
Source§impl Clone for SandboxEnforcer
impl Clone for SandboxEnforcer
Source§fn clone(&self) -> SandboxEnforcer
fn clone(&self) -> SandboxEnforcer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more