Skip to content

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

test(sandbox): cover released tinybox native jail execution

Steven Enamakelc29a37528075
diff --git a/crates/openhuman-core/src/sandbox/native_jail_tests.rs b/crates/openhuman-core/src/sandbox/native_jail_tests.rs
index 51661d7866..2eb54430dc 100644
--- a/crates/openhuman-core/src/sandbox/native_jail_tests.rs
+++ b/crates/openhuman-core/src/sandbox/native_jail_tests.rs
@@ -92,3 +92,90 @@ fn native_jail_environment_keeps_the_sandbox_allowlist_and_scratch_grant() -> an
assert!(!env.keys().any(|name| name.contains("TOKEN") || name.contains("SECRET")));
Ok(())
}
+
+#[cfg(all(feature = "modules", target_os = "linux"))]
+struct BundledModulesRestore(Option<OsString>);
+
+#[cfg(all(feature = "modules", target_os = "linux"))]
+impl Drop for BundledModulesRestore {
+ fn drop(&mut self) {
+ const KEY: &str = "OPENHUMAN_BUNDLED_MODULES";
+ match self.0.take() {
+ Some(value) => std::env::set_var(KEY, value),
+ None => std::env::remove_var(KEY),
+ }
+ }
+}
+
+#[cfg(all(feature = "modules", target_os = "linux"))]
+#[tokio::test]
+#[ignore = "requires the verified TinyBox v0.1.20 archive and a supported Linux jail"]
+async fn released_tinybox_runs_a_native_jail_through_the_pinned_loader() -> anyhow::Result<()> {
+ let _environment_lock = crate::config::TEST_ENV_LOCK.lock().await;
+ const KEY: &str = "OPENHUMAN_BUNDLED_MODULES";
+ let artifact_root = std::env::var_os(KEY)
+ .map(PathBuf::from)
+ .ok_or_else(|| anyhow::anyhow!("set OPENHUMAN_BUNDLED_MODULES to the downloaded v0.1.20 release assets"))?;
+ let _environment_restore = BundledModulesRestore(std::env::var_os(KEY));
+ let record = crate::modules::registry::find("tinybox")
+ .ok_or_else(|| anyhow::anyhow!("TinyBox registry record is missing"))?;
+ let asset = tinybus::module::platform::host_candidates()
+ .iter()
+ .find_map(|host_key| record.asset_for(host_key))
+ .ok_or_else(|| anyhow::anyhow!("the pinned TinyBox release does not support this host"))?;
+ let archive = artifact_root.join(asset.archive);
+ anyhow::ensure!(archive.is_file(), "missing verified release archive: {archive:?}");
+
+ let bundled = tempfile::tempdir()?;
+ let bundle_asset_dir = bundled
+ .path()
+ .join(record.id)
+ .join(record.version)
+ .join(asset.host_key);
+ std::fs::create_dir_all(&bundle_asset_dir)?;
+ let archive_file = std::fs::File::open(&archive)?;
+ let decoder = flate2::read::GzDecoder::new(archive_file);
+ tar::Archive::new(decoder).unpack(&bundle_asset_dir)?;
+ std::fs::copy(&archive, bundle_asset_dir.join(asset.archive))?;
+ std::fs::write(
+ bundle_asset_dir.join(format!("{}.sha256", asset.archive)),
+ format!("{}\n", asset.sha256),
+ )?;
+ std::env::set_var(KEY, bundled.path());
+
+ let install = tempfile::tempdir()?;
+ let mut config = crate::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, "tinybox")
+ .await
+ .map_err(|_| anyhow::anyhow!("the pinned TinyBox release could not be admitted"))?;
+
+ let workspace = tempfile::tempdir()?;
+ let state = tempfile::tempdir()?;
+ let policy = SandboxPolicy {
+ backend: super::super::types::SandboxBackendKind::Local,
+ workspace_root: workspace.path().to_path_buf(),
+ state_dir: state.path().to_path_buf(),
+ read_only_mounts: Vec::new(),
+ read_write_mounts: Vec::new(),
+ allow_network: true,
+ env_passthrough: Vec::new(),
+ docker_overrides: None,
+ };
+ let output = execute(
+ &config,
+ &policy,
+ "printf tinybox-jailed-ok; printf safe-error >&2",
+ workspace.path(),
+ &HashMap::new(),
+ Duration::from_secs(10),
+ false,
+ )
+ .await?;
+ assert!(output.success());
+ assert_eq!(output.stdout, "tinybox-jailed-ok");
+ assert_eq!(output.stderr, "safe-error");
+ Ok(())
+}