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: route Docker sandbox commands through TinyBox
Steven Enamakel141f1ccbae4f
diff --git a/Cargo.lock b/Cargo.lockindex 8d68d4b898..64b8b0e194 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -6894,14 +6894,14 @@ dependencies = [[[package]]name = "tinybox-bus"-version = "0.1.18"+version = "0.1.19"dependencies = ["serde",][[package]]name = "tinybox-core"-version = "0.1.18"+version = "0.1.19"dependencies = ["async-trait","serde",@@ -6911,7 +6911,7 @@ dependencies = [[[package]]name = "tinybox-docker"-version = "0.1.18"+version = "0.1.19"dependencies = ["async-trait","serde_json",@@ -6922,7 +6922,7 @@ dependencies = [[[package]]name = "tinybox-jail"-version = "0.1.18"+version = "0.1.19"dependencies = ["landlock","log",diff --git a/crates/openhuman-core/src/modules/registry/records_extra.rs b/crates/openhuman-core/src/modules/registry/records_extra.rsindex 851d2f9df1..e4a4d1a7a3 100644--- a/crates/openhuman-core/src/modules/registry/records_extra.rs+++ b/crates/openhuman-core/src/modules/registry/records_extra.rs@@ -8,63 +8,63 @@ pub(crate) const TINYBOX: ModuleRecord = ModuleRecord {description: "Sandbox capability discovery through TinyBox",bus_name: "ai.tinyhumans.tinybox.Box",object_path: "/ai/tinyhumans/tinybox/Box",- version: "0.1.18",- release_url: "https://github.com/tinyhumansai/tinybox/releases/tag/v0.1.18",+ version: "0.1.19",+ release_url: "https://github.com/tinyhumansai/tinybox/releases/tag/v0.1.19",assets: &[PlatformAsset {host_key: "ubuntu-24.04-x86_64",- archive: "tinybox-0.1.18-ubuntu-24.04-x86_64.tar.gz",- sha256: "232934349cb0ece8f049c00e5d15e38e30248a100cd9b66b203e69aee23145da",+ archive: "tinybox-0.1.19-ubuntu-24.04-x86_64.tar.gz",+ sha256: "a1dae0e4af4a1ba84fc37b048ad1d1ef0e226ec2c2b312d7607a8ec08d09d134",},PlatformAsset {host_key: "ubuntu-24.04-arm64",- archive: "tinybox-0.1.18-ubuntu-24.04-arm64.tar.gz",- sha256: "994a37f95e128cd1b54999a9d4eebf012eaeb17b6a3006c9985a83b10e4ee6e1",+ archive: "tinybox-0.1.19-ubuntu-24.04-arm64.tar.gz",+ sha256: "245eaf3ab5465e9e01da207ef63bf930c46069b3858fe9ce9da8e71559c0faf8",},PlatformAsset {host_key: "ubuntu-22.04-x86_64",- archive: "tinybox-0.1.18-ubuntu-22.04-x86_64.tar.gz",- sha256: "f8210816dfacd7ee58dcfb4482845f40ee4dbb435f706c2e154e9542a15f8329",+ archive: "tinybox-0.1.19-ubuntu-22.04-x86_64.tar.gz",+ sha256: "c23102c295b8e5ceef428d1ed178ac910031a23640eaebceb7ebfe3c19a2e05c",},PlatformAsset {host_key: "ubuntu-22.04-arm64",- archive: "tinybox-0.1.18-ubuntu-22.04-arm64.tar.gz",- sha256: "b192c1ce4333b8668ec9f38a0197aeb443c5a9afd63d5f9b617a6de97f080f4b",+ archive: "tinybox-0.1.19-ubuntu-22.04-arm64.tar.gz",+ sha256: "b81e147875a5f21b9b681dffa633c480cfa0bf0121e3ea309feb859d7206d866",},PlatformAsset {host_key: "macos-26-arm64",- archive: "tinybox-0.1.18-macos-26-arm64.tar.gz",- sha256: "6d7c9120f6f773861ed0901360142ad0c131fe9597d937a21788891a6cae9663",+ archive: "tinybox-0.1.19-macos-26-arm64.tar.gz",+ sha256: "437ae2b09337b30ad1af85f3fe95be5cc0d8134986f401a231448a37c340f54b",},PlatformAsset {host_key: "macos-26-x86_64",- archive: "tinybox-0.1.18-macos-26-x86_64.tar.gz",- sha256: "7e61a78a8ea82aec31692d84979169ba72202ac7698ecac7cf515445f911473d",+ archive: "tinybox-0.1.19-macos-26-x86_64.tar.gz",+ sha256: "24c3397596e20e3661e6fc6d0ba28f2f36a8c3d7f4e5106030f674d5d3703f6d",},PlatformAsset {host_key: "macos-15-arm64",- archive: "tinybox-0.1.18-macos-15-arm64.tar.gz",- sha256: "b827b00712d8ea5eaf081be9bb8d9e5283dd29fbf34c1dc8d26d15a64224483b",+ archive: "tinybox-0.1.19-macos-15-arm64.tar.gz",+ sha256: "61145d8dbb56d866d85610702938973b7c8f523093154ec3a27790dc060565bd",},PlatformAsset {host_key: "macos-15-x86_64",- archive: "tinybox-0.1.18-macos-15-x86_64.tar.gz",- sha256: "c4526cc2f05137d1d82d8a41681403c3c74d0c585a7ff51c4dd49ff3f2eb9694",+ archive: "tinybox-0.1.19-macos-15-x86_64.tar.gz",+ sha256: "8e68322fe3ff762ad6b31a55413cfd7772174b2bdadc0b5391d1816d36a6b373",},PlatformAsset {host_key: "windows-2025-x86_64",- archive: "tinybox-0.1.18-windows-2025-x86_64.zip",- sha256: "c320392f979d3298c4bcecb4b54f18db40d49bb546634a441219eef9f5fbf592",+ archive: "tinybox-0.1.19-windows-2025-x86_64.zip",+ sha256: "8ac5b73f23deee35d2f61209b801a5fcb6465277e35afc45dac4e91cfe528ce0",},PlatformAsset {host_key: "windows-2022-x86_64",- archive: "tinybox-0.1.18-windows-2022-x86_64.zip",- sha256: "d06c300eb7651147e9c7672e1377f25cc88e824be6afadfdafd4ec7eb6f5f8d1",+ archive: "tinybox-0.1.19-windows-2022-x86_64.zip",+ sha256: "f2682b28908c9736382fab57c0f579db4a17ae3e037d9422f185a0f949e69143",},PlatformAsset {host_key: "windows-11-arm64",- archive: "tinybox-0.1.18-windows-11-arm64.zip",- sha256: "b3a26410b6a7adda83ae9ce23e0716367e06c3561e8a2f9ffbe30b6820ccae89",+ archive: "tinybox-0.1.19-windows-11-arm64.zip",+ sha256: "50873a041c05d009f8f65812e6ac95fef001b1d71a897383da1f34fac1f2a7d0",},],load: LoadPolicy::Lazy,diff --git a/crates/openhuman-core/src/modules/registry_tests.rs b/crates/openhuman-core/src/modules/registry_tests.rsindex 8394b41071..532164d8b7 100644--- a/crates/openhuman-core/src/modules/registry_tests.rs+++ b/crates/openhuman-core/src/modules/registry_tests.rs@@ -20,12 +20,12 @@ fn tinycomputer_registry_matches_bus_contract_and_published_release() {}#[test]-fn tinybox_registry_matches_the_published_v0118_release_manifest() {+fn tinybox_registry_matches_the_published_v0119_release_manifest() {let record = find("tinybox").expect("compiled TinyBox module");- assert_eq!(record.version, "0.1.18");+ assert_eq!(record.version, "0.1.19");assert_eq!(record.release_url,- "https://github.com/tinyhumansai/tinybox/releases/tag/v0.1.18"+ "https://github.com/tinyhumansai/tinybox/releases/tag/v0.1.19");let actual = record@@ -36,58 +36,58 @@ fn tinybox_registry_matches_the_published_v0118_release_manifest() {let published = [("ubuntu-24.04-x86_64",- "tinybox-0.1.18-ubuntu-24.04-x86_64.tar.gz",- "232934349cb0ece8f049c00e5d15e38e30248a100cd9b66b203e69aee23145da",+ "tinybox-0.1.19-ubuntu-24.04-x86_64.tar.gz",+ "a1dae0e4af4a1ba84fc37b048ad1d1ef0e226ec2c2b312d7607a8ec08d09d134",),("ubuntu-24.04-arm64",- "tinybox-0.1.18-ubuntu-24.04-arm64.tar.gz",- "994a37f95e128cd1b54999a9d4eebf012eaeb17b6a3006c9985a83b10e4ee6e1",+ "tinybox-0.1.19-ubuntu-24.04-arm64.tar.gz",+ "245eaf3ab5465e9e01da207ef63bf930c46069b3858fe9ce9da8e71559c0faf8",),("ubuntu-22.04-x86_64",- "tinybox-0.1.18-ubuntu-22.04-x86_64.tar.gz",- "f8210816dfacd7ee58dcfb4482845f40ee4dbb435f706c2e154e9542a15f8329",+ "tinybox-0.1.19-ubuntu-22.04-x86_64.tar.gz",+ "c23102c295b8e5ceef428d1ed178ac910031a23640eaebceb7ebfe3c19a2e05c",),("ubuntu-22.04-arm64",- "tinybox-0.1.18-ubuntu-22.04-arm64.tar.gz",- "b192c1ce4333b8668ec9f38a0197aeb443c5a9afd63d5f9b617a6de97f080f4b",+ "tinybox-0.1.19-ubuntu-22.04-arm64.tar.gz",+ "b81e147875a5f21b9b681dffa633c480cfa0bf0121e3ea309feb859d7206d866",),("macos-26-arm64",- "tinybox-0.1.18-macos-26-arm64.tar.gz",- "6d7c9120f6f773861ed0901360142ad0c131fe9597d937a21788891a6cae9663",+ "tinybox-0.1.19-macos-26-arm64.tar.gz",+ "437ae2b09337b30ad1af85f3fe95be5cc0d8134986f401a231448a37c340f54b",),("macos-26-x86_64",- "tinybox-0.1.18-macos-26-x86_64.tar.gz",- "7e61a78a8ea82aec31692d84979169ba72202ac7698ecac7cf515445f911473d",+ "tinybox-0.1.19-macos-26-x86_64.tar.gz",+ "24c3397596e20e3661e6fc6d0ba28f2f36a8c3d7f4e5106030f674d5d3703f6d",),("macos-15-arm64",- "tinybox-0.1.18-macos-15-arm64.tar.gz",- "b827b00712d8ea5eaf081be9bb8d9e5283dd29fbf34c1dc8d26d15a64224483b",+ "tinybox-0.1.19-macos-15-arm64.tar.gz",+ "61145d8dbb56d866d85610702938973b7c8f523093154ec3a27790dc060565bd",),("macos-15-x86_64",- "tinybox-0.1.18-macos-15-x86_64.tar.gz",- "c4526cc2f05137d1d82d8a41681403c3c74d0c585a7ff51c4dd49ff3f2eb9694",+ "tinybox-0.1.19-macos-15-x86_64.tar.gz",+ "8e68322fe3ff762ad6b31a55413cfd7772174b2bdadc0b5391d1816d36a6b373",),("windows-2025-x86_64",- "tinybox-0.1.18-windows-2025-x86_64.zip",- "c320392f979d3298c4bcecb4b54f18db40d49bb546634a441219eef9f5fbf592",+ "tinybox-0.1.19-windows-2025-x86_64.zip",+ "8ac5b73f23deee35d2f61209b801a5fcb6465277e35afc45dac4e91cfe528ce0",),("windows-2022-x86_64",- "tinybox-0.1.18-windows-2022-x86_64.zip",- "d06c300eb7651147e9c7672e1377f25cc88e824be6afadfdafd4ec7eb6f5f8d1",+ "tinybox-0.1.19-windows-2022-x86_64.zip",+ "f2682b28908c9736382fab57c0f579db4a17ae3e037d9422f185a0f949e69143",),("windows-11-arm64",- "tinybox-0.1.18-windows-11-arm64.zip",- "b3a26410b6a7adda83ae9ce23e0716367e06c3561e8a2f9ffbe30b6820ccae89",+ "tinybox-0.1.19-windows-11-arm64.zip",+ "50873a041c05d009f8f65812e6ac95fef001b1d71a897383da1f34fac1f2a7d0",),];diff --git a/crates/openhuman-core/src/modules/tinybox.rs b/crates/openhuman-core/src/modules/tinybox.rsindex bfd5cfdeb7..4899ea9556 100644--- a/crates/openhuman-core/src/modules/tinybox.rs+++ b/crates/openhuman-core/src/modules/tinybox.rs@@ -48,6 +48,8 @@ const START_EXEC: &str = contract::METHODS[23];const READ_OUTPUT: &str = contract::METHODS[24];const RELEASE_OUTPUT: &str = contract::METHODS[25];const START_JAILED_EXEC: &str = contract::METHODS[26];+const RUN_DOCKER: &str = contract::METHODS[27];+const DOCKER_CALL_GRACE: Duration = Duration::from_secs(5);#[cfg(test)]#[path = "tinybox_tests.rs"]@@ -160,6 +162,27 @@ pub async fn start_jailed_exec(call(config, START_JAILED_EXEC, (request, jail), true).await}+/// Run one bounded Docker-isolated command through TinyBox.+///+/// The caller applies authorization and Docker policy before sending this+/// confidential request. The bus deadline includes a short reply grace after+/// TinyBox's own command deadline so the timeout result can be delivered.+pub async fn run_docker(+ config: &Config,+ request: contract::DockerRunRequest,+) -> Result<contract::DockerRunOutput, String> {+ let timeout = Duration::from_millis(request.timeout_ms).saturating_add(DOCKER_CALL_GRACE);+ let client = ModuleClient::new(config.clone()).with_timeout(timeout);+ call_run_docker_with_client(&client, request).await+}++async fn call_run_docker_with_client(+ client: &ModuleClient,+ request: contract::DockerRunRequest,+) -> Result<contract::DockerRunOutput, String> {+ call_with_client(client, RUN_DOCKER, (request,), true).await+}+/// Read a bounded output batch from a live or completed process.pub async fn read_output(config: &Config,diff --git a/crates/openhuman-core/src/modules/tinybox_tests.rs b/crates/openhuman-core/src/modules/tinybox_tests.rsindex ac5bec8f1e..64be75073b 100644--- a/crates/openhuman-core/src/modules/tinybox_tests.rs+++ b/crates/openhuman-core/src/modules/tinybox_tests.rs@@ -10,6 +10,20 @@ use tinybus::{Connection, InterfaceName, MemberName, ObjectPath};use super::*;+struct EnvironmentRestore {+ key: &'static str,+ previous: Option<std::ffi::OsString>,+}++impl Drop for EnvironmentRestore {+ fn drop(&mut self) {+ match self.previous.take() {+ Some(value) => std::env::set_var(self.key, value),+ None => std::env::remove_var(self.key),+ }+ }+}+struct MockTinyBox {calls: Arc<Mutex<Vec<(String, Value)>>>,}@@ -170,24 +184,132 @@ async fn confidential_execution_refusal_is_not_retried_as_an_ordinary_call() {}#[tokio::test]-#[ignore = "requires OPENHUMAN_BUNDLED_MODULES containing the pinned TinyBox release archive"]+async fn docker_command_refusal_is_not_retried_as_an_ordinary_call() {+ let (_service, client, calls) = mock_client().await;+ let error = call_run_docker_with_client(+ &client,+ contract::DockerRunRequest {+ workspace: "/workspace".to_owned(),+ image: None,+ command: "printf secret".to_owned(),+ network: None,+ memory_limit_mb: None,+ cpus: None,+ read_only_rootfs: None,+ read_only_mounts: Vec::new(),+ extra_cap_drops: Vec::new(),+ env: Default::default(),+ label: Some("openhuman.sandbox=true".to_owned()),+ timeout_ms: 1_000,+ },+ )+ .await+ .expect_err("an unattested fixture cannot receive a shell command");++ assert!(error.contains("MODULE_CALL_REPORTED"), "{error}");+ assert!(!error.contains("printf secret"));+ let calls = calls.lock().expect("call log lock");+ assert_eq!(calls.len(), 1, "only the public capabilities probe ran");+ assert_eq!(calls[0].0, CAPABILITIES);+}++#[tokio::test]+#[ignore = "requires a verified TinyBox archive, local Docker daemon, and preloaded alpine:latest"]async fn pinned_loader_serves_the_published_tinybox_release() {+ let _environment_lock = crate::config::TEST_ENV_LOCK.lock().await;+ let artifact_root = std::env::var_os(crate::modules::ops::BUNDLED_MODULES_ENV)+ .map(std::path::PathBuf::from)+ .expect(+ "set OPENHUMAN_BUNDLED_MODULES to the directory containing pinned release archives",+ );+ let record = crate::modules::registry::find(MODULE_ID).expect("TinyBox registry record");+ let asset = tinybus::module::platform::host_candidates()+ .iter()+ .find_map(|host_key| record.asset_for(host_key))+ .expect("the pinned release supports this host");+ let archive = artifact_root.join(asset.archive);assert!(- std::env::var_os(crate::modules::ops::BUNDLED_MODULES_ENV).is_some(),- "set OPENHUMAN_BUNDLED_MODULES to the directory containing the pinned release archive"+ archive.is_file(),+ "missing verified release archive: {archive:?}");+ let bundled = tempfile::tempdir().expect("temporary installer bundle root");+ let bundle_asset_dir = bundled+ .path()+ .join(MODULE_ID)+ .join(record.version)+ .join(asset.host_key);+ std::fs::create_dir_all(&bundle_asset_dir).expect("create TinyBus bundle layout");+ if asset.archive.ends_with(".tar.gz") {+ let archive_file = std::fs::File::open(&archive).expect("open verified release archive");+ let decoder = flate2::read::GzDecoder::new(archive_file);+ tar::Archive::new(decoder)+ .unpack(&bundle_asset_dir)+ .expect("extract verified release archive");+ } else if asset.archive.ends_with(".zip") {+ let archive_file = std::fs::File::open(&archive).expect("open verified release archive");+ zip::ZipArchive::new(archive_file)+ .expect("read verified release archive")+ .extract(&bundle_asset_dir)+ .expect("extract verified release archive");+ } else {+ panic!(+ "unsupported pinned release archive format: {}",+ asset.archive+ );+ }+ std::fs::copy(&archive, bundle_asset_dir.join(asset.archive))+ .expect("stage verified release archive in TinyBus bundle layout");+ std::fs::write(+ bundle_asset_dir.join(format!("{}.sha256", asset.archive)),+ format!("{}\n", asset.sha256),+ )+ .expect("stage the release digest marker required by TinyBus");+ let key = crate::modules::ops::BUNDLED_MODULES_ENV;+ let _environment_restore = EnvironmentRestore {+ key,+ previous: std::env::var_os(key),+ };+ std::env::set_var(key, bundled.path());let install = tempfile::tempdir().expect("temporary verified module cache");let mut config = Config::default();+ config.modules.enabled = true;config.modules.allow_download = false;config.modules.install_dir = Some(install.path().display().to_string());+ crate::modules::ops::ensure_loaded(&config, MODULE_ID)+ .await+ .expect("the OpenHuman release registry and TinyBus loader admit v0.1.19");let capabilities = super::capabilities(&config).await- .expect("the OpenHuman release registry and TinyBus loader admit v0.1.18");+ .expect("the loaded release serves TinyBus capabilities");assert_eq!(capabilities.contract_version, contract::CONTRACT_VERSION);assert!(capabilities.create_backends.contains(&"docker".to_owned()));assert!(capabilities.exec_backends.contains(&"docker".to_owned()));++ let workspace = tempfile::tempdir().expect("temporary Docker workspace");+ let output = run_docker(+ &config,+ contract::DockerRunRequest {+ workspace: workspace.path().display().to_string(),+ image: Some("alpine:latest".to_owned()),+ command: "printf tinybox-module-run-ok".to_owned(),+ network: Some("none".to_owned()),+ memory_limit_mb: Some(128),+ cpus: Some(1.0),+ read_only_rootfs: Some(true),+ read_only_mounts: Vec::new(),+ extra_cap_drops: Vec::new(),+ env: Default::default(),+ label: Some("openhuman.sandbox=true".to_owned()),+ timeout_ms: 15_000,+ },+ )+ .await+ .expect("the published confidential RunDocker member executes locally");+ assert_eq!(output.exit_code, 0);+ assert!(!output.timed_out);+ assert_eq!(output.stdout, "tinybox-module-run-ok");}#[test]@@ -220,6 +342,7 @@ fn every_host_operation_is_a_member_of_the_canonical_contract() {READ_OUTPUT,RELEASE_OUTPUT,START_JAILED_EXEC,+ RUN_DOCKER,];assert_eq!(methods, contract::METHODS);}diff --git a/crates/openhuman-core/src/sandbox/docker.rs b/crates/openhuman-core/src/sandbox/docker.rsindex e2ae615aca..aabe820da7 100644--- a/crates/openhuman-core/src/sandbox/docker.rs+++ b/crates/openhuman-core/src/sandbox/docker.rs@@ -1,8 +1,8 @@//! Docker-backed sandbox execution backend.//!-//! Policy mapping for the Docker sandbox; the one-shot container itself is-//! `tinybox_docker::OneShot` / `DockerCli`. Commands run inside ephemeral-//! containers with:+//! Policy mapping for the Docker sandbox; TinyBox owns one-shot container+//! creation, execution, and bounded output collection. Commands run inside+//! ephemeral containers with://! - Controlled workspace mounts (host `action_dir` → `/workspace`)//! - Network isolation (default: `none`)//! - Resource limits (memory, CPU)@@ -18,7 +18,7 @@ use super::types::{SandboxBackendHandle, SandboxBackendKind, SandboxExecRequest, SandboxExecResult, SandboxPolicy,SandboxStatus,};-use tinybox_docker::{DockerCli, OneShot};+use tinybox_docker::DockerCli;/// Label applied to all sandbox containers for orphan cleanup.const CONTAINER_LABEL: &str = "openhuman.sandbox=true";@@ -31,52 +31,19 @@ pub async fn is_docker_available() -> bool {/// Execute a command inside an ephemeral Docker container.////// Policy stays here (which image, network, limits and mounts the-/// `SandboxPolicy` asks for); the one-shot `docker run --rm` command line and-/// its execution are `tinybox_docker::{OneShot, DockerCli}`.+/// `SandboxPolicy` asks for); TinyBox owns the one-shot container operation.+/// There is no local Docker execution fallback when the module is unavailable.+#[cfg(feature = "modules")]pub async fn docker_exec(+ config: &crate::config::Config,policy: &SandboxPolicy,request: &SandboxExecRequest,) -> anyhow::Result<SandboxExecResult> {- let overrides = policy.docker_overrides.as_ref();- let mut spec = OneShot::new(&policy.workspace_root, &request.command)- .with_label(CONTAINER_LABEL)- .with_read_only_mounts(policy.read_only_mounts.iter().cloned());- if let Some(ov) = overrides {- if let Some(image) = &ov.image {- spec = spec.with_image(image);- }- if let Some(network) = &ov.network {- spec = spec.with_network(network);- }- if let Some(mb) = ov.memory_limit_mb {- spec = spec.with_memory_mb(mb);- }- if let Some(cpu) = ov.cpu_limit {- spec = spec.with_cpus(cpu);- }- if let Some(ro) = ov.read_only_rootfs {- spec = spec.with_read_only_rootfs(ro);- }- spec = spec.with_extra_cap_drops(ov.extra_caps_drop.iter().cloned());- }+ let run = build_docker_request(policy, request)?;- // Environment passthrough (explicit allowlist, only when set), then the- // request-specific environment.- let mut env: Vec<(std::ffi::OsString, std::ffi::OsString)> = policy- .env_passthrough- .iter()- .filter_map(|name| std::env::var(name).ok().map(|v| (name.into(), v.into())))- .collect();- env.extend(request.env.iter().map(|(k, v)| (k.clone(), v.clone())));- let spec = spec.with_env(env);-- tracing::debug!(- workspace = %policy.workspace_root.display(),- command = %request.command,- "[sandbox:docker] launching container"- );-- match DockerCli::new().run_one_shot(&spec, request.timeout).await {+ tracing::debug!("[sandbox:docker] launching container");++ match crate::modules::tinybox::run_docker(config, run).await {Ok(out) if out.timed_out => {tracing::warn!(timeout_secs = request.timeout.as_secs(),@@ -103,11 +70,89 @@ pub async fn docker_exec(timed_out: false,})}- Err(e) => {- tracing::error!(error = %e, "[sandbox:docker] failed to spawn container");- anyhow::bail!("Docker execution failed: {e}")+ Err(error) => anyhow::bail!("Docker execution failed: {error}"),+ }+}++#[cfg(not(feature = "modules"))]+pub async fn docker_exec(+ _config: &crate::config::Config,+ _policy: &SandboxPolicy,+ _request: &SandboxExecRequest,+) -> anyhow::Result<SandboxExecResult> {+ anyhow::bail!("TinyBox module support is disabled; Docker sandbox execution is unavailable")+}++#[cfg(feature = "modules")]+fn build_docker_request(+ policy: &SandboxPolicy,+ request: &SandboxExecRequest,+) -> anyhow::Result<crate::modules::tinybox::contract::DockerRunRequest> {+ use crate::modules::tinybox::contract::{DockerRunRequest, MAX_DOCKER_RUN_TIMEOUT_MS};+ use std::collections::BTreeMap;++ let workspace = path_string(&policy.workspace_root, "workspace")?;+ let read_only_mounts = policy+ .read_only_mounts+ .iter()+ .map(|path| path_string(path, "read-only mount"))+ .collect::<anyhow::Result<Vec<_>>>()?;++ // Keep the existing allowlist as the only inherited environment surface.+ // Per-request values override inherited values with the same name.+ let mut env = BTreeMap::new();+ for name in &policy.env_passthrough {+ if let Ok(value) = std::env::var(name) {+ env.insert(name.clone(), value);}}+ for (name, value) in &request.env {+ let name = name+ .to_str()+ .ok_or_else(|| anyhow::anyhow!("Docker environment name is not UTF-8"))?;+ let value = value+ .to_str()+ .ok_or_else(|| anyhow::anyhow!("Docker environment value is not UTF-8"))?;+ env.insert(name.to_owned(), value.to_owned());+ }++ let timeout_ms = request+ .timeout+ .as_nanos()+ .saturating_add(999_999)+ .checked_div(1_000_000)+ .unwrap_or(0)+ .max(1);+ let timeout_ms = u64::try_from(timeout_ms)+ .map_err(|_| anyhow::anyhow!("Docker timeout exceeds the supported limit"))?;+ if timeout_ms > MAX_DOCKER_RUN_TIMEOUT_MS {+ anyhow::bail!("Docker timeout exceeds the supported limit");+ }++ let overrides = policy.docker_overrides.as_ref();+ Ok(DockerRunRequest {+ workspace,+ image: overrides.and_then(|config| config.image.clone()),+ command: request.command.clone(),+ network: overrides.and_then(|config| config.network.clone()),+ memory_limit_mb: overrides.and_then(|config| config.memory_limit_mb),+ cpus: overrides.and_then(|config| config.cpu_limit),+ read_only_rootfs: overrides.and_then(|config| config.read_only_rootfs),+ read_only_mounts,+ extra_cap_drops: overrides+ .map(|config| config.extra_caps_drop.clone())+ .unwrap_or_default(),+ env,+ label: Some(CONTAINER_LABEL.to_owned()),+ timeout_ms,+ })+}++#[cfg(feature = "modules")]+fn path_string(path: &std::path::Path, kind: &str) -> anyhow::Result<String> {+ path.to_str()+ .map(str::to_owned)+ .ok_or_else(|| anyhow::anyhow!("Docker {kind} path is not UTF-8"))}/// Clean up orphaned sandbox containers (those labeled withdiff --git a/crates/openhuman-core/src/sandbox/docker_exec_tests.rs b/crates/openhuman-core/src/sandbox/docker_exec_tests.rsindex 96211ce1c5..82c707d52d 100644--- a/crates/openhuman-core/src/sandbox/docker_exec_tests.rs+++ b/crates/openhuman-core/src/sandbox/docker_exec_tests.rs@@ -1,15 +1,16 @@-//! Wire-level characterization of the Docker sandbox: a fake `docker` binary on-//! `PATH` records the exact argv it was launched with, so these tests pin the-//! command line (and the exit/timeout/truncation behaviour) that-//! `docker_exec` produces, independent of which crate builds it. Real Docker is-//! never required.+//! Docker sandbox request mapping and Docker CLI health/cleanup probes.+//! Execution mapping is tested without a daemon; TinyBox owns command-line+//! construction, execution, and output limits.#![cfg(unix)]use super::*;+#[cfg(feature = "modules")]use crate::sandbox::types::DockerOverrides;+#[cfg(feature = "modules")]use std::ffi::OsString;use std::os::unix::fs::PermissionsExt;use std::path::{Path, PathBuf};+#[cfg(feature = "modules")]use std::time::Duration;/// Install a fake `docker` that records argv (NUL separated) to `argv.out` and@@ -61,6 +62,7 @@ fn block_on<T>(fut: impl std::future::Future<Output = T>) -> T {.block_on(fut)}+#[cfg(feature = "modules")]fn policy(workspace: &Path) -> SandboxPolicy {SandboxPolicy {backend: SandboxBackendKind::Docker,@@ -74,6 +76,7 @@ fn policy(workspace: &Path) -> SandboxPolicy {}}+#[cfg(feature = "modules")]fn request(command: &str, timeout: Duration) -> SandboxExecRequest {SandboxExecRequest {command: command.into(),@@ -83,200 +86,103 @@ fn request(command: &str, timeout: Duration) -> SandboxExecRequest {}}-fn run(- dir: &Path,- body: &str,- policy: &SandboxPolicy,- req: &SandboxExecRequest,-) -> (SandboxExecResult, Vec<String>) {- let (bin, out) = fake_docker(dir, body);- let result = with_fake_path(&bin, || block_on(docker_exec(policy, req))).unwrap();- (result, recorded(&out))-}-fn s(v: &[&str]) -> Vec<String> {v.iter().map(|x| (*x).to_string()).collect()}-fn canon(p: &Path) -> String {- p.canonicalize().unwrap().display().to_string()-}-+#[cfg(feature = "modules")]#[test]-fn default_policy_argv_is_byte_identical() {- let tmp = tempfile::tempdir().unwrap();- let ws = tmp.path().join("ws");- std::fs::create_dir_all(&ws).unwrap();- let (res, argv) = run(- tmp.path(),- "echo out; echo err >&2; exit 3",- &policy(&ws),- &request("echo hi && ls", Duration::from_secs(20)),- );- let mut expected = s(&[- "run",- "--rm",- "--label",- "openhuman.sandbox=true",- "--network",- "none",- "--cap-drop",- "ALL",- "-m",- "512m",- "--cpus",- "1",- "--read-only",- "--tmpfs",- "/tmp:rw,noexec,nosuid,size=64m",- "--tmpfs",- "/var/tmp:rw,noexec,nosuid,size=64m",- "--security-opt",- "no-new-privileges",- "-v",- ]);- expected.push(format!("{}:/workspace", canon(&ws)));- expected.extend(s(&[- "-w",- "/workspace",- "alpine:3.20",- "sh",- "-c",- "echo hi && ls",- ]));- assert_eq!(argv, expected);- assert_eq!(res.exit_code, 3);- assert_eq!(res.stdout, "out\n");- assert_eq!(res.stderr, "err\n");- assert!(!res.timed_out);-}--#[test]-fn overrides_mounts_env_and_writable_rootfs_argv() {- let tmp = tempfile::tempdir().unwrap();- let ws = tmp.path().join("ws");- let ro = tmp.path().join("ro");- std::fs::create_dir_all(&ws).unwrap();- std::fs::create_dir_all(&ro).unwrap();- let missing_ro = PathBuf::from("/definitely/not/here");- let mut p = policy(&ws);- p.read_only_mounts = vec![ro.clone(), missing_ro];- p.env_passthrough = vec!["OH_DOCKER_TEST_SET".into(), "OH_DOCKER_TEST_UNSET".into()];- p.docker_overrides = Some(DockerOverrides {- image: Some("debian:12".into()),- network: Some("bridge".into()),+fn module_request_preserves_policy_and_only_forwards_allowed_environment() {+ use crate::modules::tinybox::contract::DockerRunRequest;++ let temp = tempfile::tempdir().unwrap();+ let workspace = temp.path().join("workspace");+ let readonly = temp.path().join("readonly");+ std::fs::create_dir_all(&workspace).unwrap();+ std::fs::create_dir_all(&readonly).unwrap();++ let mut sandbox_policy = policy(&workspace);+ sandbox_policy.read_only_mounts.push(readonly.clone());+ sandbox_policy.env_passthrough = vec!["OH_TINYBOX_ALLOWED_ENV".to_owned()];+ sandbox_policy.docker_overrides = Some(DockerOverrides {+ image: Some("debian:12".to_owned()),+ network: Some("bridge".to_owned()),memory_limit_mb: Some(2048),cpu_limit: Some(2.5),read_only_rootfs: Some(false),- extra_caps_drop: vec!["NET_RAW".into(), "MKNOD".into()],+ extra_caps_drop: vec!["NET_RAW".to_owned()],});- let mut req = request("make test", Duration::from_secs(20));- req.env- .insert(OsString::from("REQ_KEY"), OsString::from("req value=1"));- std::env::set_var("OH_DOCKER_TEST_SET", "pass-val");- std::env::remove_var("OH_DOCKER_TEST_UNSET");- let (res, argv) = run(tmp.path(), "exit 0", &p, &req);- std::env::remove_var("OH_DOCKER_TEST_SET");- let mut expected = s(&[- "run",- "--rm",- "--label",- "openhuman.sandbox=true",- "--network",- "bridge",- "--cap-drop",- "ALL",- "--cap-drop",- "NET_RAW",- "--cap-drop",- "MKNOD",- "-m",- "2048m",- "--cpus",- "2.5",- "--security-opt",- "no-new-privileges",- "-v",- ]);- expected.push(format!("{}:/workspace", canon(&ws)));- expected.extend(s(&["-w", "/workspace", "-v"]));- expected.push(format!("{0}:{0}:ro", canon(&ro)));- expected.extend(s(&["-v", "/definitely/not/here:/definitely/not/here:ro"]));- expected.extend(s(&[- "-e",- "OH_DOCKER_TEST_SET=pass-val",- "-e",- "REQ_KEY=req value=1",- "debian:12",- "sh",- "-c",- "make test",- ]));- assert_eq!(argv, expected);- assert_eq!(res.exit_code, 0);-}--#[test]-fn timeout_reports_timed_out_result() {- let tmp = tempfile::tempdir().unwrap();- let ws = tmp.path().join("ws");- std::fs::create_dir_all(&ws).unwrap();- let (res, _argv) = run(- tmp.path(),- "exec sleep 5",- &policy(&ws),- &request("sleep 100", Duration::from_millis(300)),- );- assert!(res.timed_out);- assert_eq!(res.exit_code, -1);- assert!(res.stdout.is_empty());- assert_eq!(res.stderr, "Command timed out after 0s and was killed");-}-#[test]-fn oversized_output_is_truncated_at_one_mebibyte() {- let tmp = tempfile::tempdir().unwrap();- let ws = tmp.path().join("ws");- std::fs::create_dir_all(&ws).unwrap();- let (res, _argv) = run(- tmp.path(),- "head -c 1100000 /dev/zero | tr '\\0' 'a'; head -c 1100000 /dev/zero | tr '\\0' 'b' >&2",- &policy(&ws),- &request("big", Duration::from_secs(20)),+ let _environment = crate::config::TEST_ENV_LOCK.blocking_lock();+ std::env::set_var("OH_TINYBOX_ALLOWED_ENV", "host value");+ std::env::set_var("OH_TINYBOX_UNLISTED_ENV", "must not be forwarded");+ let mut exec_request = request("make test", Duration::from_millis(1250));+ exec_request.env.insert(+ OsString::from("OH_TINYBOX_ALLOWED_ENV"),+ OsString::from("request override"),);- assert_eq!(- res.stdout.len(),- 1_048_576 + "\n... [output truncated at 1MB]".len()+ exec_request.env.insert(+ OsString::from("REQUEST_ENV"),+ OsString::from("request value"),);- assert!(res.stdout.ends_with("\n... [output truncated at 1MB]"));++ let actual = build_docker_request(&sandbox_policy, &exec_request).unwrap();+ std::env::remove_var("OH_TINYBOX_ALLOWED_ENV");+ std::env::remove_var("OH_TINYBOX_UNLISTED_ENV");assert_eq!(- res.stderr.len(),- 1_048_576 + "\n... [stderr truncated at 1MB]".len()+ actual,+ DockerRunRequest {+ workspace: workspace.to_string_lossy().into_owned(),+ image: Some("debian:12".to_owned()),+ command: "make test".to_owned(),+ network: Some("bridge".to_owned()),+ memory_limit_mb: Some(2048),+ cpus: Some(2.5),+ read_only_rootfs: Some(false),+ read_only_mounts: vec![readonly.to_string_lossy().into_owned()],+ extra_cap_drops: vec!["NET_RAW".to_owned()],+ env: [+ (+ "OH_TINYBOX_ALLOWED_ENV".to_owned(),+ "request override".to_owned()+ ),+ ("REQUEST_ENV".to_owned(), "request value".to_owned()),+ ]+ .into(),+ label: Some("openhuman.sandbox=true".to_owned()),+ timeout_ms: 1250,+ });- assert!(res.stderr.ends_with("\n... [stderr truncated at 1MB]"));}+#[cfg(feature = "modules")]#[test]-fn missing_docker_binary_is_an_execution_error() {- let tmp = tempfile::tempdir().unwrap();- let ws = tmp.path().join("ws");- std::fs::create_dir_all(&ws).unwrap();- // Replace PATH wholesale so no `docker` can be found.- let _guard = crate::config::TEST_ENV_LOCK.blocking_lock();- let prev = std::env::var_os("PATH");- std::env::set_var("PATH", tmp.path());- let err = block_on(docker_exec(- &policy(&ws),- &request("true", Duration::from_secs(5)),- ))- .unwrap_err();- if let Some(p) = prev {- std::env::set_var("PATH", p);- }- assert!(- err.to_string().starts_with("Docker execution failed: "),- "{err}"- );+fn module_request_rounds_small_timeouts_up_and_rejects_unbounded_timeouts() {+ use crate::modules::tinybox::contract::MAX_DOCKER_RUN_TIMEOUT_MS;++ let temp = tempfile::tempdir().unwrap();+ let mut exec_request = request("true", Duration::from_nanos(1));+ let short = build_docker_request(&policy(temp.path()), &exec_request).unwrap();+ assert_eq!(short.timeout_ms, 1);++ 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"));+}++#[cfg(all(feature = "modules", unix))]+#[test]+fn module_request_rejects_non_utf8_host_paths_without_lossy_remapping() {+ use std::os::unix::ffi::OsStringExt;++ let temp = tempfile::tempdir().unwrap();+ let path = temp.path().join(OsString::from_vec(vec![b'w', 0xff]));+ let error = build_docker_request(&policy(&path), &request("true", Duration::from_secs(1)))+ .expect_err("the module contract cannot represent an arbitrary OS path");+ assert!(error.to_string().contains("workspace path is not UTF-8"));}#[test]diff --git a/crates/openhuman-core/src/sandbox/ops.rs b/crates/openhuman-core/src/sandbox/ops.rsindex 8b62919882..28e486924b 100644--- a/crates/openhuman-core/src/sandbox/ops.rs+++ b/crates/openhuman-core/src/sandbox/ops.rs@@ -291,12 +291,14 @@ pub async fn execute_in_sandbox(if !crate::core::runtime::is_saas() && sandbox_disabled_by_host() {effective_policy.backend = SandboxBackendKind::None;}+ let mut module_config = None;let explicitly_requested = if crate::core::runtime::is_saas() || sandbox_disabled_by_host() {false} else {let config = crate::config::ops::load_config_with_timeout().await.map_err(|e| anyhow::anyhow!("Cannot read sandbox configuration: {e}"))?;+ module_config = Some(config.clone());if config.sandbox.enabled == Some(false) {false} else {@@ -339,7 +341,15 @@ pub async fn execute_in_sandbox(env: extra_env,timeout,};- docker::docker_exec(policy, &request).await+ let config = match module_config {+ Some(config) => config,+ None => crate::config::ops::load_config_with_timeout()+ .await+ .map_err(|error| {+ anyhow::anyhow!("Cannot read module configuration: {error}")+ })?,+ };+ docker::docker_exec(&config, policy, &request).await}}}diff --git a/crates/openhuman-embed/src/modules.rs b/crates/openhuman-embed/src/modules.rsindex dcface5c04..7a2cd09edb 100644--- a/crates/openhuman-embed/src/modules.rs+++ b/crates/openhuman-embed/src/modules.rs@@ -34,6 +34,7 @@ pub mod tinybox {abort_file_write, analyze_command, analyze_shell, begin_file_read, begin_file_write,cancel, capabilities, close, close_forward, create, describe, exec, finish_file_read,finish_file_write, forward, inspect, is_running, jail_status, read_file_chunk, read_output,- release_output, reserve, shutdown, spawn, start_exec, start_jailed_exec, write_file_chunk,+ release_output, reserve, run_docker, shutdown, spawn, start_exec, start_jailed_exec,+ write_file_chunk,};}diff --git a/vendor/tinybox b/vendor/tinyboxindex d493d1ccae..7f902d775e 160000--- a/vendor/tinybox+++ b/vendor/tinybox@@ -1 +1 @@-Subproject commit d493d1ccaef3cb2891ca387b30214b30b6f7df1e+Subproject commit 7f902d775e72b34d9f2e5611e23bffe713eb155e