Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(security): replace custom sandbox backends with tinybox-core

Steven Enamakeldd95c44a1e42
diff --git a/Cargo.lock b/Cargo.lock
index f2bea04cad..aeb74c69a1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3870,7 +3870,6 @@ dependencies = [
"iana-time-zone",
"k256",
"keyring",
- "landlock",
"lettre",
"libc",
"log",
@@ -3902,6 +3901,7 @@ dependencies = [
"tinyagents-registry",
"tinyagents-runtime",
"tinyagents-session",
+ "tinybox-core",
"tinybox-jail",
"tinybus",
"tinychannels",
@@ -6293,6 +6293,15 @@ dependencies = [
"tracing",
]
+[[package]]
+name = "tinybox-core"
+version = "0.1.8"
+dependencies = [
+ "async-trait",
+ "serde",
+ "thiserror 2.0.20",
+]
+
[[package]]
name = "tinybox-jail"
version = "0.1.8"
diff --git a/crates/openhuman-core/src/security/bubblewrap.rs b/crates/openhuman-core/src/security/bubblewrap.rs
deleted file mode 100644
index 86c5a69b67..0000000000
--- a/crates/openhuman-core/src/security/bubblewrap.rs
+++ /dev/null
@@ -1,84 +0,0 @@
-//! Bubblewrap sandbox (user namespaces for Linux/macOS)
-
-use crate::security::traits::Sandbox;
-use std::process::Command;
-
-/// Bubblewrap sandbox backend
-#[derive(Debug, Clone, Default)]
-pub struct BubblewrapSandbox;
-
-impl BubblewrapSandbox {
- pub fn new() -> std::io::Result<Self> {
- if Self::is_installed() {
- Ok(Self)
- } else {
- Err(std::io::Error::new(
- std::io::ErrorKind::NotFound,
- "Bubblewrap not found",
- ))
- }
- }
-
- pub fn probe() -> std::io::Result<Self> {
- Self::new()
- }
-
- fn is_installed() -> bool {
- Command::new("bwrap")
- .arg("--version")
- .output()
- .map(|o| o.status.success())
- .unwrap_or(false)
- }
-}
-
-impl Sandbox for BubblewrapSandbox {
- fn wrap_command(&self, cmd: &mut Command) -> std::io::Result<()> {
- let program = cmd.get_program().to_string_lossy().to_string();
- let args: Vec<String> = cmd
- .get_args()
- .map(|s| s.to_string_lossy().to_string())
- .collect();
-
- let mut bwrap_cmd = Command::new("bwrap");
- bwrap_cmd.args([
- "--ro-bind",
- "/usr",
- "/usr",
- "--dev",
- "/dev",
- "--proc",
- "/proc",
- // Private, empty /tmp inside the sandbox instead of sharing the
- // host's read-write /tmp. Mirrors firejail.rs's `--private=home`
- // least-privilege posture: the agent gets a scratch tmp that is
- // discarded on exit and cannot read/overwrite other processes'
- // host temp files, lockfiles, sockets, or staged secrets.
- "--tmpfs",
- "/tmp",
- "--unshare-all",
- "--die-with-parent",
- ]);
- bwrap_cmd.arg(&program);
- bwrap_cmd.args(&args);
-
- *cmd = bwrap_cmd;
- Ok(())
- }
-
- fn is_available(&self) -> bool {
- Self::is_installed()
- }
-
- fn name(&self) -> &str {
- "bubblewrap"
- }
-
- fn description(&self) -> &str {
- "User namespace sandbox (requires bwrap)"
- }
-}
-
-#[cfg(test)]
-#[path = "bubblewrap_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/security/bubblewrap_tests.rs b/crates/openhuman-core/src/security/bubblewrap_tests.rs
deleted file mode 100644
index 35b7db1ada..0000000000
--- a/crates/openhuman-core/src/security/bubblewrap_tests.rs
+++ /dev/null
@@ -1,136 +0,0 @@
-use super::*;
-
-#[test]
-fn bubblewrap_sandbox_name() {
- let sandbox = BubblewrapSandbox;
- assert_eq!(sandbox.name(), "bubblewrap");
-}
-
-#[test]
-fn bubblewrap_is_available_only_if_installed() {
- // Result depends on whether bwrap is installed
- let sandbox = BubblewrapSandbox;
- let _available = sandbox.is_available();
-
- // Either way, the name should still work
- assert_eq!(sandbox.name(), "bubblewrap");
-}
-
-// ── §1.1 Sandbox isolation flag tests ──────────────────────
-
-#[test]
-fn bubblewrap_wrap_command_includes_isolation_flags() {
- let sandbox = BubblewrapSandbox;
- let mut cmd = Command::new("echo");
- cmd.arg("hello");
- sandbox.wrap_command(&mut cmd).unwrap();
-
- assert_eq!(
- cmd.get_program().to_string_lossy(),
- "bwrap",
- "wrapped command should use bwrap as program"
- );
-
- let args: Vec<String> = cmd
- .get_args()
- .map(|s| s.to_string_lossy().to_string())
- .collect();
-
- assert!(
- args.contains(&"--unshare-all".to_string()),
- "must include --unshare-all for namespace isolation"
- );
- assert!(
- args.contains(&"--die-with-parent".to_string()),
- "must include --die-with-parent to prevent orphan processes"
- );
- assert!(
- !args.contains(&"--share-net".to_string()),
- "must NOT include --share-net (network should be blocked)"
- );
-}
-
-#[test]
-fn bubblewrap_wrap_command_preserves_original_command() {
- let sandbox = BubblewrapSandbox;
- let mut cmd = Command::new("ls");
- cmd.arg("-la");
- cmd.arg("/tmp");
- sandbox.wrap_command(&mut cmd).unwrap();
-
- let args: Vec<String> = cmd
- .get_args()
- .map(|s| s.to_string_lossy().to_string())
- .collect();
-
- assert!(
- args.contains(&"ls".to_string()),
- "original program must be passed as argument"
- );
- assert!(
- args.contains(&"-la".to_string()),
- "original args must be preserved"
- );
- assert!(
- args.contains(&"/tmp".to_string()),
- "original args must be preserved"
- );
-}
-
-#[test]
-fn bubblewrap_wrap_command_binds_required_paths() {
- let sandbox = BubblewrapSandbox;
- let mut cmd = Command::new("echo");
- sandbox.wrap_command(&mut cmd).unwrap();
-
- let args: Vec<String> = cmd
- .get_args()
- .map(|s| s.to_string_lossy().to_string())
- .collect();
-
- assert!(
- args.contains(&"--ro-bind".to_string()),
- "must include read-only bind for /usr"
- );
- assert!(
- args.contains(&"--dev".to_string()),
- "must include /dev mount"
- );
- assert!(
- args.contains(&"--proc".to_string()),
- "must include /proc mount"
- );
-}
-
-#[test]
-fn bubblewrap_wrap_command_uses_private_tmpfs_not_host_tmp() {
- let sandbox = BubblewrapSandbox;
- let mut cmd = Command::new("echo");
- sandbox.wrap_command(&mut cmd).unwrap();
-
- let args: Vec<String> = cmd
- .get_args()
- .map(|s| s.to_string_lossy().to_string())
- .collect();
-
- // The sandbox must mount a private tmpfs over /tmp ...
- let tmpfs_pos = args.iter().position(|a| a == "--tmpfs");
- assert!(
- tmpfs_pos.is_some(),
- "must include --tmpfs for a private /tmp"
- );
- assert_eq!(
- args.get(tmpfs_pos.unwrap() + 1).map(String::as_str),
- Some("/tmp"),
- "--tmpfs must target /tmp"
- );
-
- // ... and must NOT read-write bind the host /tmp into the sandbox.
- let has_tmp_rw_bind = args
- .windows(3)
- .any(|w| w[0] == "--bind" && w[1] == "/tmp" && w[2] == "/tmp");
- assert!(
- !has_tmp_rw_bind,
- "must NOT bind host /tmp read-write into the sandbox"
- );
-}
diff --git a/crates/openhuman-core/src/security/detect.rs b/crates/openhuman-core/src/security/detect.rs
deleted file mode 100644
index e7c9190399..0000000000
--- a/crates/openhuman-core/src/security/detect.rs
+++ /dev/null
@@ -1,108 +0,0 @@
-//! Auto-detection of available security features
-
-use crate::config::{SandboxBackend, SecurityConfig};
-use crate::security::traits::Sandbox;
-use std::sync::Arc;
-
-/// Create a sandbox based on auto-detection or explicit config
-pub fn create_sandbox(config: &SecurityConfig) -> Arc<dyn Sandbox> {
- let backend = &config.sandbox.backend;
-
- // If explicitly disabled, return noop
- if matches!(backend, SandboxBackend::None) || config.sandbox.enabled == Some(false) {
- return Arc::new(super::traits::NoopSandbox);
- }
-
- // If specific backend requested, try that
- match backend {
- SandboxBackend::Landlock => {
- #[cfg(feature = "sandbox-landlock")]
- {
- if std::env::consts::OS == "linux" {
- if let Ok(sandbox) = super::landlock::LandlockSandbox::new() {
- return Arc::new(sandbox);
- }
- }
- }
- log::warn!("Landlock requested but not available, falling back to application-layer");
- Arc::new(super::traits::NoopSandbox)
- }
- SandboxBackend::Firejail => {
- if std::env::consts::OS == "linux" {
- if let Ok(sandbox) = super::firejail::FirejailSandbox::new() {
- return Arc::new(sandbox);
- }
- }
- log::warn!("Firejail requested but not available, falling back to application-layer");
- Arc::new(super::traits::NoopSandbox)
- }
- SandboxBackend::Bubblewrap => {
- #[cfg(feature = "sandbox-bubblewrap")]
- {
- if matches!(std::env::consts::OS, "linux" | "macos") {
- if let Ok(sandbox) = super::bubblewrap::BubblewrapSandbox::new() {
- return Arc::new(sandbox);
- }
- }
- }
- log::warn!("Bubblewrap requested but not available, falling back to application-layer");
- Arc::new(super::traits::NoopSandbox)
- }
- SandboxBackend::Docker => {
- if let Ok(sandbox) = super::docker::DockerSandbox::new() {
- return Arc::new(sandbox);
- }
- log::warn!("Docker requested but not available, falling back to application-layer");
- Arc::new(super::traits::NoopSandbox)
- }
- SandboxBackend::Auto | SandboxBackend::None => {
- // Auto-detect best available
- detect_best_sandbox()
- }
- }
-}
-
-/// Auto-detect the best available sandbox
-fn detect_best_sandbox() -> Arc<dyn Sandbox> {
- if std::env::consts::OS == "linux" {
- // Try Landlock first (native, no dependencies)
- #[cfg(feature = "sandbox-landlock")]
- {
- if let Ok(sandbox) = super::landlock::LandlockSandbox::probe() {
- log::info!("Landlock sandbox enabled (Linux kernel 5.13+)");
- return Arc::new(sandbox);
- }
- }
-
- // Try Firejail second (user-space tool)
- if let Ok(sandbox) = super::firejail::FirejailSandbox::probe() {
- log::info!("Firejail sandbox enabled");
- return Arc::new(sandbox);
- }
- }
-
- if std::env::consts::OS == "macos" {
- // Try Bubblewrap on macOS
- #[cfg(feature = "sandbox-bubblewrap")]
- {
- if let Ok(sandbox) = super::bubblewrap::BubblewrapSandbox::probe() {
- log::info!("Bubblewrap sandbox enabled");
- return Arc::new(sandbox);
- }
- }
- }
-
- // Docker is heavy but works everywhere if docker is installed
- if let Ok(sandbox) = super::docker::DockerSandbox::probe() {
- log::info!("Docker sandbox enabled");
- return Arc::new(sandbox);
- }
-
- // Fallback: application-layer security only
- log::info!("No sandbox backend available, using application-layer security");
- Arc::new(super::traits::NoopSandbox)
-}
-
-#[cfg(test)]
-#[path = "detect_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/security/detect_tests.rs b/crates/openhuman-core/src/security/detect_tests.rs
deleted file mode 100644
index d6b21a5a44..0000000000
--- a/crates/openhuman-core/src/security/detect_tests.rs
+++ /dev/null
@@ -1,115 +0,0 @@
-use super::*;
-use crate::config::{SandboxConfig, SecurityConfig};
-
-#[test]
-fn detect_best_sandbox_returns_something() {
- let sandbox = detect_best_sandbox();
- // Should always return at least NoopSandbox
- assert!(sandbox.is_available());
-}
-
-#[test]
-fn explicit_none_returns_noop() {
- let config = SecurityConfig {
- sandbox: SandboxConfig {
- enabled: Some(false),
- backend: SandboxBackend::None,
- firejail_args: Vec::new(),
- },
- ..SecurityConfig::default()
- };
- let sandbox = create_sandbox(&config);
- assert_eq!(sandbox.name(), "none");
-}
-
-#[test]
-fn auto_mode_detects_something() {
- let config = SecurityConfig {
- sandbox: SandboxConfig {
- enabled: None, // Auto-detect
- backend: SandboxBackend::Auto,
- firejail_args: Vec::new(),
- },
- ..SecurityConfig::default()
- };
- let sandbox = create_sandbox(&config);
- // Should return some sandbox (at least NoopSandbox)
- assert!(sandbox.is_available());
-}
-
-#[test]
-fn disabled_via_enabled_false_returns_noop() {
- let config = SecurityConfig {
- sandbox: SandboxConfig {
- enabled: Some(false),
- backend: SandboxBackend::Auto,
- firejail_args: Vec::new(),
- },
- ..SecurityConfig::default()
- };
- let sandbox = create_sandbox(&config);
- assert_eq!(sandbox.name(), "none");
-}
-
-#[test]
-fn landlock_backend_on_non_linux_falls_back() {
- // On macOS/Windows, Landlock isn't available — should fall back to Noop
- let config = SecurityConfig {
- sandbox: SandboxConfig {
- enabled: None,
- backend: SandboxBackend::Landlock,
- firejail_args: Vec::new(),
- },
- ..SecurityConfig::default()
- };
- let sandbox = create_sandbox(&config);
- if std::env::consts::OS != "linux" {
- assert_eq!(sandbox.name(), "none");
- }
-}
-
-#[test]
-fn firejail_backend_on_non_linux_falls_back() {
- let config = SecurityConfig {
- sandbox: SandboxConfig {
- enabled: None,
- backend: SandboxBackend::Firejail,
- firejail_args: Vec::new(),
- },
- ..SecurityConfig::default()
- };
- let sandbox = create_sandbox(&config);
- if std::env::consts::OS != "linux" {
- assert_eq!(sandbox.name(), "none");
- }
-}
-
-#[test]
-fn bubblewrap_backend_falls_back_when_unavailable() {
- let config = SecurityConfig {
- sandbox: SandboxConfig {
- enabled: None,
- backend: SandboxBackend::Bubblewrap,
- firejail_args: Vec::new(),
- },
- ..SecurityConfig::default()
- };
- let sandbox = create_sandbox(&config);
- // Bubblewrap probably isn't installed on CI/dev — expect fallback
- assert!(sandbox.is_available());
-}
-
-#[test]
-fn docker_backend_falls_back_when_unavailable() {
- let config = SecurityConfig {
- sandbox: SandboxConfig {
- enabled: None,
- backend: SandboxBackend::Docker,
- firejail_args: Vec::new(),
- },
- ..SecurityConfig::default()
- };
- let sandbox = create_sandbox(&config);
- // Docker may or may not be available
- assert!(sandbox.is_available());
-}
diff --git a/crates/openhuman-core/src/security/docker.rs b/crates/openhuman-core/src/security/docker.rs
deleted file mode 100644
index 84754aa12d..0000000000
--- a/crates/openhuman-core/src/security/docker.rs
+++ /dev/null
@@ -1,98 +0,0 @@
-//! Docker sandbox (container isolation)
-
-use crate::security::traits::Sandbox;
-use std::process::Command;
-
-/// Docker sandbox backend
-#[derive(Debug, Clone)]
-pub struct DockerSandbox {
- image: String,
-}
-
-impl Default for DockerSandbox {
- fn default() -> Self {
- Self {
- image: "alpine:latest".to_string(),
- }
- }
-}
-
-impl DockerSandbox {
- pub fn new() -> std::io::Result<Self> {
- if Self::is_installed() {
- Ok(Self::default())
- } else {
- Err(std::io::Error::new(
- std::io::ErrorKind::NotFound,
- "Docker not found",
- ))
- }
- }
-
- pub fn with_image(image: String) -> std::io::Result<Self> {
- if Self::is_installed() {
- Ok(Self { image })
- } else {
- Err(std::io::Error::new(
- std::io::ErrorKind::NotFound,
- "Docker not found",
- ))
- }
- }
-
- pub fn probe() -> std::io::Result<Self> {
- Self::new()
- }
-
- fn is_installed() -> bool {
- Command::new("docker")
- .arg("--version")
- .output()
- .map(|o| o.status.success())
- .unwrap_or(false)
- }
-}
-
-impl Sandbox for DockerSandbox {
- fn wrap_command(&self, cmd: &mut Command) -> std::io::Result<()> {
- let program = cmd.get_program().to_string_lossy().to_string();
- let args: Vec<String> = cmd
- .get_args()
- .map(|s| s.to_string_lossy().to_string())
- .collect();
-
- let mut docker_cmd = Command::new("docker");
- docker_cmd.args([
- "run",
- "--rm",
- "--memory",
- "512m",
- "--cpus",
- "1.0",
- "--network",
- "none",
- ]);
- docker_cmd.arg(&self.image);
- docker_cmd.arg(&program);
- docker_cmd.args(&args);
-
- *cmd = docker_cmd;
- Ok(())
- }
-
- fn is_available(&self) -> bool {
- Self::is_installed()
- }
-
- fn name(&self) -> &str {
- "docker"
- }
-
- fn description(&self) -> &str {
- "Docker container isolation (requires docker)"
- }
-}
-
-#[cfg(test)]
-#[path = "docker_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/security/docker_tests.rs b/crates/openhuman-core/src/security/docker_tests.rs
deleted file mode 100644
index 703145e8b6..0000000000
--- a/crates/openhuman-core/src/security/docker_tests.rs
+++ /dev/null
@@ -1,118 +0,0 @@
-use super::*;
-
-#[test]
-fn docker_sandbox_name() {
- let sandbox = DockerSandbox::default();
- assert_eq!(sandbox.name(), "docker");
-}
-
-#[test]
-fn docker_sandbox_default_image() {
- let sandbox = DockerSandbox::default();
- assert_eq!(sandbox.image, "alpine:latest");
-}
-
-#[test]
-fn docker_with_custom_image() {
- let result = DockerSandbox::with_image("ubuntu:latest".to_string());
- match result {
- Ok(sandbox) => assert_eq!(sandbox.image, "ubuntu:latest"),
- Err(_) => assert!(!DockerSandbox::is_installed()),
- }
-}
-
-// ── §1.1 Sandbox isolation flag tests ──────────────────────
-
-#[test]
-fn docker_wrap_command_includes_isolation_flags() {
- let sandbox = DockerSandbox::default();
- let mut cmd = Command::new("echo");
- cmd.arg("hello");
- sandbox.wrap_command(&mut cmd).unwrap();
-
- assert_eq!(
- cmd.get_program().to_string_lossy(),
- "docker",
- "wrapped command should use docker as program"
- );
-
- let args: Vec<String> = cmd
- .get_args()
- .map(|s| s.to_string_lossy().to_string())
- .collect();
-
- assert!(
- args.contains(&"run".to_string()),
- "must include 'run' subcommand"
- );
- assert!(
- args.contains(&"--rm".to_string()),
- "must include --rm for auto-cleanup"
- );
- assert!(
- args.contains(&"--network".to_string()),
- "must include --network flag"
- );
- assert!(
- args.contains(&"none".to_string()),
- "network must be set to 'none' for isolation"
- );
- assert!(
- args.contains(&"--memory".to_string()),
- "must include --memory limit"
- );
- assert!(
- args.contains(&"512m".to_string()),
- "memory limit must be 512m"
- );
- assert!(
- args.contains(&"--cpus".to_string()),
- "must include --cpus limit"
- );
- assert!(args.contains(&"1.0".to_string()), "CPU limit must be 1.0");
-}
-
-#[test]
-fn docker_wrap_command_preserves_original_command() {
- let sandbox = DockerSandbox::default();
- let mut cmd = Command::new("ls");
- cmd.arg("-la");
- sandbox.wrap_command(&mut cmd).unwrap();
-
- let args: Vec<String> = cmd
- .get_args()
- .map(|s| s.to_string_lossy().to_string())
- .collect();
-
- assert!(
- args.contains(&"alpine:latest".to_string()),
- "must include the container image"
- );
- assert!(
- args.contains(&"ls".to_string()),
- "original program must be passed as argument"
- );
- assert!(
- args.contains(&"-la".to_string()),
- "original args must be preserved"
- );
-}
-
-#[test]
-fn docker_wrap_command_uses_custom_image() {
- let sandbox = DockerSandbox {
- image: "ubuntu:22.04".to_string(),
- };
- let mut cmd = Command::new("echo");
- sandbox.wrap_command(&mut cmd).unwrap();
-
- let args: Vec<String> = cmd
- .get_args()
- .map(|s| s.to_string_lossy().to_string())
- .collect();
-
- assert!(
- args.contains(&"ubuntu:22.04".to_string()),
- "must use the custom image"
- );
-}
diff --git a/crates/openhuman-core/src/security/firejail.rs b/crates/openhuman-core/src/security/firejail.rs
deleted file mode 100644
index f7c7edf809..0000000000
--- a/crates/openhuman-core/src/security/firejail.rs
+++ /dev/null
@@ -1,87 +0,0 @@
-//! Firejail sandbox (Linux user-space sandboxing)
-//!
-//! Firejail is a SUID sandbox program that Linux applications use to sandbox themselves.
-
-use crate::security::traits::Sandbox;
-use std::process::Command;
-
-/// Firejail sandbox backend for Linux
-#[derive(Debug, Clone, Default)]
-pub struct FirejailSandbox;
-
-impl FirejailSandbox {
- /// Create a new Firejail sandbox
- pub fn new() -> std::io::Result<Self> {
- if Self::is_installed() {
- Ok(Self)
- } else {
- Err(std::io::Error::new(
- std::io::ErrorKind::NotFound,
- "Firejail not found. Install firejail using your system package manager.",
- ))
- }
- }
-
- /// Probe if Firejail is available (for auto-detection)
- pub fn probe() -> std::io::Result<Self> {
- Self::new()
- }
-
- /// Check if firejail is installed
- fn is_installed() -> bool {
- Command::new("firejail")
- .arg("--version")
- .output()
- .map(|o| o.status.success())
- .unwrap_or(false)
- }
-}
-
-impl Sandbox for FirejailSandbox {
- fn wrap_command(&self, cmd: &mut Command) -> std::io::Result<()> {
- // Prepend firejail to the command
- let program = cmd.get_program().to_string_lossy().to_string();
- let args: Vec<String> = cmd
- .get_args()
- .map(|s| s.to_string_lossy().to_string())
- .collect();
-
- // Build firejail wrapper with security flags
- let mut firejail_cmd = Command::new("firejail");
- firejail_cmd.args([
- "--private=home", // New home directory
- "--private-dev", // Minimal /dev
- "--nosound", // No audio
- "--no3d", // No 3D acceleration
- "--novideo", // No video devices
- "--nowheel", // No input devices
- "--notv", // No TV devices
- "--noprofile", // Skip profile loading
- "--quiet", // Suppress warnings
- ]);
-
- // Add the original command
- firejail_cmd.arg(&program);
- firejail_cmd.args(&args);
-
- // Replace the command
- *cmd = firejail_cmd;
- Ok(())
- }
-
- fn is_available(&self) -> bool {
- Self::is_installed()
- }
-
- fn name(&self) -> &str {
- "firejail"
- }
-
- fn description(&self) -> &str {
- "Linux user-space sandbox (requires firejail to be installed)"
- }
-}
-
-#[cfg(test)]
-#[path = "firejail_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/security/firejail_tests.rs b/crates/openhuman-core/src/security/firejail_tests.rs
deleted file mode 100644
index 120e2951a5..0000000000
--- a/crates/openhuman-core/src/security/firejail_tests.rs
+++ /dev/null
@@ -1,107 +0,0 @@
-use super::*;
-
-#[test]
-fn firejail_sandbox_name() {
- assert_eq!(FirejailSandbox.name(), "firejail");
-}
-
-#[test]
-fn firejail_description_mentions_dependency() {
- let desc = FirejailSandbox.description();
- assert!(desc.contains("firejail"));
-}
-
-#[test]
-fn firejail_new_fails_if_not_installed() {
- // This will fail unless firejail is actually installed
- let result = FirejailSandbox::new();
- match result {
- Ok(_) => println!("Firejail is installed"),
- Err(e) => assert!(
- e.kind() == std::io::ErrorKind::NotFound || e.kind() == std::io::ErrorKind::Unsupported
- ),
- }
-}
-
-#[test]
-fn firejail_wrap_command_prepends_firejail() {
- let sandbox = FirejailSandbox;
- let mut cmd = Command::new("echo");
- cmd.arg("test");
-
- // Note: wrap_command will fail if firejail isn't installed,
- // but we can still test the logic structure
- let _ = sandbox.wrap_command(&mut cmd);
-
- // After wrapping, the program should be firejail
- if sandbox.is_available() {
- assert_eq!(cmd.get_program().to_string_lossy(), "firejail");
- }
-}
-
-// ── §1.1 Sandbox isolation flag tests ──────────────────────
-
-#[test]
-fn firejail_wrap_command_includes_all_security_flags() {
- let sandbox = FirejailSandbox;
- let mut cmd = Command::new("echo");
- cmd.arg("test");
- sandbox.wrap_command(&mut cmd).unwrap();
-
- assert_eq!(
- cmd.get_program().to_string_lossy(),
- "firejail",
- "wrapped command should use firejail as program"
- );
-
- let args: Vec<String> = cmd
- .get_args()
- .map(|s| s.to_string_lossy().to_string())
- .collect();
-
- let expected_flags = [
- "--private=home",
- "--private-dev",
- "--nosound",
- "--no3d",
- "--novideo",
- "--nowheel",
- "--notv",
- "--noprofile",
- "--quiet",
- ];
-
- for flag in &expected_flags {
- assert!(
- args.contains(&flag.to_string()),
- "must include security flag: {flag}"
- );
- }
-}
-
-#[test]
-fn firejail_wrap_command_preserves_original_command() {
- let sandbox = FirejailSandbox;
- let mut cmd = Command::new("ls");
- cmd.arg("-la");
- cmd.arg("/workspace");
- sandbox.wrap_command(&mut cmd).unwrap();
-
- let args: Vec<String> = cmd
- .get_args()
- .map(|s| s.to_string_lossy().to_string())
- .collect();
-
- assert!(
- args.contains(&"ls".to_string()),
- "original program must be passed as argument"
- );
- assert!(
- args.contains(&"-la".to_string()),
- "original args must be preserved"
- );
- assert!(
- args.contains(&"/workspace".to_string()),
- "original args must be preserved"
- );
-}
diff --git a/crates/openhuman-core/src/security/landlock.rs b/crates/openhuman-core/src/security/landlock.rs
deleted file mode 100644
index 3ba1e6bf39..0000000000
--- a/crates/openhuman-core/src/security/landlock.rs
+++ /dev/null
@@ -1,205 +0,0 @@
-//! Landlock sandbox (Linux kernel 5.13+ LSM)
-//!
-//! Landlock provides unprivileged sandboxing through the Linux kernel.
-//! This module uses the pure-Rust `landlock` crate for filesystem access control.
-
-#[cfg(all(feature = "sandbox-landlock", target_os = "linux"))]
-use landlock::{AccessFs, PathBeneath, PathFd, Ruleset, RulesetAttr, RulesetCreatedAttr};
-#[cfg(all(feature = "sandbox-landlock", target_os = "linux"))]
-use std::path::Path;
-
-use crate::security::traits::Sandbox;
-
-/// Landlock sandbox backend for Linux
-#[cfg(all(feature = "sandbox-landlock", target_os = "linux"))]
-#[derive(Debug)]
-pub struct LandlockSandbox {
- workspace_dir: Option<std::path::PathBuf>,
-}
-
-#[cfg(all(feature = "sandbox-landlock", target_os = "linux"))]
-impl LandlockSandbox {
- /// Create a new Landlock sandbox with the given workspace directory
- pub fn new() -> std::io::Result<Self> {
- Self::with_workspace(None)
- }
-
- /// Create a Landlock sandbox with a specific workspace directory
- pub fn with_workspace(workspace_dir: Option<std::path::PathBuf>) -> std::io::Result<Self> {
- // Test if Landlock is available by trying to create a minimal ruleset
- let test_ruleset = Ruleset::default()
- .handle_access(AccessFs::ReadFile | AccessFs::WriteFile)
- .and_then(|ruleset| ruleset.create());
-
- match test_ruleset {
- Ok(_) => Ok(Self { workspace_dir }),
- Err(e) => {
- log::debug!("Landlock not available: {}", e);
- Err(std::io::Error::new(
- std::io::ErrorKind::Unsupported,
- "Landlock not available",
- ))
- }
- }
- }
-
- /// Probe if Landlock is available (for auto-detection)
- pub fn probe() -> std::io::Result<Self> {
- Self::new()
- }
-
- /// Apply Landlock restrictions to the current process
- fn apply_restrictions(&self) -> std::io::Result<()> {
- let mut ruleset = Ruleset::default()
- .handle_access(
- AccessFs::ReadFile
- | AccessFs::WriteFile
- | AccessFs::ReadDir
- | AccessFs::RemoveDir
- | AccessFs::RemoveFile
- | AccessFs::MakeChar
- | AccessFs::MakeSock
- | AccessFs::MakeFifo
- | AccessFs::MakeBlock
- | AccessFs::MakeReg
- | AccessFs::MakeSym,
- )
- .and_then(|ruleset| ruleset.create())
- .map_err(|e| std::io::Error::other(e.to_string()))?;
-
- // Allow workspace directory (read/write)
- if let Some(ref workspace) = self.workspace_dir {
- if workspace.exists() {
- let workspace_fd =
- PathFd::new(workspace).map_err(|e| std::io::Error::other(e.to_string()))?;
- ruleset = ruleset
- .add_rule(PathBeneath::new(
- workspace_fd,
- AccessFs::ReadFile | AccessFs::WriteFile | AccessFs::ReadDir,
- ))
- .map_err(|e| std::io::Error::other(e.to_string()))?;
- }
- }
-
- // Allow /tmp for general operations
- let tmp_fd =
- PathFd::new(Path::new("/tmp")).map_err(|e| std::io::Error::other(e.to_string()))?;
- ruleset = ruleset
- .add_rule(PathBeneath::new(
- tmp_fd,
- AccessFs::ReadFile | AccessFs::WriteFile,
- ))
- .map_err(|e| std::io::Error::other(e.to_string()))?;
-
- // Allow /usr and /bin for executing commands
- let usr_fd =
- PathFd::new(Path::new("/usr")).map_err(|e| std::io::Error::other(e.to_string()))?;
- ruleset = ruleset
- .add_rule(PathBeneath::new(
- usr_fd,
- AccessFs::ReadFile | AccessFs::ReadDir,
- ))
- .map_err(|e| std::io::Error::other(e.to_string()))?;
-
- let bin_fd =
- PathFd::new(Path::new("/bin")).map_err(|e| std::io::Error::other(e.to_string()))?;
- ruleset = ruleset
- .add_rule(PathBeneath::new(
- bin_fd,
- AccessFs::ReadFile | AccessFs::ReadDir,
- ))
- .map_err(|e| std::io::Error::other(e.to_string()))?;
-
- // Apply the ruleset
- match ruleset.restrict_self() {
- Ok(_) => {
- log::debug!("Landlock restrictions applied successfully");
- Ok(())
- }
- Err(e) => {
- log::warn!("Failed to apply Landlock restrictions: {}", e);
- Err(std::io::Error::other(e.to_string()))
- }
- }
- }
-}
-
-#[cfg(all(feature = "sandbox-landlock", target_os = "linux"))]
-impl Sandbox for LandlockSandbox {
- fn wrap_command(&self, _cmd: &mut std::process::Command) -> std::io::Result<()> {
- // Apply Landlock restrictions before executing the command
- // Note: This affects the current process, not the child process
- // Child processes inherit the Landlock restrictions
- self.apply_restrictions()
- }
-
- fn is_available(&self) -> bool {
- // Try to create a minimal ruleset to verify availability
- Ruleset::default()
- .handle_access(AccessFs::ReadFile)
- .and_then(|ruleset| ruleset.create())
- .is_ok()
- }
-
- fn name(&self) -> &str {
- "landlock"
- }
-
- fn description(&self) -> &str {
- "Linux kernel LSM sandboxing (filesystem access control)"
- }
-}
-
-// Stub implementations for non-Linux or when feature is disabled
-#[cfg(not(all(feature = "sandbox-landlock", target_os = "linux")))]
-pub struct LandlockSandbox;
-
-#[cfg(not(all(feature = "sandbox-landlock", target_os = "linux")))]
-impl LandlockSandbox {
- pub fn new() -> std::io::Result<Self> {
- Err(std::io::Error::new(
- std::io::ErrorKind::Unsupported,
- "Landlock is only supported on Linux with the sandbox-landlock feature",
- ))
- }
-
- pub fn with_workspace(_workspace_dir: Option<std::path::PathBuf>) -> std::io::Result<Self> {
- Err(std::io::Error::new(
- std::io::ErrorKind::Unsupported,
- "Landlock is only supported on Linux",
- ))
- }
-
- pub fn probe() -> std::io::Result<Self> {
- Err(std::io::Error::new(
- std::io::ErrorKind::Unsupported,
- "Landlock is only supported on Linux",
- ))
- }
-}
-
-#[cfg(not(all(feature = "sandbox-landlock", target_os = "linux")))]
-impl Sandbox for LandlockSandbox {
- fn wrap_command(&self, _cmd: &mut std::process::Command) -> std::io::Result<()> {
- Err(std::io::Error::new(
- std::io::ErrorKind::Unsupported,
- "Landlock is only supported on Linux",
- ))
- }
-
- fn is_available(&self) -> bool {
- false
- }
-
- fn name(&self) -> &str {
- "landlock"
- }
-
- fn description(&self) -> &str {
- "Linux kernel LSM sandboxing (not available on this platform)"
- }
-}
-
-#[cfg(test)]
-#[path = "landlock_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/security/landlock_tests.rs b/crates/openhuman-core/src/security/landlock_tests.rs
deleted file mode 100644
index 0c2f98981c..0000000000
--- a/crates/openhuman-core/src/security/landlock_tests.rs
+++ /dev/null
@@ -1,41 +0,0 @@
-use super::*;
-
-#[cfg(all(feature = "sandbox-landlock", target_os = "linux"))]
-#[test]
-fn landlock_sandbox_name() {
- if let Ok(sandbox) = LandlockSandbox::new() {
- assert_eq!(sandbox.name(), "landlock");
- }
-}
-
-#[cfg(not(all(feature = "sandbox-landlock", target_os = "linux")))]
-#[test]
-fn landlock_not_available_on_non_linux() {
- assert!(!LandlockSandbox.is_available());
- assert_eq!(LandlockSandbox.name(), "landlock");
-}
-
-#[test]
-fn landlock_with_none_workspace() {
- // Should work even without a workspace directory
- let result = LandlockSandbox::with_workspace(None);
- // Result depends on platform and feature flag
- match result {
- Ok(sandbox) => assert!(sandbox.is_available()),
- Err(_) => {
- // Stub, feature off, or Linux kernel without Landlock support
- }
- }
-}
-
-// ── §1.1 Landlock stub tests ──────────────────────────────
-
-#[cfg(not(all(feature = "sandbox-landlock", target_os = "linux")))]
-#[test]
-fn landlock_stub_wrap_command_returns_unsupported() {
- let sandbox = LandlockSandbox;
- let mut cmd = std::process::Command::new("echo");
- let result = sandbox.wrap_command(&mut cmd);
- assert!(result.is_err());
- assert_eq!(result.unwrap_err().kind(), std::io::ErrorKind::Unsupported);
-}
diff --git a/crates/openhuman-core/src/security/mod.rs b/crates/openhuman-core/src/security/mod.rs
index 9b2a4633df..4099be65d6 100644
--- a/crates/openhuman-core/src/security/mod.rs
+++ b/crates/openhuman-core/src/security/mod.rs
@@ -10,24 +10,18 @@ pub mod audit;
// `Guard<D>` decorator draws from, and a swapped driver must never see any of
// it. None of them is gated — the family is kernel, permanently.
pub mod approval;
-pub mod bubblewrap;
pub mod credentials;
-pub mod detect;
pub mod devices;
-pub mod docker;
pub mod egress;
pub mod encryption;
-pub mod firejail;
pub mod keyring;
pub mod keyring_consent;
-pub mod landlock;
pub mod live_policy;
pub mod pairing;
pub mod pii;
pub mod policy;
pub mod prompt_injection;
pub mod secrets;
-pub mod traits;
#[allow(unused_imports)]
pub use self::keyring::SecretStore;
@@ -38,8 +32,6 @@ pub use audit::{
};
pub use core::*;
#[allow(unused_imports)]
-pub use detect::create_sandbox;
-#[allow(unused_imports)]
pub use egress::{
emit_external_transfer, enforce_egress, local_only_blocks, local_only_tool_block, DataKind,
EgressDescriptor, EgressReason, IdentificationRisk,
@@ -62,8 +54,6 @@ pub use policy::{CommandClass, GateDecision};
#[allow(unused_imports)]
pub use policy::{TrustedAccess, TrustedRoot};
pub use policy::{POLICY_BLOCKED_MARKER, POLICY_DENIED_MARKER};
-#[allow(unused_imports)]
-pub use traits::{NoopSandbox, Sandbox};
pub use schemas::{
all_controller_schemas as all_security_controller_schemas,
diff --git a/crates/openhuman-core/src/security/policy/command_checks.rs b/crates/openhuman-core/src/security/policy/command_checks.rs
index 925cd8c66f..5347b2f012 100644
--- a/crates/openhuman-core/src/security/policy/command_checks.rs
+++ b/crates/openhuman-core/src/security/policy/command_checks.rs
@@ -3,15 +3,15 @@ use crate::util::floor_char_boundary;
use super::policy_command::{
classify_segment, has_dangerous_env_prefix, has_hidden_execution, is_command_executor,
};
+use super::types::{
+ AutonomyLevel, CommandClass, CommandRiskLevel, GateDecision, SecurityPolicy,
+ POLICY_BLOCKED_MARKER,
+};
use tinybox_core::shell::scan::{
command_basename, contains_unquoted_char, contains_unquoted_single_ampersand,
has_leading_env_assignment, normalized_command_name, skip_env_assignments,
split_unquoted_segments, strip_quoted_heredoc_bodies,
};
-use super::types::{
- AutonomyLevel, CommandClass, CommandRiskLevel, GateDecision, SecurityPolicy,
- POLICY_BLOCKED_MARKER,
-};
impl SecurityPolicy {
/// Classify command risk. Any high-risk segment marks the whole command high.
diff --git a/crates/openhuman-core/src/security/policy/policy_command/classification.rs b/crates/openhuman-core/src/security/policy/policy_command/classification.rs
index 4a102e573a..ac11ba5d1f 100644
--- a/crates/openhuman-core/src/security/policy/policy_command/classification.rs
+++ b/crates/openhuman-core/src/security/policy/policy_command/classification.rs
@@ -2,9 +2,11 @@
//! bucket lists, verb-sensitive VCS / package-manager handling, and the
//! structural "hidden execution" guard for the harness-gated command flow.
-use tinybox_core::shell::scan::{contains_unquoted_background_ampersand, strip_quoted_heredoc_bodies};
use crate::security::policy::policy_command::command_name::is_command_executor;
use crate::security::policy::types::CommandClass;
+use tinybox_core::shell::scan::{
+ contains_unquoted_background_ampersand, strip_quoted_heredoc_bodies,
+};
/// Provably read-only command bases (cross-platform union). A base **not** in
/// this set — and not a recognized network/destructive/executor command, nor a
diff --git a/crates/openhuman-core/src/security/traits.rs b/crates/openhuman-core/src/security/traits.rs
deleted file mode 100644
index c7fcfc011b..0000000000
--- a/crates/openhuman-core/src/security/traits.rs
+++ /dev/null
@@ -1,45 +0,0 @@
-//! Sandbox trait for pluggable OS-level isolation
-
-use std::process::Command;
-
-/// Sandbox backend for OS-level isolation
-pub trait Sandbox: Send + Sync {
- /// Wrap a command with sandbox protection
- fn wrap_command(&self, cmd: &mut Command) -> std::io::Result<()>;
-
- /// Check if this sandbox backend is available on the current platform
- fn is_available(&self) -> bool;
-
- /// Human-readable name of this sandbox backend
- fn name(&self) -> &str;
-
- /// Description of what this sandbox provides
- fn description(&self) -> &str;
-}
-
-/// No-op sandbox (always available, provides no additional isolation)
-#[derive(Debug, Clone, Default)]
-pub struct NoopSandbox;
-
-impl Sandbox for NoopSandbox {
- fn wrap_command(&self, _cmd: &mut Command) -> std::io::Result<()> {
- // Pass through unchanged
- Ok(())
- }
-
- fn is_available(&self) -> bool {
- true
- }
-
- fn name(&self) -> &str {
- "none"
- }
-
- fn description(&self) -> &str {
- "No sandboxing (application-layer security only)"
- }
-}
-
-#[cfg(test)]
-#[path = "traits_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/security/traits_tests.rs b/crates/openhuman-core/src/security/traits_tests.rs
deleted file mode 100644
index c54716ae37..0000000000
--- a/crates/openhuman-core/src/security/traits_tests.rs
+++ /dev/null
@@ -1,34 +0,0 @@
-use super::*;
-
-#[test]
-fn noop_sandbox_name() {
- assert_eq!(NoopSandbox.name(), "none");
-}
-
-#[test]
-fn noop_sandbox_is_always_available() {
- assert!(NoopSandbox.is_available());
-}
-
-#[test]
-fn noop_sandbox_wrap_command_is_noop() {
- let mut cmd = Command::new("echo");
- cmd.arg("test");
- let original_program = cmd.get_program().to_string_lossy().to_string();
- let original_args: Vec<String> = cmd
- .get_args()
- .map(|s| s.to_string_lossy().to_string())
- .collect();
-
- let sandbox = NoopSandbox;
- assert!(sandbox.wrap_command(&mut cmd).is_ok());
-
- // Command should be unchanged
- assert_eq!(cmd.get_program().to_string_lossy(), original_program);
- assert_eq!(
- cmd.get_args()
- .map(|s| s.to_string_lossy().to_string())
- .collect::<Vec<_>>(),
- original_args
- );
-}