Skip to main content

agent_sandbox/
config.rs

1use std::collections::HashMap;
2use std::path::PathBuf;
3use std::time::Duration;
4
5use serde::{Deserialize, Serialize};
6
7/// Configuration for creating a sandbox instance.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct SandboxConfig {
10    /// Host directory to expose as `/work` inside the sandbox.
11    pub work_dir: PathBuf,
12
13    /// Additional mount points beyond the work directory.
14    #[serde(default)]
15    pub mounts: Vec<MountPoint>,
16
17    /// Environment variables to set inside the sandbox.
18    #[serde(default)]
19    pub env_vars: HashMap<String, String>,
20
21    /// Maximum execution time per command (default: 30s).
22    #[serde(default = "default_timeout")]
23    pub timeout: Duration,
24
25    /// Maximum memory in bytes the WASM instance can use (default: 512MB).
26    #[serde(default = "default_memory_limit")]
27    pub memory_limit_bytes: u64,
28
29    /// Fuel limit for execution (higher = more compute allowed, default: 1 billion).
30    #[serde(default = "default_fuel_limit")]
31    pub fuel_limit: u64,
32}
33
34/// A directory mount point mapping host path to guest path.
35#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct MountPoint {
37    /// Path on the host filesystem.
38    pub host_path: PathBuf,
39
40    /// Path inside the sandbox (e.g., `/data`).
41    pub guest_path: String,
42
43    /// Whether the sandbox can write to this mount.
44    #[serde(default)]
45    pub writable: bool,
46}
47
48fn default_timeout() -> Duration {
49    Duration::from_secs(30)
50}
51
52fn default_memory_limit() -> u64 {
53    512 * 1024 * 1024 // 512 MB
54}
55
56fn default_fuel_limit() -> u64 {
57    1_000_000_000 // 1 billion instructions
58}
59
60impl Default for SandboxConfig {
61    fn default() -> Self {
62        Self {
63            work_dir: PathBuf::from("."),
64            mounts: Vec::new(),
65            env_vars: HashMap::new(),
66            timeout: default_timeout(),
67            memory_limit_bytes: default_memory_limit(),
68            fuel_limit: default_fuel_limit(),
69        }
70    }
71}