Skip to content

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

fix(system): pass install environment to exec gate and match vars case-insensitively

Steven Enamakel2baf5df3b75c
diff --git a/crates/openhuman-core/src/tools/impl/system/exec_adapters.rs b/crates/openhuman-core/src/tools/impl/system/exec_adapters.rs
index c3b73b6780..349dd0a24f 100644
--- a/crates/openhuman-core/src/tools/impl/system/exec_adapters.rs
+++ b/crates/openhuman-core/src/tools/impl/system/exec_adapters.rs
@@ -84,7 +84,7 @@ impl ExecGate for InstallGate {
}
Ok(ExecPermit {
action_dir: PathBuf::from(&self.security.workspace_dir),
- environment: Default::default(),
+ environment: self.environment.clone(),
backend_selection: "native".into(),
backend_capability: ExecBackendCapability::new(NativeExecCapability),
})
diff --git a/crates/openhuman-core/src/tools/impl/system/install_tool.rs b/crates/openhuman-core/src/tools/impl/system/install_tool.rs
index 903b5845ed..d42e38b5fa 100644
--- a/crates/openhuman-core/src/tools/impl/system/install_tool.rs
+++ b/crates/openhuman-core/src/tools/impl/system/install_tool.rs
@@ -48,7 +48,13 @@ impl InstallToolTool {
}
fn install_environment() -> std::collections::BTreeMap<std::ffi::OsString, std::ffi::OsString> {
- let allowed = [
+ filter_install_environment(std::env::vars_os())
+}
+
+fn filter_install_environment(
+ variables: impl IntoIterator<Item = (std::ffi::OsString, std::ffi::OsString)>,
+) -> std::collections::BTreeMap<std::ffi::OsString, std::ffi::OsString> {
+ const ALLOWED: &[&str] = &[
"PATH",
"HOME",
"USERPROFILE",
@@ -73,8 +79,15 @@ fn install_environment() -> std::collections::BTreeMap<std::ffi::OsString, std::
"XDG_DATA_HOME",
"XDG_STATE_HOME",
];
- std::env::vars_os()
- .filter(|(name, _)| allowed.iter().any(|allowed| name == allowed))
+ variables
+ .into_iter()
+ .filter(|(name, _)| {
+ name.to_str().is_some_and(|name| {
+ ALLOWED
+ .iter()
+ .any(|allowed| name.eq_ignore_ascii_case(allowed))
+ })
+ })
.collect()
}
diff --git a/crates/openhuman-core/src/tools/impl/system/install_tool_tests.rs b/crates/openhuman-core/src/tools/impl/system/install_tool_tests.rs
index f754187ded..dd71c4996d 100644
--- a/crates/openhuman-core/src/tools/impl/system/install_tool_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/system/install_tool_tests.rs
@@ -169,3 +169,25 @@ async fn install_backend_receives_only_the_explicit_install_environment() {
"the installer backend must receive the host-approved environment"
);
}
+
+#[test]
+fn install_environment_filters_host_variables_without_dropping_package_manager_paths() {
+ let filtered = filter_install_environment([
+ (OsString::from("PATH"), OsString::from("/tools/bin")),
+ (OsString::from("HOME"), OsString::from("/home/operator")),
+ (OsString::from("CARGO_HOME"), OsString::from("/home/operator/.cargo")),
+ (OsString::from("SystemRoot"), OsString::from("C:\\Windows")),
+ (OsString::from("GH_TOKEN"), OsString::from("secret")),
+ (OsString::from("AWS_ACCESS_KEY_ID"), OsString::from("secret")),
+ ]);
+
+ assert_eq!(filtered.get("PATH"), Some(&OsString::from("/tools/bin")));
+ assert_eq!(filtered.get("HOME"), Some(&OsString::from("/home/operator")));
+ assert_eq!(
+ filtered.get("CARGO_HOME"),
+ Some(&OsString::from("/home/operator/.cargo"))
+ );
+ assert_eq!(filtered.get("SystemRoot"), Some(&OsString::from("C:\\Windows")));
+ assert!(!filtered.contains_key("GH_TOKEN"));
+ assert!(!filtered.contains_key("AWS_ACCESS_KEY_ID"));
+}