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): route docker runtime commands through tinybox module
Steven Enamakel2cc336e0dffb
diff --git a/crates/openhuman-core/src/agent/host_runtime_tests.rs b/crates/openhuman-core/src/agent/host_runtime_tests.rsindex 455fabaf72..66e3b58563 100644--- a/crates/openhuman-core/src/agent/host_runtime_tests.rs+++ b/crates/openhuman-core/src/agent/host_runtime_tests.rs@@ -41,6 +41,7 @@ fn native_runtime_reports_capabilities_and_shell_command() {}#[test]+#[cfg(feature = "modules")]fn docker_runtime_builds_expected_flags() {let runtime = DockerRuntime::new(DockerRuntimeConfig {image: "alpine:3.20".into(),@@ -59,22 +60,42 @@ fn docker_runtime_builds_expected_flags() {assert!(runtime.storage_path().ends_with("openhuman/runtime/docker"));let tempdir = tempfile::tempdir().unwrap();- let command = runtime.build_shell_command("pwd", tempdir.path()).unwrap();- let args: Vec<String> = command- .as_std()- .get_args()- .map(|arg| arg.to_string_lossy().into_owned())- .collect();- let joined = args.join(" ");- assert!(joined.contains("run --rm"));- assert!(joined.contains("--network host"));- assert!(joined.contains("-m 512m"));- assert!(joined.contains("--cpus 1.5"));- assert!(joined.contains("--read-only"));- assert!(joined.contains(":/workspace"));- assert!(joined.contains("-w /workspace"));- assert!(joined.contains("alpine:3.20"));- assert!(joined.ends_with("sh -lc pwd"));+ let (request, mount_workspace) = runtime+ .build_docker_request("pwd", tempdir.path())+ .expect("Docker runtime should use the TinyBox request path");+ assert!(mount_workspace);+ assert_eq!(+ request.workspace,+ tempdir.path().canonicalize().unwrap().to_string_lossy()+ );+ assert_eq!(request.image.as_deref(), Some("alpine:3.20"));+ assert_eq!(request.network.as_deref(), Some("host"));+ assert_eq!(request.memory_limit_mb, Some(512));+ assert_eq!(request.cpus, Some(1.5));+ assert_eq!(request.read_only_rootfs, Some(true));+ assert!(request.read_only_mounts.is_empty());+ assert!(request.extra_cap_drops.is_empty());+ assert_eq!(request.command, "pwd");+ assert!(request.login_shell, "legacy DockerRuntime used sh -lc");+ assert_eq!(request.label.as_deref(), Some("openhuman.runtime=true"));+ assert!(runtime.build_shell_command("pwd", tempdir.path()).is_err());+}++#[cfg(feature = "modules")]+#[test]+fn docker_runtime_without_workspace_uses_unmounted_module_request() {+ let runtime = DockerRuntime::new(DockerRuntimeConfig {+ mount_workspace: false,+ ..DockerRuntimeConfig::default()+ });+ let tempdir = tempfile::tempdir().unwrap();+ let (request, mount_workspace) = runtime+ .build_docker_request("printf ok", tempdir.path())+ .unwrap();+ assert!(!mount_workspace);+ assert!(request.workspace.is_empty());+ assert_eq!(request.command, "printf ok");+ assert!(request.login_shell);}#[test]diff --git a/crates/openhuman-core/src/cron/mod.rs b/crates/openhuman-core/src/cron/mod.rsindex 130b7dc20f..521ffa4c75 100644--- a/crates/openhuman-core/src/cron/mod.rs+++ b/crates/openhuman-core/src/cron/mod.rs@@ -27,9 +27,9 @@ pub mod tools;pub mod scheduler;pub use ops as rpc;-pub use ops::{add_once, add_once_at, parse_human_delay, pause_job, resume_job};#[cfg(test)]pub use ops::update_cron_job;+pub use ops::{add_once, add_once_at, parse_human_delay, pause_job, resume_job};// Pure scheduling logic (schedule model, next-run computation) lives in// `tinyflows-schedule`; the host keeps the scheduler runtime, store, config// and RPC, and re-exports the upstream names so `cron::Schedule` etc. hold.diff --git a/crates/openhuman-core/src/cron/schemas.rs b/crates/openhuman-core/src/cron/schemas.rsindex 7ae80f6f14..88a04a2329 100644--- a/crates/openhuman-core/src/cron/schemas.rs+++ b/crates/openhuman-core/src/cron/schemas.rs@@ -357,9 +357,7 @@ fn handle_add(params: Map<String, Value>) -> ControllerFuture {&config.action_dir,);crate::cron::scheduler::shell_job::authorize_shell_command(- &config,- &security,- &cmd,+ &config, &security, &cmd,).await?;crate::cron::store::add_shell_job(&config, name, schedule, &cmd)diff --git a/crates/openhuman-core/src/modules/tinybox_tests.rs b/crates/openhuman-core/src/modules/tinybox_tests.rsindex f9679541b6..de9d9a7f19 100644--- a/crates/openhuman-core/src/modules/tinybox_tests.rs+++ b/crates/openhuman-core/src/modules/tinybox_tests.rs@@ -398,14 +398,10 @@ async fn no_workspace_docker_call_uses_its_typed_member_and_request() {label: Some("openhuman.runtime=true".to_owned()),timeout_ms: 12_000,};- let output: contract::DockerRunOutput = call_with_client(- &client,- RUN_DOCKER_WITHOUT_WORKSPACE,- (request,),- false,- )- .await- .expect("the adapter decodes the typed no-workspace result");+ let output: contract::DockerRunOutput =+ call_with_client(&client, RUN_DOCKER_WITHOUT_WORKSPACE, (request,), false)+ .await+ .expect("the adapter decodes the typed no-workspace result");assert_eq!(output.exit_code, 0);let calls = calls.lock().expect("recorded TinyBox calls");diff --git a/crates/openhuman-core/src/sandbox/docker_exec_tests.rs b/crates/openhuman-core/src/sandbox/docker_exec_tests.rsindex f631eec3cb..45c68232af 100644--- a/crates/openhuman-core/src/sandbox/docker_exec_tests.rs+++ b/crates/openhuman-core/src/sandbox/docker_exec_tests.rs@@ -113,11 +113,9 @@ fn module_request_rounds_small_timeouts_up_and_rejects_unbounded_timeouts() {exec_request.timeout = Duration::from_millis(MAX_DOCKER_RUN_TIMEOUT_MS + 1);let error = build_docker_request(&policy(temp.path()), &exec_request).expect_err("unbounded request must not bypass the contract limit");- assert!(- error- .to_string()- .contains("timeout exceeds the supported limit")- );+ assert!(error+ .to_string()+ .contains("timeout exceeds the supported limit"));}#[cfg(all(feature = "modules", unix))]diff --git a/crates/openhuman-core/src/sandbox/ops_host_grants_tests.rs b/crates/openhuman-core/src/sandbox/ops_host_grants_tests.rsindex fda29b9751..3484e09daa 100644--- a/crates/openhuman-core/src/sandbox/ops_host_grants_tests.rs+++ b/crates/openhuman-core/src/sandbox/ops_host_grants_tests.rs@@ -7,12 +7,10 @@ fn saas_local_grants_never_consult_the_operator_home() {panic!("a tenant must not read the operator's home")});assert!(grants.read_write.is_empty());- assert!(- grants- .read_only- .iter()- .all(|path| path.starts_with("/usr/local") || path.starts_with("/opt"))- );+ assert!(grants+ .read_only+ .iter()+ .all(|path| path.starts_with("/usr/local") || path.starts_with("/opt")));}#[test]@@ -21,9 +19,7 @@ fn single_user_local_grants_keep_the_configured_toolchain_home() {std::fs::create_dir(home.path().join(".rustup")).unwrap();let runtime = RuntimeConfig::default();let grants = local_jail_grants_with_home(&runtime, false, || Some(home.path().to_path_buf()));- assert!(- grants- .read_only- .contains(&home.path().join(".rustup").canonicalize().unwrap())- );+ assert!(grants+ .read_only+ .contains(&home.path().join(".rustup").canonicalize().unwrap()));}diff --git a/crates/openhuman-core/src/sandbox/schemas_tests.rs b/crates/openhuman-core/src/sandbox/schemas_tests.rsindex 76021a5995..a9476afba8 100644--- a/crates/openhuman-core/src/sandbox/schemas_tests.rs+++ b/crates/openhuman-core/src/sandbox/schemas_tests.rs@@ -1,6 +1,6 @@use super::*;-use crate::core::runtime::DomainSet;use crate::core::runtime::context::CoreContext;+use crate::core::runtime::DomainSet;/// Scope a `Config` onto the embedder-config seam that `load_config_with_timeout()`/// prefers, so a handler reads it instead of doing live disk I/O againstdiff --git a/crates/openhuman-core/src/security/policy/policy_paths_and_risk_tests.rs b/crates/openhuman-core/src/security/policy/policy_paths_and_risk_tests.rsindex 115bb05472..a8306429bf 100644--- a/crates/openhuman-core/src/security/policy/policy_paths_and_risk_tests.rs+++ b/crates/openhuman-core/src/security/policy/policy_paths_and_risk_tests.rs@@ -210,7 +210,10 @@ fn tinybox_fact_allowlist_treats_heredoc_as_data_and_unknown_commands_as_writes(literal_words: vec!["unrecognized-tool".into(), "--flag".into()],};assert!(!policy.is_command_allowed_analysis(&unknown_write));- assert_eq!(policy.check_gated_command_analysis(&unknown_write), Ok(CommandClass::Write));+ assert_eq!(+ policy.check_gated_command_analysis(&unknown_write),+ Ok(CommandClass::Write)+ );}#[test]diff --git a/crates/openhuman-core/src/tools/impl/system/shell.rs b/crates/openhuman-core/src/tools/impl/system/shell.rsindex 110b8508a1..3a2955d6f0 100644--- a/crates/openhuman-core/src/tools/impl/system/shell.rs+++ b/crates/openhuman-core/src/tools/impl/system/shell.rs@@ -37,6 +37,47 @@ fn command_failure(code: Option<i32>, stdout: &str, stderr: &str) -> ToolResultfailure}+#[cfg(feature = "modules")]+fn docker_module_result(+ output: crate::modules::tinybox::contract::DockerRunOutput,+ explicit_timeout: Option<Duration>,+) -> ToolResult {+ let mut stdout = output.stdout;+ let mut stderr = output.stderr;+ if stdout.len() > MAX_OUTPUT_BYTES {+ stdout.truncate(crate::util::floor_char_boundary(&stdout, MAX_OUTPUT_BYTES));+ stdout.push_str("\n... [output truncated at 1MB]");+ }+ if stderr.len() > MAX_OUTPUT_BYTES {+ stderr.truncate(crate::util::floor_char_boundary(&stderr, MAX_OUTPUT_BYTES));+ stderr.push_str("\n... [stderr truncated at 1MB]");+ }++ if output.timed_out {+ let secs = explicit_timeout+ .map(|duration| duration.as_secs())+ .unwrap_or(0);+ let mut message = tool_timeout_message(secs);+ if !stdout.is_empty() {+ message.push_str("\n[stdout]\n");+ message.push_str(&stdout);+ }+ if !stderr.is_empty() {+ message.push_str("\n[stderr]\n");+ message.push_str(&stderr);+ }+ ToolResult::error(message)+ } else if output.exit_code == 0 {+ if stderr.is_empty() {+ ToolResult::success(stdout)+ } else {+ ToolResult::success(format!("{stdout}\n[stderr]\n{stderr}"))+ }+ } else {+ command_failure(Some(output.exit_code), &stdout, &stderr)+ }+}+/// Shell command execution tool with sandboxingpub struct ShellTool {security: Arc<SecurityPolicy>,@@ -418,6 +459,87 @@ impl ShellTool {// Clear the environment to prevent leaking API keys and other secrets// (CWE-200), then re-add only safe, functional variables.let action_dir = self.effective_action_dir_for_context(context);+ #[cfg(feature = "modules")]+ if let Some((mut request, mount_workspace)) =+ self.runtime.build_docker_request(command, &action_dir)+ {+ let Some(config) = self.analysis_config.as_deref() else {+ return (+ false,+ ToolResult::error("Docker module execution is unavailable."),+ );+ };++ let explicit_timeout = self.explicit_timeout(requested_timeout);+ if let Some(timeout) = explicit_timeout {+ let timeout_ms = timeout+ .as_nanos()+ .saturating_add(999_999)+ .checked_div(1_000_000)+ .unwrap_or(0)+ .max(1);+ let Ok(timeout_ms) = u64::try_from(timeout_ms) else {+ return (+ false,+ ToolResult::error("Docker timeout exceeds the supported limit."),+ );+ };+ if timeout_ms > crate::modules::tinybox::contract::MAX_DOCKER_RUN_TIMEOUT_MS {+ return (+ false,+ ToolResult::error("Docker timeout exceeds the supported limit."),+ );+ }+ request.timeout_ms = timeout_ms;+ }++ let mut env = std::collections::BTreeMap::new();+ for (name, value) in shell_child_env(crate::tools::timeout::CommandEnvironment::var_os)+ {+ let Ok(value) = value.into_string() else {+ return (+ false,+ ToolResult::error("Docker environment contains a non-UTF-8 value."),+ );+ };+ env.insert(name.to_owned(), value);+ }+ for (name, value) in tinytools_std::filesystem::shell_git_env() {+ let (Ok(name), Ok(value)) = (name.into_string(), value.into_string()) else {+ return (+ false,+ ToolResult::error("Docker environment contains a non-UTF-8 value."),+ );+ };+ env.insert(name, value);+ }++ let scratch_dir = crate::security::openhuman_scratch_dir();+ if scratch_dir.is_dir() {+ let Some(scratch_dir) = scratch_dir.to_str() else {+ return (+ false,+ ToolResult::error("Docker scratch directory is not valid UTF-8."),+ );+ };+ for name in ["TMPDIR", "TMP", "TEMP"] {+ env.insert(name.to_owned(), scratch_dir.to_owned());+ }+ }+ request.env = env;++ let result = if mount_workspace {+ crate::modules::tinybox::run_docker(config, request).await+ } else {+ crate::modules::tinybox::run_docker_without_workspace(config, request).await+ };+ let result = match result {+ Ok(output) => docker_module_result(output, explicit_timeout),+ Err(_) => ToolResult::error("Docker module execution failed."),+ };+ return (true, result);+ }+let mut cmd = match self.runtime.build_shell_command(command, &action_dir) {Ok(cmd) => cmd,Err(e) => {