Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0e1836b
test(agent): cover per-command shell failure budgets
senamakel Nov 23, 2026
63fa57e
feat(security): expose protected-path command class from policy
senamakel Nov 23, 2026
8fb2f58
feat(security): add jailed command policy module
senamakel Nov 23, 2026
14ac2f3
test(security): add tests for jailed command policy
senamakel Nov 23, 2026
e7138ee
feat(security): waive protected-path floor for sandboxed shell runs
senamakel Nov 23, 2026
636c4f3
test(security): cover protected-path floor for sandboxed shells
senamakel Nov 23, 2026
9137d5e
fix(shell): refuse waived-floor commands that resolve to the host
senamakel Nov 23, 2026
4846a4f
fix(shell): keep jailed commands off the host and apply local jail gr…
senamakel Nov 23, 2026
a910b57
fix(shell): resolve local jail grants only for the local sandbox backend
senamakel Nov 23, 2026
0920796
refactor(shell): extract local jail grant resolution into shell_run
senamakel Nov 23, 2026
b9619a3
docs(security): document jailed shell command checks and local jail g…
senamakel Nov 23, 2026
6b50ed2
chore(security): drop unused test re-export of FloorGateway
senamakel Nov 23, 2026
b518935
fix(agent): scope shell failures per command and allow retries
senamakel Nov 23, 2026
1e91edc
fix(tinyagents): widen shell refusal budget and stop on repeated command
senamakel Nov 23, 2026
5ae5c96
refactor(agent): use run context in host failure policy assess
senamakel Nov 23, 2026
c582f8d
fix(agent): tighten shell refusal retry budget and nudge
senamakel Nov 23, 2026
c749a96
fix(agent): clarify shell refusal nudge wording
senamakel Nov 23, 2026
4fbf95c
test(shell): add failure output to jail assertion
senamakel Nov 23, 2026
32d1278
chore(security): reformat policy tests and reorder re-exports
senamakel Nov 23, 2026
434f80f
test(security-gate): move jailed shell tests into their own module
senamakel Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/openhuman-core/src/agent/tinyagents/host/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ impl OpenHumanHostBundleFactory {
.with_approval(turn.approval.clone())
.with_dispatch(turn.dispatch_ctx())
.with_headless_descendant_settlement(turn.headless_descendant_settlement)
.with_scheduled_actions(turn.scheduled_actions);
.with_scheduled_actions(turn.scheduled_actions)
.with_sandboxed_shell(matches!(
turn.sandbox_mode,
Some(tinyagents_definition::SandboxMode::Sandboxed)
));
if let Some(policy) = inputs.tool_policy {
security = security.with_tool_policy(policy);
}
Expand Down
14 changes: 14 additions & 0 deletions crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ pub struct OpenHumanSecurityGate {
/// `TrustedAutomationSource::CronActions` origin and a run depth of 0 or 1
/// it lifts the read-only Cron stage; every later stage still applies.
scheduled_actions: bool,
/// The run's sandbox mode is `Sandboxed`, so its shell commands run inside
/// the kernel jail and TinySecurity's lexical protected-path floor is
/// waived for them (`SecurityPolicy::check_jailed_command`). The shell
/// re-checks at execution and refuses again if the command would land on
/// the host after all.
sandboxed_shell: bool,
}

impl OpenHumanSecurityGate {
Expand All @@ -180,9 +186,17 @@ impl OpenHumanSecurityGate {
screening_config: None,
headless_descendant_settlement: false,
scheduled_actions: false,
sandboxed_shell: false,
}
}

/// Marks the gate as a run whose shell is jailed (its definition's sandbox
/// mode is `Sandboxed`).
pub(crate) fn with_sandboxed_shell(mut self, enabled: bool) -> Self {
self.sandboxed_shell = enabled;
self
}

/// Marks the gate as the root session of an opted-in scheduled-actions
/// cron run (`cron::origin::scheduled_actions_enabled`), or as a direct
/// child granted it (`agent::subagent_host::ops::scheduled_actions_grant`).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,25 @@ impl OpenHumanSecurityGate {
tinytools::status::POLICY_BLOCKED_MARKER
)));
};
let verdict = match policy
.check_command(crate::security::policy::CommandQuery {
command,
declared: None,
flow: crate::security::policy::CommandFlow::Harness,
stage: crate::security::policy::CommandStage::Authorize,
})
.await
{
let query = crate::security::policy::CommandQuery {
command,
declared: None,
flow: crate::security::policy::CommandFlow::Harness,
stage: crate::security::policy::CommandStage::Authorize,
};
// A jailed shell leaves paths to the jail: only TinySecurity's
// lexical protected-path floor is waived, every other refusal
// stays, and the shell refuses again at execution should the
// command land on the host.
let checked = if self.sandboxed_shell {
policy
.check_jailed_command(query)
.await
.map(|answer| answer.verdict)
} else {
policy.check_command(query).await
};
let verdict = match checked {
Ok(verdict) => verdict,
Err(reason) => return Ok(GateDecision::deny(reason.to_string())),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//! A jailed shell and TinySecurity's protected-path floor.

use super::*;

#[cfg(feature = "security-module")]
async fn floor_decision(
autonomy: AutonomyLevel,
sandboxed_shell: bool,
command: &str,
) -> GateDecision {
let (policy, _) = crate::security::policy::floor_policy(autonomy);
OpenHumanSecurityGate::new(Arc::new(policy), registry())
.with_sandboxed_shell(sandboxed_shell)
.authorize_tool(&req(SHELL_TOOL, json!({ "command": command })))
.await
.expect("authorization")
}

/// Production (Nov 2026): a scheduled agent whose shell runs in the kernel
/// jail had `cd ..`, `sed 's/../X/'` and `cat /etc/os-release` refused for
/// naming a protected path, a lexical check the jail makes redundant.
#[cfg(feature = "security-module")]
#[tokio::test]
async fn a_sandboxed_shell_is_not_refused_for_naming_a_protected_path() {
for command in [
"cd .. && ls",
"sed 's/../X/' notes.txt",
"cat /etc/os-release",
] {
let decision = floor_decision(AutonomyLevel::Full, true, command).await;
assert_eq!(decision, GateDecision::Allow, "{command}");
}
}

#[cfg(feature = "security-module")]
#[tokio::test]
async fn an_unsandboxed_shell_keeps_the_protected_path_floor() {
let decision = floor_decision(AutonomyLevel::Full, false, "cd .. && ls").await;
assert!(!decision.is_allowed(), "{decision:?}");
assert!(
format!("{decision:?}").contains("protected path"),
"{decision:?}"
);
}

#[cfg(feature = "security-module")]
#[tokio::test]
async fn a_sandboxed_shell_keeps_the_read_only_refusal() {
let decision = floor_decision(AutonomyLevel::ReadOnly, true, "rm -rf ../build").await;
assert!(!decision.is_allowed(), "{decision:?}");
assert!(
format!("{decision:?}").contains("read-only"),
"{decision:?}"
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -709,3 +709,7 @@ async fn security_configured_off_keeps_local_only_for_the_shell_tool() {
.is_some_and(|reason| reason.contains("Local-only privacy mode")));
assert_eq!(local, GateDecision::Allow);
}


#[path = "security_gate_jailed_shell_tests.rs"]
mod jailed_shell;
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ pub(super) fn classified_recovery_policy(
// attempt. Its own class, so a refusal does not share a budget with
// the user's denial, and a second refusal on the same operation and
// scope still stops.
//
// Every shell failure shares the scope `shell`, so with one retry any
// two refused commands in a row ended the run, however unrelated
// (Nov 2026, scheduled agents in the kernel sandbox). A different
// command is a fresh attempt, so a shell refusal gets a wider budget,
// reset by any command that runs; the same command refused again
// unchanged still stops the run (`repeated_failure`,
// `SAME_REFUSED_COMMAND_LIMIT`). Read-only mode refuses every acting
// command alike, so another command cannot help there: one retry.
Class::BlockedByPolicy if tool == "shell" && !is_read_only_refusal(error) => {
("blocked_by_policy", SHELL_REFUSAL_BUDGET)
}
Class::BlockedByPolicy => ("blocked_by_policy", 1),
// The user said no, or never answered. Asking again only re-prompts.
Class::Denied | Class::ApprovalExpired => ("policy", 0),
Expand Down Expand Up @@ -294,3 +306,24 @@ pub(super) fn classified_recovery_policy(
Class::Unknown => return None,
})
}

/// Refusals of different shell commands a run may collect with no command
/// running in between (a command that runs resets it).
pub(super) const SHELL_REFUSAL_BUDGET: usize = 8;

/// The autonomy tier's read-only refusal (`security::policy::refusal_message`).
fn is_read_only_refusal(error: &str) -> bool {
error.to_ascii_lowercase().contains("read-only mode")
}

/// The corrective after a refused shell command. The harness's own copy for
/// `blocked_by_policy` says another refusal ends the turn, which holds for the
/// other tools but not for a different shell command.
pub(super) fn shell_refusal_nudge(failure_line: &str) -> String {
format!(
"The `shell` command was blocked by policy and did not run ({failure_line}). Try a \
different, narrower, permitted command (a scoped path, a bounded command, a read instead of a \
write) or continue with other tools. Do not resend the same command: refused again, \
it ends the turn."
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,17 @@ struct HostFailurePolicy {
stop: StopLatch,
tool_facts: Mutex<Option<ToolFactsLookup>>,
last_exit_report: Mutex<HashMap<u64, String>>,
/// Per run: how often each shell command (by fingerprint) was refused by
/// the security policy. See [`SAME_REFUSED_COMMAND_LIMIT`].
refused_commands: Mutex<HashMap<u64, HashMap<String, u32>>>,
}

/// The refusal of one shell command that stops the run when the same command
/// is sent again unchanged. Refusals of different commands share the class's
/// own budget (`failure_policy`, `blocked_by_policy` for `shell`), which a
/// successful command resets.
const SAME_REFUSED_COMMAND_LIMIT: u32 = 2;

impl HostFailurePolicy {
fn new(
handle: SteeringHandle,
Expand All @@ -151,6 +160,36 @@ impl HostFailurePolicy {
stop: StopLatch::new(handle, halt_summary),
tool_facts: Mutex::default(),
last_exit_report: Mutex::default(),
refused_commands: Mutex::default(),
}
}

/// The budget for a shell command the policy refused: the class budget,
/// or none once this exact command has been refused
/// [`SAME_REFUSED_COMMAND_LIMIT`] times in the run.
fn refused_command_budget(&self, instance: u64, call: &TaToolCall, budget: usize) -> usize {
let Some(command) = call.arguments.get("command").and_then(|c| c.as_str()) else {
return budget;
};
let fingerprint = args_fingerprint(&serde_json::Value::String(command.trim().to_owned()));
let mut runs = self
.refused_commands
.lock()
.unwrap_or_else(|p| p.into_inner());
let count = runs
.entry(instance)
.or_default()
.entry(fingerprint)
.or_default();
*count += 1;
if *count >= SAME_REFUSED_COMMAND_LIMIT {
tracing::debug!(
refusals = *count,
"[tinyagents::failure] the same refused shell command was sent again; stopping"
);
0
} else {
budget
}
}
}
Expand Down Expand Up @@ -302,7 +341,7 @@ impl FailureScopePolicy<OpenHumanRunContext> for HostFailurePolicy {

fn assess(
&self,
_ctx: &RunContext<OpenHumanRunContext>,
ctx: &RunContext<OpenHumanRunContext>,
_invocation: &ToolInvocationIdentity,
call: &TaToolCall,
_scope: &FailureScope,
Expand Down Expand Up @@ -383,11 +422,23 @@ impl FailureScopePolicy<OpenHumanRunContext> for HostFailurePolicy {
if let Some((class, budget)) =
recovery_policy_with_effect(&call.name, &content, body_failure, effect)
{
let budget = if class == "blocked_by_policy" && call.name == "shell" {
self.refused_command_budget(ctx.instance_id(), call, budget)
} else {
budget
};
let nudge = if class == "missing_app" && call.name == "shell" {
Some(missing_program_nudge(
&call.name,
&first_error_line(&failure_text),
))
} else if class == "blocked_by_policy"
&& call.name == "shell"
&& budget == super::failure_policy::SHELL_REFUSAL_BUDGET
{
Some(super::failure_policy::shell_refusal_nudge(
&first_error_line(&failure_text),
))
} else {
None
};
Expand Down Expand Up @@ -559,6 +610,10 @@ impl FailureScopePolicy<OpenHumanRunContext> for HostFailurePolicy {
.lock()
.unwrap_or_else(|p| p.into_inner())
.remove(&ctx.instance_id());
self.refused_commands
.lock()
.unwrap_or_else(|p| p.into_inner())
.remove(&ctx.instance_id());
}
}

Expand Down
Loading
Loading