Skip to main content

agent_sandbox/
config.rs

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