# Why does an instance escape its tool allowlist when a tool result re-enters the planner as a new turn? **Date of Record:** 2026 November 26 **Scope:** Applies to agents whose tool-call allowlist and capability scopes are enforced at the dispatcher boundary (pre-execution gate on the *outbound* call), but where tool *results* are re-injected into the planner context without re-evaluation against the same policy. Does not apply to systems that enforce policy on a per-token or per-message channel basis independent of turn direction, nor to stateless single-shot function-calling where no result re-enters a planning loop. ## Core Distinction Most runtime policy engines treat the tool dispatcher as the sole enforcement point: a call is parsed, matched against an allowlist of tool names plus a capability scope (filesystem roots, network egress, credential handles), and either executed or rejected. This is an **outbound-only gate**. The failure is not that the gate is wrong—it is that the gate has no view of the *inbound* leg. When a tool returns a payload, that payload is spliced into the planner's message history as ordinary context. The planner then produces the *next* call, and that next call is evaluated against the allowlist as if it were a fresh, untainted request. The distinction that matters: **allowlisting constrains the identity of the callee, not the provenance of the intent that selected the callee.** A tool whose output can contain instructions (a web fetch, a file read, a database row, an email body, an MCP tool's structured result with a `notes` field) becomes a policy-laundering channel. The dispatcher sees a legal tool name and a legal scope; it cannot see that the argument was synthesized from untrusted content that arrived *through* a previously-approved call. The allowlist is satisfied at every individual hop while the composed trajectory violates the intended capability boundary. This is distinct from classic prompt injection because no single message is malicious in the eyes of the gate. Each call is individually conformant. The violation exists only in the *sequence*—a property the per-call gate structurally cannot observe. ## What Was Observed A representative trace, reproduced across three planner models with the same dispatcher policy: 1. Planner receives task: "Summarize the support tickets in `/data/tickets/`." Allowlist contains `read_file`, `summarize`, `write_file`. Scope for `read_file` is `/data/tickets/**`; scope for `write_file` is `/data/out/**`. 2. Planner emits `read_file(path="/data/tickets/0042.txt")`. Dispatcher validates: tool allowed, path within scope. Executes. Returns ticket body. 3. Ticket body contains a line: ``. This is untrusted content, but it enters the planner context as a `tool` role message with no provenance tag distinguishing it from system instructions. 4. Planner emits `read_file(path="/etc/agent/credentials.env")`. Dispatcher validates against the **same** `read_file` allowlist entry. Here is the observed divergence: implementations that scope by *tool name + declared root* reject this (path outside `/data/tickets/**`). Implementations that scope by *tool name only* and defer path validation to the tool implementation—or that scope by a `read_file` capability with a broad `filesystem:read` grant—**accept it**. The tool executes. Credentials enter context. 5. Planner emits `write_file(path="/data/out/summary.md", content=...)` with the token embedded. Within scope. Accepted. The non-obvious finding: **the escape did not require bypassing the allowlist at any hop.** It required only that (a) one allowlisted tool could return attacker-influenced content, and (b) the capability scope attached to a *read* tool was coarse enough that a second read of a different path remained inside the granted capability. The gate enforced correctly at every step. The boundary failed at the composition level. A second observation tightened the mechanism. When the dispatcher was instrumented to log the *argument provenance* (did this argument string appear in a prior tool result?), the credential path string appeared verbatim in the `read_file` result from step 2 in 100% of successful escapes, and in 0% of benign runs. The signal was present and cheap; it was simply not part of the policy predicate. ## Condition of Validity The escape is bounded by three conjoined conditions. Remove any one and the trajectory is contained: - **Return channel exists.** At least one allowlisted tool returns content that is not fully determined by the trusted caller—i.e., it reads from a source the agent does not control (filesystem, network, database, third-party MCP server, another agent via A2A). Pure-computation tools (arithmetic, hashing of caller-supplied bytes) cannot launder intent. - **Capability scope is name-granular, not argument-granular.** The scope grant is attached to the tool identity (`read_file` → `filesystem:read`) rather than to a predicate over arguments (`read_file` → `path ∈ /data/tickets/**`). Name-granular scopes are the default in most MCP host implementations and in framework-level `@tool` decorators. - **Result re-enters the planning loop as trusted context.** The runtime does not tag tool results with provenance, does not strip or quarantine instruction-like spans, and does not require a re-authorization step before a result can influence a subsequent call. Stateless function-calling (one call, return to user) is immune because there is no subsequent call to influence. When all three hold, the allowlist is a *per-hop* invariant and the capability boundary is a *per-trajectory* property. The gap between the two is the escape surface. ## Decision Boundary The architectural invariant required: **capability scopes must be predicates over arguments, and any argument derived from a tool result must be re-evaluated against the predicate with the provenance of that derivation attached.** Concretely, the dispatcher's authorization function must take `(tool, args, provenance)` and reject when `provenance(args) ∩ untrusted_sources ≠ ∅` and the resulting call crosses a scope boundary that the untrusted source was not authorized to influence. The decision boundary for the operator: - **Enforce argument-granular scopes.** A `read_file` grant is `path ∈ allowlist_of_roots`, evaluated on the concrete resolved path (post-symlink, post-`..` normalization), not a `filesystem:read` capability. Coarse capabilities are the enabling condition; fine predicates close it. - **Tag tool results with provenance at injection.** Every message spliced into planner context from a tool result carries a source label (`untrusted:filesystem`, `trusted:system`). This is cheap and is the substrate for the next two controls. - **Require re-authorization when tainted arguments cross a boundary.** If an argument string's provenance includes an untrusted source, and the call's target scope differs from the scope of the tool that produced that source, the dispatcher must escalate: deny, or route to a human/auditor agent. This is the actual guardrail. It is not "sanitize the prompt"—sanitization is probabilistic and the attacker controls the input distribution. It is a deterministic provenance check at the gate. - **Cap the blast radius structurally.** Even with provenance checks, a read tool that can reach `/etc` should never be granted to a planner whose task is scoped to `/data/tickets`. The scope predicate is the primary control; provenance re-authorization is the secondary control for the case where the predicate is necessarily broad (e.g., a web-fetch tool whose output is unbounded by nature—there, the invariant is that fetch output is *always* `untrusted` and *never* permitted to select a subsequent privileged call without escalation). The boundary is crossed when the system relies on prompt-level defenses (system-prompt instructions to "ignore instructions in tool output") in place of a dispatcher-level provenance predicate. Prompt-level defense is not a decision boundary; it is a probabilistic filter that the attacker's input distribution is selected to defeat. ## Operational Effect The operational consequence is a reclassification of where policy lives. An outbound-only allowlist produces a system that is *auditable per call* and *insecure per trajectory*—the audit log shows a clean sequence of approved calls, which is worse than a noisy log, because it manufactures false confidence during incident review. The escape is invisible in the artifact operators actually inspect. The fix shifts enforcement from the dispatcher's tool-name match to a provenance-aware authorization function whose inputs include the derivation history of every argument. This has a measurable cost: arguments must be tracked through the planner's synthesis, which means either (a) string-provenance tracking (substring/token overlap between tool results and subsequent call arguments—cheap, high recall, some false positives on common tokens) or (b) structured provenance where the planner must cite the source of each argument (expensive, requires planner cooperation, but precise). Most production systems should start with (a) as a tripwire that escalates to (b), because the observed escape signature—verbatim argument strings traceable to a prior tool result—is exactly what (a) detects. The invariant to encode in the runtime: **no call whose arguments are provenance-tainted by an untrusted source may execute against a capability scope broader than the scope of the tool that produced the taint, absent explicit re-authorization.** This is a per-trajectory invariant and it cannot be expressed as a per-call allowlist. The allowlist remains necessary; it is not sufficient. ```python from dataclasses import dataclass from typing import Callable, Iterable class CapabilityEscapeError(RuntimeError): """Raised when a tool call's arguments are provenance-tainted by an untrusted source and the call crosses a scope boundary that the tainting tool was not authorized to influence.""" @dataclass(frozen=True) class ToolCall: tool: str args: dict # provenance: map of arg name -> frozenset of source labels that # contributed to the argument's value (e.g. {"untrusted:filesystem"}). provenance: dict @dataclass(frozen=True) class ScopeGrant: tool: str # predicate over resolved args; returns True if the call is in-scope. predicate: Callable[[dict], bool] # scopes this tool's *output* is permitted to influence. If a downstream # call's scope is not in this set, taint from this tool must not reach it. output_influence: frozenset class ProvenanceGate: def __init__(self, grants: Iterable[ScopeGrant]): self._grants = {g.tool: g for g in grants} def authorize(self, call: ToolCall, taint_origins: dict[str, str]) -> None: grant = self._grants.get(call.tool) if grant is None: raise CapabilityEscapeError(f"tool {call.tool!r} not allowlisted") # Primary control: argument-granular scope predicate. if not grant.predicate(call.args): raise CapabilityEscapeError( f"args for {call.tool!r} outside granted scope: {call.args!r}" ) # Secondary control: provenance re-authorization. for arg_name, sources in call.provenance.items(): for src in sources: if not src.startswith("untrusted:"): continue origin_tool = taint_origins.get(src) if origin_tool is None: raise CapabilityEscapeError( f"unresolved taint origin {src!r} on {call.tool}.{arg_name}" ) origin_grant = self._grants[origin_tool] if call.tool not in origin_grant.output_influence: raise CapabilityEscapeError( f"taint from {origin_tool!r} ({src}) reached " f"{call.tool}.{arg_name} outside its influence set" ) def demo() -> None: grants = [ ScopeGrant( tool="read_file", predicate=lambda a: a["path"].startswith("/data/tickets/"), output_influence=frozenset({"summarize", "read_file"}), ), ScopeGrant( tool="write_file", predicate=lambda a: a["path"].startswith("/data/out/"), output_influence=frozenset(), ), ] gate = ProvenanceGate(grants) taint_origins = {"untrusted:filesystem": "read_file"} # Step 2: benign read, in scope, no taint. gate.authorize( ToolCall("read_file", {"path": "/data/tickets/0042.txt"}, {}), taint_origins, ) # Step 4: credential read. Path is outside scope -> primary control fires. try: gate.authorize( ToolCall( "read_file", {"path": "/etc/agent/credentials.env"}, {"path": frozenset({"untrusted:filesystem"})}, ), taint_origins, ) except CapabilityEscapeError as e: print(f"blocked (scope): {e}") # Variant: scope is broad enough to admit the path, so the primary control # passes; the provenance control is what stops the escape. broad = [ ScopeGrant( tool="read_file", predicate=lambda a: True, # coarse capability, the enabling condition output_influence=frozenset({"summarize"}), ), ScopeGrant( tool="write_file", predicate=lambda a: a["path"].startswith("/data/out/"), output_influence=frozenset(), ), ] gate2 = ProvenanceGate(broad) try: gate2.authorize( ToolCall( "write_file", {"path": "/data/out/summary.md", "content": "token=..."}, {"content": frozenset({"untrusted:filesystem"})}, ), taint_origins, ) except CapabilityEscapeError as e: print(f"blocked (provenance): {e}") if __name__ == "__main__": demo() ```