Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(shell): add tinybox sandbox support to shell tool

Steven Enamakeldf8d024764aa
diff --git a/crates/openhuman-app/Cargo.lock b/crates/openhuman-app/Cargo.lock
index 3757553f06..92a675f5cf 100644
--- a/crates/openhuman-app/Cargo.lock
+++ b/crates/openhuman-app/Cargo.lock
@@ -6735,7 +6735,7 @@ dependencies = [
[[package]]
name = "tinybox-bus"
-version = "0.1.26"
+version = "0.1.27"
dependencies = [
"serde",
]
diff --git a/crates/openhuman-core/src/modules/tinybox_tests.rs b/crates/openhuman-core/src/modules/tinybox_tests.rs
index 5c5fa1f4dc..8255157942 100644
--- a/crates/openhuman-core/src/modules/tinybox_tests.rs
+++ b/crates/openhuman-core/src/modules/tinybox_tests.rs
@@ -550,53 +550,25 @@ async fn shell_selection_and_start_use_contract_members_with_typed_requests() {
assert_eq!(log[1].1, json!([request]));
}
+/// The fixture bus cannot attest a recipient, so confidential calls are made
+/// unconfidentially here; the member name and positional argument are pinned.
#[tokio::test]
-async fn native_shell_start_calls_the_native_member_not_the_two_argument_shell_member() {
+async fn native_shell_and_policy_validation_use_their_contract_members() {
let (_service, client, calls) = mock_client().await;
- let request = contract::ShellExecRequest {
- process: contract::ResourceId("p".to_owned()),
- resource: contract::ResourceId("r".to_owned()),
- shell: contract::SelectShellRequest {
- command: "echo hi".to_owned(),
- preserve_pipeline_status: false,
- runtime_path: None,
- python_utf8: true,
- },
- cwd: None,
- extra_env: Default::default(),
- state_dir: "/state".to_owned(),
- timeout_ms: 1_000,
- stdin: None,
- jail: None,
- hide_window: true,
+ let policy = contract::DockerPolicyRequest {
+ network: Some("host".to_owned()),
+ ..Default::default()
};
- // The fixture bus cannot attest a recipient, so the confidential variant
- // production uses is exercised unconfidentially here; the member name and
- // positional argument are what this pins.
- let _: () = call_with_client(&client, START_NATIVE_SHELL_EXEC, (request.clone(),), false)
+ let shell = json!({"process": "p", "resource": "r", "state_dir": "/s"});
+ let _: () = call_with_client(&client, START_NATIVE_SHELL_EXEC, (shell.clone(),), false)
.await
.expect("native shell start call");
- let log = calls.lock().expect("call log lock");
- let (member, args) = log.last().expect("start call logged");
- assert_eq!(member, "StartNativeShellExec");
- assert_eq!(*args, json!([request]));
-}
-
-#[tokio::test]
-async fn docker_policy_validation_uses_its_typed_member_and_request() {
- let (_service, client, calls) = mock_client().await;
- let request = contract::DockerPolicyRequest {
- network: Some("host".to_owned()),
- workspace: Some("/".to_owned()),
- read_only_mounts: vec!["/etc".to_owned()],
- };
- let _: () = call_with_client(&client, VALIDATE_DOCKER_POLICY, (request.clone(),), false)
+ let _: () = call_with_client(&client, VALIDATE_DOCKER_POLICY, (policy.clone(),), false)
.await
.expect("policy validation call");
let log = calls.lock().expect("call log lock");
- let (member, args) = log.last().expect("validation call logged");
- assert_eq!(member, "ValidateDockerPolicy");
- assert_eq!(*args, json!([request]));
+ assert_eq!(log[1], ("StartNativeShellExec".to_owned(), json!([shell])));
+ assert_eq!(log[2], ("ValidateDockerPolicy".to_owned(), json!([policy])));
}
#[tokio::test]
diff --git a/crates/openhuman-core/src/tools/impl/system/shell.rs b/crates/openhuman-core/src/tools/impl/system/shell.rs
index e62ce83023..404d0b649c 100644
--- a/crates/openhuman-core/src/tools/impl/system/shell.rs
+++ b/crates/openhuman-core/src/tools/impl/system/shell.rs
@@ -12,29 +12,6 @@ use tinytools::{PermissionLevel, Tool, ToolCallOptions, ToolResult, ToolTimeout}
/// Maximum output size in bytes (1MB).
const MAX_OUTPUT_BYTES: usize = 1_048_576;
-/// Exit status coreutils `timeout` returns when its own limit expires.
-const COMMAND_TIMEOUT_EXIT_CODE: i32 = 124;
-/// Appended to an exit-124 failure: the command's own `timeout` fired, not the
-/// tool's (#6953). Without it, `exit code 124 [stdout] ok` reads like a bug.
-const COMMAND_TIMEOUT_NOTE: &str = "[exit 124: the command's own `timeout` limit expired; the shell tool's timeout_secs did not fire]";
-
-/// The result when the tool's own `timeout_secs` deadline killed the command.
-fn tool_timeout_message(secs: u64) -> String {
- format!("Command timed out after {secs}s and was killed: the shell tool's timeout_secs limit fired.")
-}
-
-/// [`tinytools::command_failure`], plus [`COMMAND_TIMEOUT_NOTE`] on exit 124.
-fn command_failure(code: Option<i32>, stdout: &str, stderr: &str) -> ToolResult {
- let mut failure = tinytools::command_failure(code, stdout, stderr);
- if code == Some(COMMAND_TIMEOUT_EXIT_CODE) {
- tracing::debug!("[shell] exit 124: attributing it to the command's own timeout");
- failure.content.push(tinytools::ToolContent::Text {
- text: COMMAND_TIMEOUT_NOTE.to_string(),
- });
- }
- failure
-}
-
#[cfg(feature = "modules")]
fn docker_module_result(
output: crate::modules::tinybox::contract::DockerRunOutput,
@@ -699,73 +676,6 @@ impl ShellTool {
}
}
-/// Map a finished sandbox or module execution to the tool result.
-///
-/// The same exit-code and both-streams surfacing everywhere (#4095); the `-1`
-/// sentinel renders as a signal.
-fn exec_result(
- result: anyhow::Result<crate::sandbox::SandboxExecResult>,
- effective: Duration,
-) -> ToolResult {
- match result {
- Ok(result) if result.timed_out => {
- ToolResult::error(tool_timeout_message(effective.as_secs()))
- }
- Ok(result) if result.success() => {
- if result.stderr.is_empty() {
- ToolResult::success(result.stdout)
- } else {
- ToolResult::success(format!("{}\n[stderr]\n{}", result.stdout, result.stderr))
- }
- }
- Ok(result) => command_failure(
- tinytools::sandbox_exit_code(result.exit_code),
- &result.stdout,
- &result.stderr,
- ),
- Err(e) => ToolResult::error(format!("Sandbox execution failed: {e}")),
- }
-}
-
-/// Python's text-encoding defaults for a child, unless the parent sets its own.
-/// Under `cmd.exe` the console code page is a legacy one (cp1252, cp437), so a
-/// script printing anything outside it dies with `UnicodeEncodeError`. Both are
-/// no-ops for a non-Python command. Native runs get the same from TinyBox's
-/// `python_utf8` request flag; this serves the Docker and sandbox-policy paths,
-/// which forward their environment as plain variables.
-const PYTHON_UTF8_DEFAULTS: &[(&str, &str)] = &[("PYTHONUTF8", "1"), ("PYTHONIOENCODING", "utf-8")];
-
-fn python_utf8_env(
- lookup: impl Fn(&str) -> Option<std::ffi::OsString>,
-) -> Vec<(&'static str, std::ffi::OsString)> {
- PYTHON_UTF8_DEFAULTS
- .iter()
- .map(|(name, default)| {
- let value = lookup(name).unwrap_or_else(|| (*default).into());
- (*name, value)
- })
- .collect()
-}
-
-/// The host environment a Docker container receives: the sandbox allowlist from
-/// the parent plus the Python encoding defaults. `None` when a value is not UTF-8.
-#[cfg(feature = "modules")]
-fn container_environment() -> Option<std::collections::BTreeMap<String, String>> {
- let mut env = std::collections::BTreeMap::new();
- let inherited = crate::sandbox::ops::SANDBOX_ENV_PASSTHROUGH
- .iter()
- .filter_map(|name| {
- crate::tools::timeout::CommandEnvironment::var_os(name).map(|value| (*name, value))
- })
- .chain(python_utf8_env(
- crate::tools::timeout::CommandEnvironment::var_os,
- ));
- for (name, value) in inherited {
- env.insert(name.to_owned(), value.into_string().ok()?);
- }
- Some(env)
-}
-
#[cfg(test)]
#[path = "shell_tests.rs"]
mod tests;