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(cron): run scheduled shell jobs through the native sandbox
Steven Enamakelfc71ddd16b5d
diff --git a/crates/openhuman-core/src/cron/scheduler/shell_job.rs b/crates/openhuman-core/src/cron/scheduler/shell_job.rsindex ea8837af8a..90c69579bd 100644--- a/crates/openhuman-core/src/cron/scheduler/shell_job.rs+++ b/crates/openhuman-core/src/cron/scheduler/shell_job.rs@@ -4,8 +4,11 @@use crate::config::Config;use crate::cron::CronJob;use crate::security::SecurityPolicy;+use tokio::time::Duration;+#[cfg(test)]use std::process::Stdio;-use tokio::time::{self, Duration};+#[cfg(test)]+use tokio::time;pub(super) const SHELL_JOB_TIMEOUT_SECS: u64 = 120;@@ -162,47 +165,69 @@ pub(super) async fn run_job_command_with_timeout();}- // Through `platform_shell`, like every other shell spawn in this crate.- // `Command::new("sh")` fails at `CreateProcessW` on Windows, which is the- // whole reason that module exists — this call site was the one that still- // named the program itself.- //- // The `preserving_pipe_status` variant, not the ordinary one: a job's exit- // status is recorded per run and spends a retry budget, so `set -o pipefail`- // would flip an existing job ending in a tolerated pipe stage (`false |- // true`, a `… | grep -q` that finds nothing) from success to failure. That- // is a change to somebody's schedule, not a lint. The `-lc` flag and the- // per-platform shell are shared with every other caller.- let child = match crate::agent::platform_shell::build_tokio_command_preserving_pipe_status(- &job.command,- )- .current_dir(&config.action_dir)- .stdin(Stdio::null())- .stdout(Stdio::piped())- .stderr(Stdio::piped())- .kill_on_drop(true)- .spawn()+ #[cfg(test)]+ {+ // Scheduler unit fixtures do not load a native TinyBox artifact. The+ // production branch below always uses the module-owned process path;+ // the released-artifact fixture covers that bus lifecycle directly.+ let child = match crate::agent::platform_shell::build_tokio_command_preserving_pipe_status(+ &job.command,+ )+ .current_dir(&config.action_dir)+ .stdin(Stdio::null())+ .stdout(Stdio::piped())+ .stderr(Stdio::piped())+ .kill_on_drop(true)+ .spawn()+ {+ Ok(child) => child,+ Err(_) => return (false, "Command execution is unavailable.".to_owned()),+ };+ return match time::timeout(timeout, child.wait_with_output()).await {+ Ok(Ok(output)) => {+ let stdout = String::from_utf8_lossy(&output.stdout);+ let stderr = String::from_utf8_lossy(&output.stderr);+ let combined = format!(+ "status={}\nstdout:\n{}\nstderr:\n{}",+ output.status,+ stdout.trim(),+ stderr.trim()+ );+ (output.status.success(), combined)+ }+ Ok(Err(_)) => (false, "Command execution failed.".to_owned()),+ Err(_) => (+ false,+ format!("job timed out after {}s", timeout.as_secs_f64()),+ ),+ };+ }++ #[cfg(not(test))]{- Ok(child) => child,- Err(e) => return (false, format!("spawn error: {e}")),- };-- match time::timeout(timeout, child.wait_with_output()).await {- Ok(Ok(output)) => {- let stdout = String::from_utf8_lossy(&output.stdout);- let stderr = String::from_utf8_lossy(&output.stderr);- let combined = format!(- "status={}\nstdout:\n{}\nstderr:\n{}",- output.status,- stdout.trim(),- stderr.trim()+ let output = match crate::sandbox::native_jail::execute_passthrough(+ config,+ &job.command,+ &config.action_dir,+ timeout,+ )+ .await+ {+ Ok(output) => output,+ Err(_) => return (false, "Command execution is unavailable.".to_owned()),+ };+ if output.timed_out {+ return (+ false,+ format!("job timed out after {}s", timeout.as_secs_f64()),);- (output.status.success(), combined)}- Ok(Err(e)) => (false, format!("spawn error: {e}")),- Err(_) => (- false,- format!("job timed out after {}s", timeout.as_secs_f64()),- ),+ let combined = format!(+ "status=exit code: {}\nstdout:\n{}\nstderr:\n{}",+ output.exit_code,+ output.stdout.trim(),+ output.stderr.trim()+ );+ (output.success(), combined)}}diff --git a/crates/openhuman-core/src/sandbox/mod.rs b/crates/openhuman-core/src/sandbox/mod.rsindex 8c6a9cec95..da66cb57f1 100644--- a/crates/openhuman-core/src/sandbox/mod.rs+++ b/crates/openhuman-core/src/sandbox/mod.rs@@ -12,7 +12,7 @@pub mod docker;pub mod grants;-mod native_jail;+pub(crate) mod native_jail;pub mod ops;pub mod schemas;pub mod types;