The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(shell): gate shell tool behind boot guard
Steven Enamakele8252f12f873
diff --git a/crates/openhuman-core/src/core/runtime/boot_guard.rs b/crates/openhuman-core/src/core/runtime/boot_guard.rsindex 78aea0848f..589a83dd84 100644--- a/crates/openhuman-core/src/core/runtime/boot_guard.rs+++ b/crates/openhuman-core/src/core/runtime/boot_guard.rs@@ -285,14 +285,14 @@ fn sandbox_problems(inputs: &BootInputs<'_>) -> Vec<String> {if !inputs.sandbox_available {problems.push("host_shell is allowlisted but Docker is not available".to_string());}- if sandbox.network.trim() == "host" {+ if crate::user_agents::tools::is_host_network(&sandbox.network) {problems.push("network `host` defeats the sandbox".to_string());}if sandbox.image.trim().is_empty() {problems.push("no image is set".to_string());}- if sandbox.memory_limit_mb == 0 || sandbox.cpu_limit.is_nan() || sandbox.cpu_limit <= 0.0 {- problems.push("memory_limit_mb and cpu_limit must be positive".to_string());+ if sandbox.memory_limit_mb == 0 || !sandbox.cpu_limit.is_finite() || sandbox.cpu_limit <= 0.0 {+ problems.push("memory_limit_mb and cpu_limit must be positive and finite".to_string());}problems}diff --git a/crates/openhuman-core/src/tools/impl/system/shell.rs b/crates/openhuman-core/src/tools/impl/system/shell.rsindex 9072637b40..f3e42c92ce 100644--- a/crates/openhuman-core/src/tools/impl/system/shell.rs+++ b/crates/openhuman-core/src/tools/impl/system/shell.rs@@ -376,8 +376,9 @@ impl ShellTool {}Err(why) => {tracing::warn!(reason = %why, "[shell] SaaS sandbox refused the command");+ // Nothing ran: report it as not allowed.(- true,+ false,ToolResult::error(format!("Sandbox unavailable: {why}")),)}diff --git a/crates/openhuman-core/src/user_agents/tools.rs b/crates/openhuman-core/src/user_agents/tools.rsindex cc4503b54d..c3f69af874 100644--- a/crates/openhuman-core/src/user_agents/tools.rs+++ b/crates/openhuman-core/src/user_agents/tools.rs@@ -192,6 +192,12 @@ pub fn gate_verdict(tool: &str) -> Result<(), String> {verdict}+/// Whether a Docker network name is the host network (Docker matches it+/// case-insensitively).+pub fn is_host_network(network: &str) -> bool {+ network.trim().eq_ignore_ascii_case("host")+}+/// The container policy for a user's shell command. `action_dir` must be a/// user's `sandbox/` directory under `<root>/agents/`, or the command is/// refused.@@ -215,12 +221,28 @@ pub fn sandbox_policy_with(action_dir.display()));}- if config.network.trim() == "host" {+ // Resolve symlinks: the directory mounted read-write must really be this+ // agent's sandbox, not a link from it to somewhere else on the host.+ let resolved = action_dir+ .canonicalize()+ .map_err(|e| format!("{}: {e}", action_dir.display()))?;+ let expected = agents+ .canonicalize()+ .map_err(|e| format!("{}: {e}", agents.display()))?+ .join(agent_dir.and_then(Path::file_name).unwrap_or_default())+ .join("sandbox");+ if resolved != expected {+ return Err(format!(+ "{} resolves outside the user's sandbox",+ action_dir.display()+ ));+ }+ if is_host_network(&config.network) {return Err("the sandbox cannot use the host network".to_string());}Ok(SandboxPolicy {backend: SandboxBackendKind::Docker,- workspace_root: action_dir.to_path_buf(),+ workspace_root: resolved,state_dir: state_dir.to_path_buf(),read_only_mounts: Vec::new(),read_write_mounts: Vec::new(),diff --git a/crates/openhuman-core/src/user_agents/tools_tests.rs b/crates/openhuman-core/src/user_agents/tools_tests.rsindex 48f549c2a1..e83fd815fa 100644--- a/crates/openhuman-core/src/user_agents/tools_tests.rs+++ b/crates/openhuman-core/src/user_agents/tools_tests.rs@@ -85,14 +85,27 @@ fn root() -> PathBuf {PathBuf::from("/srv/oh")}+const AGENT: &str = "u-0123456789abcdef0123456789abcdef";++/// A SaaS root on disk with one agent's `sandbox/` and `workspace/`.+fn on_disk() -> (tempfile::TempDir, PathBuf) {+ let tmp = tempfile::tempdir().unwrap();+ let root = tmp.path().join("oh");+ for dir in ["sandbox", "workspace"] {+ std::fs::create_dir_all(root.join("agents").join(AGENT).join(dir)).unwrap();+ }+ (tmp, root)+}+#[test]fn the_sandbox_policy_is_a_locked_down_container() {- let action = root().join("agents/u-0123456789abcdef0123456789abcdef/sandbox");- let state = root().join("agents/u-0123456789abcdef0123456789abcdef/workspace");+ let (_tmp, root) = on_disk();+ let action = root.join("agents").join(AGENT).join("sandbox");+ let state = root.join("agents").join(AGENT).join("workspace");let policy =- sandbox_policy_with(&root(), &SaasSandboxConfig::default(), &action, &state).unwrap();+ sandbox_policy_with(&root, &SaasSandboxConfig::default(), &action, &state).unwrap();assert_eq!(policy.backend, SandboxBackendKind::Docker);- assert_eq!(policy.workspace_root, action);+ assert_eq!(policy.workspace_root, action.canonicalize().unwrap());assert!(!policy.allow_network);assert!(policy.env_passthrough.is_empty());assert!(policy.read_only_mounts.is_empty() && policy.read_write_mounts.is_empty());@@ -107,8 +120,9 @@ fn a_named_network_allows_egress() {network: "egress".into(),..SaasSandboxConfig::default()};- let action = root().join("agents/u-0123456789abcdef0123456789abcdef/sandbox");- let policy = sandbox_policy_with(&root(), &config, &action, &action).unwrap();+ let (_tmp, root) = on_disk();+ let action = root.join("agents").join(AGENT).join("sandbox");+ let policy = sandbox_policy_with(&root, &config, &action, &action).unwrap();assert!(policy.allow_network);}@@ -134,11 +148,37 @@ fn the_sandbox_refuses_anything_but_a_user_sandbox() {}#[test]-fn the_host_network_is_refused() {- let config = SaasSandboxConfig {- network: "host".into(),- ..SaasSandboxConfig::default()- };- let action = root().join("agents/u-0123456789abcdef0123456789abcdef/sandbox");- assert!(sandbox_policy_with(&root(), &config, &action, &action).is_err());+fn the_host_network_is_refused_in_any_case() {+ let (_tmp, root) = on_disk();+ let action = root.join("agents").join(AGENT).join("sandbox");+ for network in ["host", "HOST", " Host "] {+ let config = SaasSandboxConfig {+ network: network.into(),+ ..SaasSandboxConfig::default()+ };+ assert!(+ sandbox_policy_with(&root, &config, &action, &action).is_err(),+ "{network}"+ );+ }+}++#[cfg(unix)]+#[test]+fn a_symlinked_sandbox_is_refused() {+ let (tmp, root) = on_disk();+ let elsewhere = tmp.path().join("elsewhere");+ std::fs::create_dir_all(&elsewhere).unwrap();+ let sandbox = root.join("agents").join(AGENT).join("sandbox");+ std::fs::remove_dir(&sandbox).unwrap();+ std::os::unix::fs::symlink(&elsewhere, &sandbox).unwrap();+ let refused =+ sandbox_policy_with(&root, &SaasSandboxConfig::default(), &sandbox, &sandbox).unwrap_err();+ assert!(refused.contains("outside"), "{refused}");+}++#[test]+fn a_missing_sandbox_is_refused() {+ let action = root().join("agents").join(AGENT).join("sandbox");+ assert!(sandbox_policy_with(&root(), &SaasSandboxConfig::default(), &action, &action).is_err());}