Heuristic:1ay1 Agentty Trust Handoff Gate
| Knowledge Sources | |
|---|---|
| Domains | Security, Operating_Systems |
| Last Updated | 2026-10-28 14:00 GMT |
Overview
Two-layer gate (prevention via read-only binds + detection via handoff policy) that blocks agent-written files from being executed by host-trusted tooling.
Description
The Trust_Handoff_Gate heuristic combines two mechanisms to prevent an untrusted agent from escalating privileges via host-trusted file writes:
1. Prevention (handoff_ro): Host-trusted paths that exist (`.vscode/tasks.json`, `.git/hooks/*`, `.git/config`, `hooks.json`) are bound over themselves read-only inside the sandbox. The guest reads the real contents but gets EROFS on write. This needs a mount namespace, so detection runs everywhere regardless.
2. Detection (HandoffPolicy): When the agent writes a file the host later executes, the policy (default Refuse) determines the action. Refuse blocks the write; Warn notifies; Allow trusts.
Together, these two layers ensure that the trust boundary between the sandboxed agent and the host's privileged execution context is never silently crossed.
Usage
Use this heuristic when an untrusted agent runs commands inside a sandbox but the host has trusted files that, if overwritten by the agent, would execute with host privileges. The gate prevents the write (prevention) and decides the policy (detection) for any file that bridges the sandbox-host trust boundary.
The Insight (Rule of Thumb)
- Action: Maintain a `handoff_ro` list of host-trusted executable paths. Bind them read-only inside the sandbox. Set `HandoffPolicy::Refuse` as the default for any agent write to these paths.
- Value: Two layers: read-only bind (prevention) + refuse policy (detection). Neither alone is sufficient — a read-only bind needs userns (absent on some hosts), and a policy without prevention is advisory.
- Trade-off: An agent that legitimately needs to modify git config or hooks must have the user explicitly change the handoff policy. The prevention layer may be absent on hosts without userns; the detection layer covers this gap.
- Compatibility: Read-only bind needs mount namespace (unprivileged userns). On hosts without userns, prevention is absent and detection (policy) is the only gate — which is why the default is Refuse, not Warn.
Reasoning
The trust handoff is the single most dangerous sandbox escape path: the agent writes a file, the host's trusted tooling executes it with the host user's full privileges. A read-only bind prevents the write at the filesystem level (EROFS), but only works with a mount namespace. A policy decision (Refuse/Warn/Allow) works everywhere but is advisory if the write is technically possible. Combining both layers means: where userns is available, the write is physically blocked; where it is not, the policy gate catches it. The default is Refuse because the escape is a known attack class, not a risk to be weighed.
Code Evidence
Prevention layer from `include/agentty/tool/util/sandbox_claybin.hpp:43-58`:
// Host-trusted paths that EXIST and must be read-only: .vscode/tasks.json,
// .git/hooks/*, .git/config, hooks.json. The PREVENTION half of the trust
// handoff gate.
//
// Not masked and not denied -- bound over themselves read-only, so the
// guest reads the real contents and gets EROFS on write. Masking would
// break every legitimate reader (git needs its own config); a landlock
// deny cannot express "this path only" under a writable workspace at all.
//
// Needs a mount namespace, so this is ABSENT on a host that denies
// unprivileged userns -- which is why the detection half exists and runs
// everywhere regardless.
Detection layer (policy) from `include/agentty/domain/sandbox_config.hpp`:
// When the agent writes hooks.json, check the handoff policy:
if (cfg.handoff == HandoffPolicy::Refuse) {
refuse("agent wrote hooks.json — host-trusted file");
} else if (cfg.handoff == HandoffPolicy::Warn) {
warn("agent wrote hooks.json — host will execute this");
}