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
fix(sandbox): run the macOS desktop sandbox confined to the selected folder
M3gA-Mind15c995f70d0a
diff --git a/crates/openhuman-core/src/sandbox/docker.rs b/crates/openhuman-core/src/sandbox/docker.rsindex 858679038c..4de3987d4e 100644--- a/crates/openhuman-core/src/sandbox/docker.rs+++ b/crates/openhuman-core/src/sandbox/docker.rs@@ -212,6 +212,7 @@ fn docker_handle_for_status(available: bool) -> SandboxBackendHandle {SandboxStatus::Error},backend_id: None,+ isolation: None,}}diff --git a/crates/openhuman-core/src/sandbox/mod.rs b/crates/openhuman-core/src/sandbox/mod.rsindex ab0d107335..f6b817bcec 100644--- a/crates/openhuman-core/src/sandbox/mod.rs+++ b/crates/openhuman-core/src/sandbox/mod.rs@@ -29,5 +29,5 @@ pub use schemas::{};pub use types::{DockerOverrides, ElevatedOp, SandboxBackendHandle, SandboxBackendKind, SandboxExecRequest,- SandboxExecResult, SandboxPolicy, SandboxStatus,+ SandboxExecResult, SandboxIsolation, SandboxPolicy, SandboxStatus,};diff --git a/crates/openhuman-core/src/sandbox/native_jail.rs b/crates/openhuman-core/src/sandbox/native_jail.rsindex 5bf430f13b..7df13d0ec4 100644--- a/crates/openhuman-core/src/sandbox/native_jail.rs+++ b/crates/openhuman-core/src/sandbox/native_jail.rs@@ -5,24 +5,64 @@ use std::{collections::HashMap, ffi::OsString, path::Path, time::Duration};#[cfg(feature = "modules")]use std::collections::BTreeMap;-use super::types::{SandboxExecResult, SandboxPolicy, SandboxStatus};+use super::types::{SandboxExecResult, SandboxIsolation, SandboxPolicy, SandboxStatus};use crate::config::Config;#[cfg(feature = "modules")]use crate::modules::tinybox::{self, contract};-/// Report whether the selected module-owned jail can meet the host's security floor.+/// TinyBox's macOS backend: `sandbox-exec` with a write-deny profile.+#[cfg(any(feature = "modules", test))]+const SEATBELT: &str = "seatbelt";++/// The confinement a native jail gives a command, or `None` when the host must+/// refuse to run it.+///+/// Untrusted code (an explicitly requested Landlock jail, a SaaS tenant) needs+/// kernel process isolation. The local desktop sandbox only has to keep the+/// agent inside the selected folder, which Seatbelt does by denying writes+/// everywhere else, so it is accepted there as folder confinement.+#[cfg(any(feature = "modules", test))]+pub(crate) fn jail_isolation(+ backend: &str,+ available: bool,+ suitable_for_untrusted_code: bool,+ untrusted: bool,+) -> Option<SandboxIsolation> {+ if !available {+ None+ } else if suitable_for_untrusted_code {+ Some(SandboxIsolation::Isolated)+ } else if !untrusted && backend == SEATBELT {+ Some(SandboxIsolation::FolderConfined)+ } else {+ None+ }+}++/// Report what the selected module-owned jail provides for this host.#[cfg(feature = "modules")]-pub(crate) async fn status(config: &Config) -> Result<(String, SandboxStatus), String> {+pub(crate) async fn status(+ config: &Config,+) -> Result<(String, SandboxStatus, Option<SandboxIsolation>), String> {let status = tinybox::jail_status(config).await?;+ let isolation = jail_isolation(+ &status.backend,+ status.available,+ status.suitable_for_untrusted_code,+ crate::core::runtime::is_saas(),+ );Ok((status.backend,- super::ops::local_status_for_jail(status.available, status.suitable_for_untrusted_code),+ super::ops::local_status_for_jail(isolation),+ isolation,))}#[cfg(not(feature = "modules"))]-pub(crate) async fn status(_config: &Config) -> Result<(String, SandboxStatus), String> {+pub(crate) async fn status(+ _config: &Config,+) -> Result<(String, SandboxStatus, Option<SandboxIsolation>), String> {Err("TinyBox module support is disabled; native jail status is unavailable".to_owned())}@@ -32,7 +72,13 @@ pub(crate) async fn require_backend(config: &Config, expected: &str) -> anyhow::let status = tinybox::jail_status(config).await.map_err(|_| anyhow::anyhow!("TinyBox native jail status is unavailable"))?;- if !status.available || !status.suitable_for_untrusted_code || status.backend != expected {+ let isolation = jail_isolation(+ &status.backend,+ status.available,+ status.suitable_for_untrusted_code,+ true,+ );+ if isolation != Some(SandboxIsolation::Isolated) || status.backend != expected {anyhow::bail!("requested native jail backend is unavailable");}Ok(())@@ -108,22 +154,35 @@ async fn execute_owned(let status = tinybox::jail_status(config).await.map_err(|_| anyhow::anyhow!("TinyBox native jail status is unavailable"))?;- if !status.available || !status.suitable_for_untrusted_code {+ let untrusted = explicitly_requested || crate::core::runtime::is_saas();+ let Some(isolation) = jail_isolation(+ &status.backend,+ status.available,+ status.suitable_for_untrusted_code,+ untrusted,+ ) else {anyhow::bail!("TinyBox native jail cannot meet the required isolation floor");- }+ };if explicitly_requested && status.backend != "landlock" {anyhow::bail!("requested Landlock sandbox is unavailable");}+ tracing::debug!(+ backend = %status.backend,+ ?isolation,+ "[sandbox:local] running in the native jail"+ );let mut run =super::shell_exec::NativeShellRun::new(command, working_dir, &policy.state_dir, timeout);run.workspace = policy.workspace_root.clone();run.env = approved_environment(extra_env)?;- run.isolate_network = true;+ // The jail's `allow_net` is what confines the command; keep the resource's+ // declared policy in step with it.+ run.isolate_network = !policy.allow_network;run.meter = meter;// TinyBox adds its own per-call scratch directory to the writable grants and// points TMPDIR, TMP and TEMP at it unless the caller overrides them.- run.jail = Some(jail_request(policy)?);+ run.jail = Some(jail_request(policy, isolation)?);super::shell_exec::run(config, run).await}@@ -147,7 +206,11 @@ fn approved_environment(}#[cfg(feature = "modules")]-fn jail_request(policy: &SandboxPolicy) -> anyhow::Result<contract::NativeJailConfig> {+fn jail_request(+ policy: &SandboxPolicy,+ isolation: SandboxIsolation,+) -> anyhow::Result<contract::NativeJailConfig> {+ let isolated = isolation == SandboxIsolation::Isolated;Ok(contract::NativeJailConfig {read_only: policy.read_only_mounts@@ -161,8 +224,14 @@ fn jail_request(policy: &SandboxPolicy) -> anyhow::Result<contract::NativeJailCo.collect::<anyhow::Result<Vec<_>>>()?,allow_net: policy.allow_network,allow_subprocess: true,- enforcement: contract::JailEnforcement::Enforced,- require_process_isolation: true,+ // Seatbelt enforces its profile best-effort; TinyBox still refuses a+ // constraint it cannot apply at all.+ enforcement: if isolated {+ contract::JailEnforcement::Enforced+ } else {+ contract::JailEnforcement::Declared+ },+ require_process_isolation: isolated,})}diff --git a/crates/openhuman-core/src/sandbox/native_jail_tests.rs b/crates/openhuman-core/src/sandbox/native_jail_tests.rsindex e8112c7478..122569c76f 100644--- a/crates/openhuman-core/src/sandbox/native_jail_tests.rs+++ b/crates/openhuman-core/src/sandbox/native_jail_tests.rs@@ -5,21 +5,56 @@ use super::*;use std::path::PathBuf;#[test]-fn jail_status_is_ready_only_above_the_isolation_floor() {+fn jail_status_is_ready_only_for_an_accepted_jail() {+ use super::super::ops::local_status_for_jail;assert_eq!(- super::super::ops::local_status_for_jail(true, true),+ local_status_for_jail(Some(SandboxIsolation::Isolated)),SandboxStatus::Ready);assert_eq!(- super::super::ops::local_status_for_jail(false, true),- SandboxStatus::Inactive+ local_status_for_jail(Some(SandboxIsolation::FolderConfined)),+ SandboxStatus::Ready);+ assert_eq!(local_status_for_jail(None), SandboxStatus::Inactive);+}++#[test]+fn kernel_isolation_is_accepted_for_every_caller() {+ for untrusted in [false, true] {+ assert_eq!(+ jail_isolation("landlock", true, true, untrusted),+ Some(SandboxIsolation::Isolated)+ );+ }+}++#[test]+fn seatbelt_confines_the_local_desktop_sandbox_to_its_folder() {assert_eq!(- super::super::ops::local_status_for_jail(true, false),- SandboxStatus::Inactive+ jail_isolation("seatbelt", true, false, false),+ Some(SandboxIsolation::FolderConfined));}+#[test]+fn seatbelt_is_refused_where_untrusted_code_needs_isolation() {+ // An explicitly requested Landlock jail, or a SaaS tenant.+ assert_eq!(jail_isolation("seatbelt", true, false, true), None);+}++#[test]+fn an_unavailable_or_unconfining_jail_is_refused() {+ for untrusted in [false, true] {+ // Missing launcher: nothing would be confined.+ assert_eq!(jail_isolation("seatbelt", false, false, untrusted), None);+ assert_eq!(jail_isolation("landlock", false, true, untrusted), None);+ // The no-op backend confines nothing.+ assert_eq!(jail_isolation("noop", true, false, untrusted), None);+ // A Landlock host below the kernel floor is not folder confinement.+ assert_eq!(jail_isolation("landlock", true, false, untrusted), None);+ }+}+#[cfg(feature = "modules")]#[test]fn native_jail_request_preserves_grants_and_requires_enforcement() -> anyhow::Result<()> {@@ -36,7 +71,7 @@ fn native_jail_request_preserves_grants_and_requires_enforcement() -> anyhow::Reenv_passthrough: Vec::new(),docker_overrides: None,};- let request = jail_request(&policy)?;+ let request = jail_request(&policy, SandboxIsolation::Isolated)?;assert_eq!(request.read_only, [readonly.path().to_str().unwrap()]);// TinyBox appends its own per-call scratch directory to the writable grants.@@ -45,6 +80,16 @@ fn native_jail_request_preserves_grants_and_requires_enforcement() -> anyhow::Reassert!(request.allow_subprocess);assert_eq!(request.enforcement, contract::JailEnforcement::Enforced);assert!(request.require_process_isolation);++ // Folder confinement keeps the grants and the network decision, and asks+ // TinyBox for what Seatbelt can give: declared constraints, no process+ // isolation.+ let confined = jail_request(&policy, SandboxIsolation::FolderConfined)?;+ assert_eq!(confined.read_only, request.read_only);+ assert_eq!(confined.read_write, request.read_write);+ assert!(!confined.allow_net);+ assert_eq!(confined.enforcement, contract::JailEnforcement::Declared);+ assert!(!confined.require_process_isolation);Ok(())}diff --git a/crates/openhuman-core/src/sandbox/ops.rs b/crates/openhuman-core/src/sandbox/ops.rsindex 33cb747e0a..8a86cb58af 100644--- a/crates/openhuman-core/src/sandbox/ops.rs+++ b/crates/openhuman-core/src/sandbox/ops.rs@@ -218,10 +218,9 @@ pub fn resolve_sandbox_policy(/// passes unnoticed. That is exactly how the original defect survived.#[cfg(any(feature = "modules", test))]pub(crate) fn local_status_for_jail(- available: bool,- suitable_for_untrusted_code: bool,+ isolation: Option<super::types::SandboxIsolation>,) -> SandboxStatus {- if available && suitable_for_untrusted_code {+ if isolation.is_some() {SandboxStatus::Ready} else {SandboxStatus::Inactive@@ -239,6 +238,7 @@ pub async fn create_sandbox_backend(kind: policy.backend,status: SandboxStatus::Error,backend_id: None,+ isolation: None,});}let config = match ctx.load_config().await {@@ -263,9 +263,10 @@ pub async fn create_sandbox_backend_with_config(kind: SandboxBackendKind::None,status: SandboxStatus::Ready,backend_id: None,+ isolation: None,}),SandboxBackendKind::Local => {- let (backend_name, status) = super::native_jail::status(config).await?;+ let (backend_name, status, isolation) = super::native_jail::status(config).await?;if status == SandboxStatus::Inactive {tracing::warn!(backend = backend_name,@@ -276,6 +277,7 @@ pub async fn create_sandbox_backend_with_config(kind: SandboxBackendKind::Local,status,backend_id: Some(backend_name),+ isolation,})}SandboxBackendKind::Docker => docker::docker_backend_handle(config).await,@@ -287,6 +289,7 @@ fn docker_error_handle() -> SandboxBackendHandle {kind: SandboxBackendKind::Docker,status: SandboxStatus::Error,backend_id: None,+ isolation: None,}}diff --git a/crates/openhuman-core/src/sandbox/schemas.rs b/crates/openhuman-core/src/sandbox/schemas.rsindex ab82bed476..4a62f20daa 100644--- a/crates/openhuman-core/src/sandbox/schemas.rs+++ b/crates/openhuman-core/src/sandbox/schemas.rs@@ -78,7 +78,7 @@ pub fn schemas(function: &str) -> ControllerSchema {outputs: vec![FieldSchema {name: "status",ty: TypeSchema::Json,- comment: "Backend handle with kind, status, and backend_id.",+ comment: "Backend handle with kind, status, backend_id, and (local) isolation.",required: true,}],},diff --git a/crates/openhuman-core/src/sandbox/types.rs b/crates/openhuman-core/src/sandbox/types.rsindex b973622926..4c8d167a5c 100644--- a/crates/openhuman-core/src/sandbox/types.rs+++ b/crates/openhuman-core/src/sandbox/types.rs@@ -93,6 +93,20 @@ pub struct SandboxBackendHandle {pub status: SandboxStatus,/// Container ID for Docker backends; jail label for local.pub backend_id: Option<String>,+ /// How strongly a ready local jail confines commands; `None` otherwise.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub isolation: Option<SandboxIsolation>,+}++/// The confinement a local native jail actually provides.+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]+#[serde(rename_all = "snake_case")]+pub enum SandboxIsolation {+ /// Kernel (or stronger) process isolation: fit for untrusted code.+ Isolated,+ /// Writes confined to the selected folder (macOS Seatbelt); no process+ /// isolation.+ FolderConfined,}/// Health/lifecycle status of a sandbox backend.