Files
optimclaw/src/sandbox/error.rs
T
Illia PolosukhinandClaude Opus 4.5 a39f5aa1a4 Add Docker execution sandbox for secure shell command isolation
Implements a general-purpose Docker sandbox (inspired by Codex) that provides:
- Container isolation for shell commands with ephemeral containers
- HTTP proxy for network access control with domain allowlist
- Credential injection by proxy (secrets never enter containers)
- Three security policies: ReadOnly, WorkspaceWrite, FullAccess
- Resource limits (memory, CPU, timeout enforcement)

Key components:
- SandboxManager: Main entry point coordinating proxy and containers
- NetworkProxy: HTTP proxy validating requests and injecting credentials
- ContainerRunner: Docker lifecycle management via bollard
- DomainAllowlist: Pattern matching for allowed network destinations

The ShellTool now routes commands through the sandbox when enabled,
with automatic fallback to direct execution if Docker is unavailable.

Configuration via SANDBOX_ENABLED, SANDBOX_POLICY, SANDBOX_TIMEOUT_SECS,
SANDBOX_MEMORY_LIMIT_MB, SANDBOX_IMAGE, SANDBOX_EXTRA_DOMAINS env vars.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
2026-02-04 22:09:52 -08:00

59 lines
1.8 KiB
Rust

//! Error types for the Docker execution sandbox.
use std::time::Duration;
/// Errors that can occur in the sandbox system.
#[derive(Debug, thiserror::Error)]
pub enum SandboxError {
/// Docker daemon is not available or not running.
#[error("Docker not available: {reason}")]
DockerNotAvailable { reason: String },
/// Failed to create container.
#[error("Container creation failed: {reason}")]
ContainerCreationFailed { reason: String },
/// Failed to start container.
#[error("Container start failed: {reason}")]
ContainerStartFailed { reason: String },
/// Command execution failed inside container.
#[error("Execution failed: {reason}")]
ExecutionFailed { reason: String },
/// Command timed out.
#[error("Command timed out after {0:?}")]
Timeout(Duration),
/// Container resource limit exceeded.
#[error("Resource limit exceeded: {resource} limit of {limit}")]
ResourceLimitExceeded { resource: String, limit: String },
/// Network proxy error.
#[error("Proxy error: {reason}")]
ProxyError { reason: String },
/// Network request blocked by policy.
#[error("Network request blocked: {reason}")]
NetworkBlocked { reason: String },
/// Credential injection failed.
#[error("Credential injection failed for {domain}: {reason}")]
CredentialInjectionFailed { domain: String, reason: String },
/// Docker API error.
#[error("Docker API error: {0}")]
Docker(#[from] bollard::errors::Error),
/// I/O error.
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
/// Configuration error.
#[error("Configuration error: {reason}")]
Config { reason: String },
}
/// Result type for sandbox operations.
pub type Result<T> = std::result::Result<T, SandboxError>;