Skip to main content

vtcode_safety/sandboxing/
mod.rs

1//! Sandboxing module for VT Code
2//!
3//! This module provides sandbox policies and execution environment transformations
4//! inspired by the OpenAI Codex execution model and the AI sandbox field guide.
5//! It enables safe command execution with configurable isolation levels.
6//!
7//! ## Architecture
8//!
9//! The sandboxing system implements the field guide's three-question model:
10//! - **Boundary**: What is shared (kernel-enforced via Seatbelt/Landlock)
11//! - **Policy**: What can code touch (SandboxPolicy enum)
12//! - **Lifecycle**: What survives between runs (session-scoped approvals)
13//!
14//! Key components:
15//! - **SandboxPolicy**: Configurable isolation levels (ReadOnly, WorkspaceWrite, DangerFullAccess)
16//! - **SandboxManager**: Transforms command specifications into sandboxed execution environments
17//! - **SandboxPermissions**: Fine-grained permission control for individual operations
18//! - **NetworkAllowlistEntry**: Domain-based network egress control
19//! - **SensitivePath**: Credential location blocking
20//! - **ResourceLimits**: Memory, PID, disk, and CPU limits
21//!
22//! ## Usage
23//!
24//! ```rust,ignore
25//! use vtcode_core::sandboxing::{SandboxPolicy, SandboxManager, CommandSpec, ResourceLimits};
26//!
27//! let policy = SandboxPolicy::read_only();
28//! let manager = SandboxManager::new();
29//! let spec = CommandSpec {
30//!     program: "cat".to_string(),
31//!     args: vec!["file.txt".to_string()],
32//!     ..Default::default()
33//! };
34//!
35//! // Transform to sandboxed environment
36//! let exec_env = manager.transform(spec, &policy, std::path::Path::new("/tmp"), None)?;
37//! # Ok::<(), anyhow::Error>(())
38//! ```
39
40mod child_spawn;
41mod debug;
42mod exec_env;
43#[cfg(target_os = "linux")]
44mod linux;
45#[cfg(target_os = "linux")]
46mod linux_seccomp;
47mod manager;
48mod permissions;
49mod policy;
50
51pub use child_spawn::{
52    FILTERED_ENV_VARS, PRESERVED_ENV_VARS, VTCODE_SANDBOX_ACTIVE, VTCODE_SANDBOX_NETWORK_DISABLED, VTCODE_SANDBOX_TYPE,
53    VTCODE_SANDBOX_WRITABLE_ROOTS, build_sanitized_env, filter_sensitive_env, setup_parent_death_signal,
54    should_filter_env_var,
55};
56pub use debug::{
57    DebugSubcommand, SandboxDebugResult, debug_sandbox, sandbox_capabilities_summary, test_network_blocked,
58    test_path_writable,
59};
60pub use exec_env::{CommandSpec, ExecEnv, ExecExpiration, LinuxSandboxLauncher, SandboxType};
61#[cfg(target_os = "linux")]
62pub use linux::{apply_sandbox_restrictions, landlock_supported};
63pub use manager::{SandboxManager, SandboxTransformError};
64pub use permissions::{AdditionalPermissions, SandboxPermissions};
65pub use policy::{
66    BLOCKED_SYSCALLS, DEFAULT_SENSITIVE_PATHS, FILTERED_SYSCALLS, NetworkAllowlistEntry, ResourceLimits, SandboxPolicy,
67    SeccompProfile, SensitivePath, WritableRoot, default_sensitive_paths,
68};