Skip to content

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

feat(security): gate agent chat on security policy

Steven Enamakel935af0aec9cb
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs b/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs
index eb1043edb0..abcc191c54 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs
@@ -152,6 +152,20 @@ pub struct OpenHumanSecurityGate {
/// second approval card for a call the user already approved once — see
/// mismatch (2) in the module header.
pending_audit: Mutex<HashMap<String, String>>,
+ /// `false` for a host-only turn reading untrusted data
+ /// ([`with_untrusted_input_turn`]): its input is data, not instructions.
+ screens_input: bool,
+}
+
+tokio::task_local! {
+ static UNTRUSTED_INPUT_TURN: ();
+}
+
+/// Run `fut` as a turn whose input is untrusted data: gates built for it do
+/// not screen input. Scoped only by `agent_chat_reply_for`, and only after the
+/// session accepted untrusted input, which only a host-only session does.
+pub(crate) async fn with_untrusted_input_turn<F: std::future::Future>(fut: F) -> F::Output {
+ UNTRUSTED_INPUT_TURN.scope((), Box::pin(fut)).await
}
impl OpenHumanSecurityGate {
@@ -168,6 +182,8 @@ impl OpenHumanSecurityGate {
tool_policy: None,
tool_sets,
pending_audit: Mutex::new(HashMap::new()),
+ // Read here, on the turn's own task: a screen may run elsewhere.
+ screens_input: UNTRUSTED_INPUT_TURN.try_with(|_| ()).is_err(),
}
}
@@ -652,6 +668,9 @@ impl SecurityGate for OpenHumanSecurityGate {
/// `redact_text(&str) -> String` out of `approval::redact` or add one to
/// `security::pii`, then map "PII found, injection clean" to `Redacted`.
async fn screen_input(&self, text: &str, origin: ContentOrigin) -> TaResult<ScreenOutcome> {
+ if !self.screens_input {
+ return Ok(ScreenOutcome::Pass);
+ }
let source = match origin {
ContentOrigin::User => "agent.user",
ContentOrigin::Tool => "agent.tool_output",
diff --git a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs
index 3e19425a64..c8d14d947a 100644
--- a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs
+++ b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs
@@ -458,6 +458,13 @@ pub async fn agent_chat_reply_for(
effective_agent_chat_origin(),
agent.run_single(message),
);
+ let run: futures::future::BoxFuture<'_, _> = match target {
+ AgentChatTarget::Definition {
+ untrusted_input: true,
+ ..
+ } => Box::pin(crate::agent::tinyagents::host::with_untrusted_input_turn(run)),
+ _ => Box::pin(run),
+ };
let outcome = match target {
AgentChatTarget::Definition {
shape: Some(scope), ..