Skip to content

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

feat(sandbox): add native jail and shell exec fixture

Steven Enamakela24da6f228de
diff --git a/crates/openhuman-core/src/sandbox/native_jail.rs b/crates/openhuman-core/src/sandbox/native_jail.rs
index bc06dbc12f..0bc810e1b1 100644
--- a/crates/openhuman-core/src/sandbox/native_jail.rs
+++ b/crates/openhuman-core/src/sandbox/native_jail.rs
@@ -91,92 +91,6 @@ pub(crate) async fn execute(
}
}
-/// Run a host-authorized command through TinyBox's supervised passthrough
-/// process lifecycle. This is used by cron, whose existing execution surface
-/// runs on the host rather than inside a jail.
-pub(crate) async fn execute_passthrough(
- config: &Config,
- command: &str,
- working_dir: &Path,
- timeout: Duration,
-) -> anyhow::Result<SandboxExecResult> {
- #[cfg(feature = "modules")]
- {
- let config = config.clone();
- let command = command.to_owned();
- let working_dir = working_dir.to_path_buf();
- tokio::spawn(async move {
- execute_passthrough_owned(&config, &command, &working_dir, timeout).await
- })
- .await
- .map_err(|_| anyhow::anyhow!("TinyBox passthrough worker did not finish"))?
- }
- #[cfg(not(feature = "modules"))]
- {
- let _ = (config, command, working_dir, timeout);
- anyhow::bail!("TinyBox module support is disabled; command execution is unavailable")
- }
-}
-
-#[cfg(feature = "modules")]
-async fn execute_passthrough_owned(
- config: &Config,
- command: &str,
- working_dir: &Path,
- timeout: Duration,
-) -> anyhow::Result<SandboxExecResult> {
- let resource = tinybox::reserve(config, contract::ReserveRequest::Resource)
- .await
- .map_err(|_| anyhow::anyhow!("TinyBox could not reserve a command resource"))?;
- let result = async {
- let workspace = path_string(working_dir, "command working directory")?;
- tinybox::create(
- config,
- contract::CreateRequest {
- resource: resource.clone(),
- backend: "passthrough".to_owned(),
- host: contract::HostConfig::Local,
- workspace: contract::Workspace::Directory(workspace),
- // Cron's existing host command inherits network access; this
- // passthrough resource does not add a sandbox restriction.
- network: contract::NetworkPolicy::Open,
- resources: contract::ResourceLimits::default(),
- ports: Vec::new(),
- env: BTreeMap::new(),
- },
- )
- .await
- .map_err(|_| anyhow::anyhow!("TinyBox could not create a command resource"))?;
-
- let process = tinybox::reserve(config, contract::ReserveRequest::Process(resource.clone()))
- .await
- .map_err(|_| anyhow::anyhow!("TinyBox could not reserve a command process"))?;
- 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
- }
- .await;
- let close = tinybox::close(config, resource).await;
- match (result, close) {
- (Ok(output), Ok(())) => Ok(output),
- (Err(error), Ok(())) => Err(error),
- (Ok(_), Err(_)) => anyhow::bail!("TinyBox did not acknowledge command cleanup"),
- (Err(error), Err(_)) => Err(error),
- }
-}
-
#[cfg(feature = "modules")]
async fn execute_owned(
config: &Config,
diff --git a/crates/openhuman-core/src/sandbox/shell_exec_fixture.rs b/crates/openhuman-core/src/sandbox/shell_exec_fixture.rs
index 743c601250..4f80ca0c65 100644
--- a/crates/openhuman-core/src/sandbox/shell_exec_fixture.rs
+++ b/crates/openhuman-core/src/sandbox/shell_exec_fixture.rs
@@ -13,15 +13,22 @@ const SNAPSHOT: &[&str] = &[
];
pub(crate) async fn run(run: NativeShellRun) -> anyhow::Result<SandboxExecResult> {
- let mut command = tokio::process::Command::new(if cfg!(windows) { "cmd" } else { "sh" });
+ let bash = ["/usr/bin/bash", "/bin/bash"]
+ .into_iter()
+ .find(|path| std::path::Path::new(path).exists());
+ let mut command = tokio::process::Command::new(if cfg!(windows) {
+ "cmd"
+ } else {
+ bash.unwrap_or("sh")
+ });
if cfg!(windows) {
command.arg("/C").arg(&run.command);
- } else if run.preserve_pipeline_status {
- command.arg("-c").arg(&run.command);
- } else {
+ } else if bash.is_some() && !run.preserve_pipeline_status {
command
.arg("-c")
- .arg(format!("set -o pipefail 2>/dev/null\n{}", run.command));
+ .arg(format!("set -o pipefail\n{}", run.command));
+ } else {
+ command.arg("-c").arg(&run.command);
}
command.env_clear();
for name in SNAPSHOT {