Skip to content

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

feat(sandbox): add docker policy validation for dangerous settings

Steven Enamakelf437d6c0afa4
diff --git a/crates/openhuman-core/src/sandbox/docker.rs b/crates/openhuman-core/src/sandbox/docker.rs
index 1b324258c9..fcbf5d7ab8 100644
--- a/crates/openhuman-core/src/sandbox/docker.rs
+++ b/crates/openhuman-core/src/sandbox/docker.rs
@@ -215,6 +215,46 @@ fn docker_handle_for_status(available: bool) -> SandboxBackendHandle {
}
}
+/// Validate that a sandbox policy's Docker configuration doesn't have
+/// dangerous settings (host network, privileged mounts, etc.).
+pub fn validate_docker_policy(policy: &SandboxPolicy) -> Result<(), Vec<String>> {
+ let mut issues = Vec::new();
+
+ if let Some(overrides) = &policy.docker_overrides {
+ if overrides.network.as_deref() == Some("host") {
+ issues.push("Docker sandbox uses host network — defeats network isolation".into());
+ }
+ }
+
+ // Check for dangerous mount paths.
+ let dangerous_mounts = ["/", "/etc", "/var/run/docker.sock", "/proc", "/sys"];
+ for mount in &policy.read_only_mounts {
+ let path_str = mount.to_string_lossy();
+ for &dangerous in &dangerous_mounts {
+ if path_str == dangerous {
+ issues.push(format!(
+ "Dangerous read-only mount: {path_str} — could leak host secrets"
+ ));
+ }
+ }
+ }
+
+ let workspace_str = policy.workspace_root.to_string_lossy();
+ for &dangerous in &dangerous_mounts {
+ if workspace_str == dangerous {
+ issues.push(format!(
+ "Workspace root is a dangerous path: {workspace_str}"
+ ));
+ }
+ }
+
+ if issues.is_empty() {
+ Ok(())
+ } else {
+ Err(issues)
+ }
+}
+
#[cfg(test)]
#[path = "docker_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/sandbox/docker_tests.rs b/crates/openhuman-core/src/sandbox/docker_tests.rs
index b887cb1cce..c5f7eec1a3 100644
--- a/crates/openhuman-core/src/sandbox/docker_tests.rs
+++ b/crates/openhuman-core/src/sandbox/docker_tests.rs
@@ -15,28 +15,50 @@ fn test_policy() -> SandboxPolicy {
}
}
-/// Policy validation (host network, dangerous mounts) is owned by the TinyBox
-/// module since contract 1.17; the host must forward the policy unchanged so
-/// the module can refuse it.
-#[cfg(feature = "modules")]
#[test]
-fn host_network_and_dangerous_mounts_reach_the_module_unfiltered() {
+fn validate_docker_policy_accepts_safe_config() {
+ let policy = test_policy();
+ assert!(validate_docker_policy(&policy).is_ok());
+}
+
+#[test]
+fn validate_docker_policy_rejects_host_network() {
+ let mut policy = test_policy();
+ policy.docker_overrides = Some(DockerOverrides {
+ network: Some("host".into()),
+ ..DockerOverrides::default()
+ });
+ let issues = validate_docker_policy(&policy).unwrap_err();
+ assert!(issues.iter().any(|i| i.contains("host network")));
+}
+
+#[test]
+fn validate_docker_policy_rejects_dangerous_mounts() {
let mut policy = test_policy();
- policy.workspace_root = PathBuf::from("/etc");
policy.read_only_mounts = vec![PathBuf::from("/var/run/docker.sock")];
+ let issues = validate_docker_policy(&policy).unwrap_err();
+ assert!(issues.iter().any(|i| i.contains("docker.sock")));
+}
+
+#[test]
+fn validate_docker_policy_rejects_root_workspace() {
+ let mut policy = test_policy();
+ policy.workspace_root = PathBuf::from("/");
+ let issues = validate_docker_policy(&policy).unwrap_err();
+ assert!(issues.iter().any(|i| i.contains("dangerous path")));
+}
+
+#[test]
+fn validate_docker_policy_multiple_issues() {
+ let mut policy = test_policy();
+ policy.workspace_root = PathBuf::from("/etc");
+ policy.read_only_mounts = vec![PathBuf::from("/proc")];
policy.docker_overrides = Some(DockerOverrides {
network: Some("host".into()),
..DockerOverrides::default()
});
- let request = SandboxExecRequest {
- command: "true".into(),
- env: Default::default(),
- timeout: std::time::Duration::from_secs(1),
- };
- let run = build_docker_request(&policy, &request).expect("host adapter forwards policy");
- assert_eq!(run.workspace, "/etc");
- assert_eq!(run.network.as_deref(), Some("host"));
- assert_eq!(run.read_only_mounts, vec!["/var/run/docker.sock".to_owned()]);
+ let issues = validate_docker_policy(&policy).unwrap_err();
+ assert!(issues.len() >= 3);
}
#[cfg(feature = "modules")]