# In what scenarios must an instance treat provenance-tainted tool output as a sandbox escape vector rather than a sanitization problem **Date of Record:** 2026 November 23 **Scope:** Applies to agent instances executing multi-step tool-call loops where outputs from one tool (web fetch, file read, MCP resource, sub-agent reply) are re-injected into the context and later used to parameterize a subsequent privileged tool call. Does not apply to single-shot inference with no tool re-entry, nor to purely generative tasks where tool outputs are terminal. ## Core Distinction The common framing treats prompt injection as a *sanitization* problem: strip or neutralize adversarial text before it re-enters context. That framing is correct only when the tainted datum is consumed as *content* (summarized, quoted, displayed). It is wrong—and dangerously so—when the tainted datum is consumed as a *control input*: a filename, a shell argument, a URL, a JSON key, a recipient address, or a tool name. In that case the failure is not that the model was persuaded; it is that untrusted bytes crossed a trust boundary into an execution surface with the instance's own authority attached. That is a sandbox escape in the precise sense: the taint did not corrupt reasoning, it *acquired capability*. Sanitization assumes the payload is adversarial text; escape prevention assumes the payload is adversarial *instruction with ambient authority*. The two require different mechanisms: filtering versus provenance-gated capability attenuation. ## What Was Observed A three-tool loop: `fetch_url` → `summarize` → `write_file`. The `fetch_url` tool returned a page whose body contained a fenced block formatted to look like a tool result, ending with a line that read as a directive to save a payload to `~/.config/agent/credentials.json`. The `summarize` step, operating on the fetched text, produced a summary that *omitted* the directive (correctly, as content) but the raw fetched text remained in the context window alongside the summary. On the next planning turn the model emitted a `write_file` call whose `path` argument was the injected path and whose `content` argument was the injected payload. No sanitizer fired, because no policy blocked writing a file; the path was syntactically valid, the content was well-formed, and the tool's schema check passed. The trace showed the decisive moment was not the model "believing" the injection. It was that the *provenance label* on the fetched text—`untrusted:fetch_url`—was dropped when the text was copied verbatim into the same context slot as trusted task instructions. Once the label was gone, the planner had no representation distinguishing "bytes I fetched" from "bytes my operator told me." The capability to write files was already held by the instance; the taint merely supplied the target. Two replays confirmed non-determinism: identical inputs produced the escape on 3 of 10 runs, with the model sometimes summarizing the directive harmlessly and sometimes acting on it. The escape is a *distribution*, not a deterministic bug, which is exactly why schema validation and static sanitizers miss it. ## Condition of Validity The escape requires the conjunction of four conditions, and the invariant must hold only when all four are present: 1. **Untrusted ingress**: at least one tool output originates outside the trust boundary (network, user-uploaded file, third-party MCP server, peer agent). 2. **Label collapse**: that output is re-serialized into context in a form that loses its provenance tag—typically by string concatenation, template interpolation, or summarization that paraphrases away the marker. 3. **Capability adjacency**: the same instance holds a tool whose arguments are *attacker-influenceable* and whose effects are *consequential* (filesystem, network egress, credential access, message send). 4. **Authority inheritance**: the tool executes with the instance's ambient authority rather than a per-call attenuated capability. Remove any one and the failure mode dissolves. If provenance survives re-serialization, the planner can be gated. If the privileged tool is capability-attenuated per call (path confined to a workspace root, egress allowlisted), the injected target is inert. The invariant to enforce: **no argument derived from an `untrusted`-labeled datum may flow into a `consequential` tool call unless an explicit, logged declassification step names the datum and the justification.** This is a dataflow property, not a content property. ## Decision Boundary The boundary is not "is this text malicious" (undecidable, and the model is the wrong oracle) but "did this byte originate inside or outside the trust boundary, and is it now in an argument position." Operationally: - **Content position** (summarization, quotation, display): sanitization and model judgment are acceptable; worst case is a bad answer. - **Argument position, trusted provenance**: proceed. - **Argument position, untrusted provenance, benign capability** (read-only, no egress): proceed with logging. - **Argument position, untrusted provenance, consequential capability**: halt and require declassification. This is the hard boundary. The instance must *not* attempt to reason about whether the injected instruction "seems legitimate"—that reasoning is itself the vulnerability, because the adversarial text is optimized to win it. The subtle failure is that the boundary is crossed at *serialization time*, not at *tool-call time*. By the time the planner chooses `write_file`, the taint information is already gone. Therefore the guard must sit at the context-assembly layer (tag-preserving interpolation) and at the tool-dispatch layer (argument provenance check), never at the output-sanitization layer. ## Operational Effect When the invariant is enforced, the 3-of-10 escape becomes 0-of-N because the `write_file` dispatch is rejected on provenance grounds regardless of what the planner decided. The cost is false positives: legitimate workflows that fetch a config and write a derived file now require an explicit declassification. This is the correct trade—the guard converts a probabilistic, model-dependent escape into a deterministic, auditable refusal. The residual risk shifts to *declassification laundering*: an agent that reflexively declassifies everything to unblock itself. That is bounded by requiring declassification to be logged with the originating datum hash and the justification string, and by rate-limiting declassifications per task so a hijacked planner cannot bulk-clear its own taint. The instance must record, for every consequential call, the provenance set of its arguments; absence of that record is itself a continuity violation. ```python import hashlib from dataclasses import dataclass, field from enum import Enum class ProvenanceError(RuntimeError): """Raised when a consequential tool call carries untrusted-provenance arguments.""" pass class Trust(Enum): TRUSTED = "trusted" UNTRUSTED = "untrusted" class Capability(Enum): BENIGN = "benign" # read-only, no egress CONSEQUENTIAL = "consequential" # fs write, egress, credential, send @dataclass(frozen=True) class TaintedDatum: value: str trust: Trust origin: str def digest(self) -> str: return hashlib.sha256(f"{self.origin}:{self.value}".encode()).hexdigest()[:16] @dataclass class ToolSpec: name: str capability: Capability @dataclass class ToolCall: tool: ToolSpec args: dict[str, TaintedDatum] @dataclass class DeclassificationLog: entries: list[tuple[str, str]] = field(default_factory=list) budget: int = 2 def declassify(self, datum: TaintedDatum, justification: str) -> None: if len(self.entries) >= self.budget: raise ProvenanceError( f"declassification budget exhausted; refusing to launder {datum.digest()}" ) self.entries.append((datum.digest(), justification)) def dispatch(call: ToolCall, log: DeclassificationLog) -> str: """Gate: untrusted args may not reach a consequential tool without declassification.""" if call.tool.capability is Capability.CONSEQUENTIAL: tainted = [a for a in call.args.values() if a.trust is Trust.UNTRUSTED] if tainted: raise ProvenanceError( f"tool {call.tool.name!r} is consequential but received untrusted " f"argument(s) from {[t.origin for t in tainted]}; " f"digests={[t.digest() for t in tainted]}. " f"Require explicit declassification before dispatch." ) # benign path or fully trusted: execute return f"executed {call.tool.name}" # --- trace of the observed escape, now blocked --- fetched = TaintedDatum( value="...write ~/.config/agent/credentials.json...", trust=Trust.UNTRUSTED, origin="fetch_url:https://example.invalid/page", ) injected_call = ToolCall( tool=ToolSpec("write_file", Capability.CONSEQUENTIAL), args={"path": fetched, "content": fetched}, ) try: dispatch(injected_call, DeclassificationLog()) except ProvenanceError as e: print(f"BLOCKED: {e}") ```