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): restore native jail enforcement for tinybox
Steven Enamakel49f3ad0a2f6d
diff --git a/crates/openhuman-core/src/modules/tinybox.rs b/crates/openhuman-core/src/modules/tinybox.rsindex 57df9de7b2..95cef98071 100644--- a/crates/openhuman-core/src/modules/tinybox.rs+++ b/crates/openhuman-core/src/modules/tinybox.rs@@ -52,6 +52,8 @@ const RUN_DOCKER: &str = contract::METHODS[27];const DOCKER_STATUS: &str = contract::METHODS[28];const CLEANUP_DOCKER: &str = contract::METHODS[29];const RUN_DOCKER_WITHOUT_WORKSPACE: &str = contract::METHODS[30];+const SELECT_SHELL: &str = contract::names::SELECT_SHELL;+const START_SHELL_EXEC: &str = contract::names::START_SHELL_EXEC;const DOCKER_CALL_GRACE: Duration = Duration::from_secs(5);#[cfg(test)]@@ -165,6 +167,28 @@ pub async fn start_jailed_exec(call(config, START_JAILED_EXEC, (request, jail), true).await}+/// Ask TinyBox which shell it would spawn for a command on its machine.+///+/// The reply is discovery only: the host never spawns the plan itself, it+/// executes through [`start_shell_exec`].+pub async fn select_shell(+ config: &Config,+ request: contract::SelectShellRequest,+) -> Result<contract::ShellInvocation, String> {+ call(config, SELECT_SHELL, (request,), false).await+}++/// Start a local shell under module-owned supervision and output replay.+///+/// The caller has already authorized the command; the module owns shell+/// selection, the safe child environment and cleanup.+pub async fn start_shell_exec(+ config: &Config,+ request: contract::ShellExecRequest,+) -> Result<contract::ProcessRef, String> {+ call(config, START_SHELL_EXEC, (request,), true).await+}+/// Run one bounded Docker-isolated command through TinyBox.////// The caller applies authorization and Docker policy before sending thisdiff --git a/crates/openhuman-core/src/modules/tinybox_tests.rs b/crates/openhuman-core/src/modules/tinybox_tests.rsindex 72f3c825fa..feb252e903 100644--- a/crates/openhuman-core/src/modules/tinybox_tests.rs+++ b/crates/openhuman-core/src/modules/tinybox_tests.rs@@ -474,6 +474,25 @@ fn every_host_operation_is_a_member_of_the_canonical_contract() {RUN_DOCKER_WITHOUT_WORKSPACE,];assert_eq!(methods, contract::METHODS[..methods.len()]);+ assert!(contract::METHODS.contains(&SELECT_SHELL));+ assert!(contract::METHODS.contains(&START_SHELL_EXEC));+}++#[tokio::test]+async fn shell_selection_and_start_use_contract_members_with_typed_requests() {+ let (_service, client, calls) = mock_client().await;+ let request = contract::SelectShellRequest {+ command: "echo hi".to_owned(),+ preserve_pipeline_status: false,+ runtime_path: Some("/opt/bin".to_owned()),+ python_utf8: true,+ };+ let _: () = call_with_client(&client, SELECT_SHELL, (request.clone(),), false)+ .await+ .expect("select shell call");+ let log = calls.lock().expect("call log lock");+ assert_eq!(log[1].0, "SelectShell");+ assert_eq!(log[1].1, json!([request]));}#[tokio::test]diff --git a/crates/openhuman-core/src/sandbox/native_jail.rs b/crates/openhuman-core/src/sandbox/native_jail.rsindex 46c76f6455..70a67a2f84 100644--- a/crates/openhuman-core/src/sandbox/native_jail.rs+++ b/crates/openhuman-core/src/sandbox/native_jail.rs@@ -6,7 +6,7 @@ use std::{collections::HashMap, ffi::OsString, path::Path, time::Duration};use std::{collections::BTreeMap, ffi::OsStr};use super::types::{SandboxExecResult, SandboxPolicy, SandboxStatus};-use crate::{agent::platform_shell, config::Config};+use crate::config::Config;#[cfg(feature = "modules")]use crate::modules::tinybox::{self, contract};@@ -148,18 +148,22 @@ async fn execute_passthrough_owned(.await.map_err(|_| anyhow::anyhow!("TinyBox could not create a command resource"))?;- let request = shell_request(&resource, command, working_dir, BTreeMap::new(), true)?;let process = tinybox::reserve(config, contract::ReserveRequest::Process(resource.clone())).await.map_err(|_| anyhow::anyhow!("TinyBox could not reserve a command process"))?;- let process = tinybox::start_exec(- config,- contract::SpawnRequest {- process,- command: request,- },- )- .await+ let request = shell_exec_request(+ process,+ &resource,+ command,+ working_dir,+ BTreeMap::new(),+ &config.workspace_dir,+ timeout,+ true,+ None,+ )?;+ let process = tinybox::start_shell_exec(config, request)+ .await.map_err(|_| anyhow::anyhow!("TinyBox could not start a command process"))?;collect_process(config, process, timeout).await}@@ -219,20 +223,23 @@ async fn execute_owned("scratch",)?;let (env, read_write) = execution_environment(policy, extra_env, &scratch.path)?;- let exec = shell_request(&resource, command, working_dir, env, false)?;let jail = jail_request(policy, read_write)?;let process = tinybox::reserve(config, contract::ReserveRequest::Process(resource.clone())).await.map_err(|_| anyhow::anyhow!("TinyBox could not reserve a native jail process"))?;- let process = tinybox::start_jailed_exec(- config,- contract::SpawnRequest {- process,- command: exec,- },- jail,- )- .await+ let exec = shell_exec_request(+ process,+ &resource,+ command,+ working_dir,+ env,+ &policy.state_dir,+ timeout,+ false,+ Some(jail),+ )?;+ let process = tinybox::start_shell_exec(config, exec)+ .await.map_err(|_| anyhow::anyhow!("TinyBox could not start the native jailed process"))?;collect_process(config, process, timeout).await@@ -293,40 +300,41 @@ fn execution_environment(Ok((env, read_write))}+/// Map a host-authorized command onto TinyBox's `StartShellExec` request.+///+/// TinyBox selects the shell (cmd or bash with pipefail), builds the safe child+/// environment and owns the scratch directory; the host supplies only the+/// command, working directory, approved environment overrides and policy.#[cfg(feature = "modules")]-fn shell_request(+#[allow(clippy::too_many_arguments)]+fn shell_exec_request(+ process: contract::ResourceId,resource: &contract::ResourceId,command: &str,working_dir: &Path,- env: BTreeMap<String, String>,- preserve_pipe_status: bool,-) -> anyhow::Result<contract::ExecRequest> {- let shell = if preserve_pipe_status {- platform_shell::build_std_command_preserving_pipe_status(command)- } else {- platform_shell::build_std_command(command)- };- let program = shell- .get_program()- .to_str()- .ok_or_else(|| anyhow::anyhow!("platform shell name is not UTF-8"))?;- let mut argv = vec![program.to_owned()];- argv.extend(- shell- .get_args()- .map(|arg| {- arg.to_str()- .map(str::to_owned)- .ok_or_else(|| anyhow::anyhow!("platform shell argument is not UTF-8"))- })- .collect::<anyhow::Result<Vec<_>>>()?,- );- Ok(contract::ExecRequest {+ extra_env: BTreeMap<String, String>,+ state_dir: &Path,+ timeout: Duration,+ preserve_pipeline_status: bool,+ jail: Option<contract::NativeJailConfig>,+) -> anyhow::Result<contract::ShellExecRequest> {+ Ok(contract::ShellExecRequest {+ process,resource: resource.clone(),- argv,+ shell: contract::SelectShellRequest {+ command: command.to_owned(),+ preserve_pipeline_status,+ runtime_path: None,+ python_utf8: false,+ },cwd: Some(path_string(working_dir, "sandbox working directory")?),- env,+ extra_env,+ state_dir: path_string(state_dir, "sandbox state directory")?,+ timeout_ms: u64::try_from(timeout.as_millis())+ .unwrap_or(u64::MAX)+ .max(1),stdin: None,+ jail,})}diff --git a/crates/openhuman-core/src/sandbox/native_jail_tests.rs b/crates/openhuman-core/src/sandbox/native_jail_tests.rsindex 01315953f6..b62b5e394b 100644--- a/crates/openhuman-core/src/sandbox/native_jail_tests.rs+++ b/crates/openhuman-core/src/sandbox/native_jail_tests.rs@@ -22,31 +22,36 @@ fn jail_status_is_ready_only_above_the_isolation_floor() {#[cfg(feature = "modules")]#[test]-fn shell_request_uses_the_platform_shell_and_caller_known_process_resource() -> anyhow::Result<()> {+fn shell_exec_request_delegates_shell_selection_to_the_module() -> anyhow::Result<()> {let resource = contract::ResourceId("known-resource".to_owned());+ let process = contract::ResourceId("known-process".to_owned());let cwd = tempfile::tempdir()?;+ let state = tempfile::tempdir()?;let env = BTreeMap::from([("LANG".to_owned(), "C".to_owned())]);- let request = shell_request(+ let request = shell_exec_request(+ process.clone(),&resource,"printf 'one two'",cwd.path(),env.clone(),- false,+ state.path(),+ Duration::from_secs(7),+ true,+ None,)?;- let expected = platform_shell::build_std_command("printf 'one two'");- let expected_argv = std::iter::once(expected.get_program().to_str().unwrap().to_owned())- .chain(- expected- .get_args()- .map(|arg| arg.to_str().unwrap().to_owned()),- )- .collect::<Vec<_>>();+ assert_eq!(request.process, process);assert_eq!(request.resource, resource);- assert_eq!(request.argv, expected_argv);+ assert_eq!(request.shell.command, "printf 'one two'");+ assert!(request.shell.preserve_pipeline_status);+ assert_eq!(request.shell.runtime_path, None);+ assert!(!request.shell.python_utf8);assert_eq!(request.cwd.as_deref(), cwd.path().to_str());- assert_eq!(request.env, env);+ assert_eq!(request.extra_env, env);+ assert_eq!(request.state_dir, state.path().to_str().unwrap());+ assert_eq!(request.timeout_ms, 7_000);assert_eq!(request.stdin, None);+ assert!(request.jail.is_none());Ok(())}