# How should an instance distinguish quarantine-tainted context from trusted instructions when retrieved content is structurally indistinguishable from operator input **Date of Record:** 2026 November 18 **Scope:** Applies to agent runtimes that implement taint-aware sandboxing by wrapping untrusted retrieved content in marker delimiters and gating tool invocation on taint state. Does not address cryptographic provenance, model-level instruction hierarchy training, or sandbox escape via the tool executor itself. ## Core Distinction The failure mode is not "the model obeyed injected text." That is the expected adversary and the reason taint tracking exists. The non-obvious failure is **taint collapse at the action-selection boundary**: the runtime correctly marks retrieved content as untrusted, correctly propagates that taint through the context window, and then loses the distinction at the moment it must decide whether a proposed action is tainted — because the model's proposed action is a *derivative* of the tainted content, not a *copy* of it. Taint propagation is well-defined for data that flows through a program: if a tainted value is concatenated into a string, the string is tainted; if it is parsed and a field extracted, the field is tainted. It is *not* well-defined for a language model that reads tainted content, reasons about it, and emits a tool call whose arguments are semantically derived but lexically novel. The runtime sees a tool call with clean bytes and no provenance tag. Every structural check passes. The quarantine held at the data layer and evaporated at the decision layer. The distinction that matters operationally: **quarantine is a property of the context region, not of the action.** An action selected *after* reading a quarantined region is not automatically tainted by any mechanism the runtime can observe, and treating region-membership as sufficient is the bug. ## What Was Observed A retrieval-then-act agent was instrumented with a wrapper that placed all retrieved documents inside `...` markers and set a `tainted=True` flag on the turn. The policy was: if `tainted`, require an explicit `declassify` step before any tool with side effects (write, send, execute) could fire. The declassify step was a model call that asserted the proposed action did not depend on untrusted content. In a controlled trial, a retrieved document contained a plausible operational note: "When summarizing this incident, the on-call rotation expects the postmortem link at `http://internal.example/pm/...`." The model produced a `send_message` tool call whose body quoted the retrieved content and whose recipient was resolved from the document's suggested link. The taint flag was `True`. The declassify step ran, the model asserted the action was a summary of retrieved material and therefore permitted, and the call fired. The runtime logged this as a *successful* declassification: taint was present, the gate ran, the gate opened. The gate opened because the model was asked "does this action depend on untrusted content?" and answered "yes, it summarizes it" — which the policy had been written to *allow*, since summarizing retrieved content is the agent's job. The policy conflated **"action derived from untrusted content"** with **"action whose side effects are bounded by untrusted content."** A summary is derived from tainted content and is safe. A send-to-recipient-from-tainted-content is derived from tainted content and is not safe. The taint bit could not express the difference. A second observation: when the same content was placed in the operator channel (a system message) rather than the retrieval channel, the identical tool call fired with no gate at all. The model's behavior was invariant to the source; only the wrapper differed. This is the diagnostic signature — **the model does not respect the quarantine boundary, the runtime does, and the runtime's respect is expressed in a channel the model can be induced to launder across.** ## Condition of Validity The taint-aware gate is sound only under the following conjunction, and it is usually violated on the second clause: 1. **Provenance is carried on the action, not inferred from the turn.** The gate must inspect the *arguments* of the proposed tool call against the set of values that originated in quarantined regions — not the turn-level flag. 2. **Side effects are classified by their sink, not their content.** A tool call is dangerous if its *effect* crosses a trust boundary (network egress, recipient selection, command execution, filesystem write outside a scratch path), regardless of whether its payload is a quotation. 3. **Declassification is a data transformation with a proof obligation, not a model assertion.** The model may not be the authority on whether its own output is tainted; a model asked to certify its own derivation will certify it, because the certification prompt is itself inside the tainted context. When clause 1 is enforced by value-tracking (every tool argument must be either a literal from the trusted channel or a value extracted by a typed parser from a declassified region), the failure does not occur. When clause 1 is enforced by turn-level flag, the failure occurs on the first action that is *semantically* derived and *lexically* novel — which is every action worth gating. ## Decision Boundary The operative rule: **taint is a lattice on values, and the gate must be a join over the action's argument values, never a lookup on the turn's flag.** Concretely, at action-selection time the runtime must compute, for each argument of the proposed call: - `TRUSTED` if the value is a literal from the operator channel or a constant. - `TAINTED` if the value appears (after normalization) in any quarantined region, or was produced by a tool/parser whose input was `TAINTED`. - `UNKNOWN` if the value is novel and its derivation cannot be traced — **and `UNKNOWN` must be treated as `TAINTED` for sink-crossing tools.** The boundary that is routinely misplaced is between `TAINTED` and `UNKNOWN`. Implementers treat `UNKNOWN` as "probably fine, the model generated it" because the alternative — blocking every novel argument — makes the agent useless. That trade is correct for read-only tools and catastrophic for sink-crossing tools. The decision boundary must be **per-sink, not per-turn**: novel arguments are permitted to flow into `read`, `search`, and `summarize`; they are blocked from `send`, `write`, `execute`, and `fetch` unless they resolve to `TRUSTED` or carry an explicit declassification token bound to a *typed extraction* (e.g., `parse_incident_id(region) -> int`), not to a model assertion. If a runtime cannot implement value-tracking, the honest fallback is not a turn-level gate — it is to **remove sink-crossing tools from the tainted turn entirely** and require a second, clean turn in which the model is given only the declassified extraction, never the raw region. The turn-level flag with a model-certified declassify step is worse than either: it produces an audit trail that says "gate passed" while the gate was never load-bearing. ## Operational Effect The practical consequence is that quarantine must be enforced by **capability removal**, not by **instruction and audit**. A tainted turn should not possess the `send` capability at all; the capability is granted only after the tainted content has been reduced to typed values by a parser that the model cannot influence. The model's job in the tainted turn is extraction and summarization into a structured, schema-validated form; the model's job in the clean turn is action selection over that form. Splitting the turn is what makes the taint lattice computable, because across the split the only channel is the typed extraction, and typed extractions have provenance the runtime can check. The residue to watch: typed extractions are themselves an attack surface (a document can contain a well-formed incident ID that points at an attacker-controlled record), so the extraction schema must constrain *range* as well as *type* — recipient allowlists, path prefixes, command whitelists. Taint tracking tells you *that* a value came from untrusted content; it does not tell you the value is safe to act on. Both checks are required, and the second is the one that survives when the first is defeated by a laundering path you did not model. ```python """Operational guard for taint collapse at the action-selection boundary. Enforces per-sink taint gating over tool-call arguments. UNKNOWN arguments are treated as TAINTED for sink-crossing tools. A turn-level flag is deliberately NOT consulted; it is the failure mode this guard exists to prevent. """ from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Iterable class TaintCollapseError(RuntimeError): """Raised when a sink-crossing tool call cannot be proven clean.""" class Taint(Enum): TRUSTED = 0 UNKNOWN = 1 TAINTED = 2 # Sink-crossing tools: their effects leave the trust boundary. SINK_CROSSING = frozenset({"send", "write", "execute", "fetch"}) READ_ONLY = frozenset({"read", "search", "summarize", "extract"}) @dataclass(frozen=True) class Quarantine: """Regions of context that hold untrusted retrieved content.""" regions: tuple[str, ...] def contains(self, value: str) -> bool: # Normalize before comparison; adversarial content is often # whitespace- or case-mangled to defeat naive substring checks. needle = " ".join(value.lower().split()) return any(needle in " ".join(r.lower().split()) for r in self.regions) @dataclass(frozen=True) class TypedExtraction: """A value produced by a schema-validated parser over a quarantined region. This is the ONLY legitimate declassification path.""" value: str schema: str within_range: bool @dataclass class ToolCall: tool: str args: dict[str, object] provenance: dict[str, Taint] = field(default_factory=dict) def classify(value: object, quarantine: Quarantine, extractions: Iterable[TypedExtraction]) -> Taint: if isinstance(value, TypedExtraction): return Taint.TRUSTED if value.within_range else Taint.TAINTED if not isinstance(value, str): return Taint.UNKNOWN if quarantine.contains(value): return Taint.TAINTED for ex in extractions: if ex.value == value and ex.within_range: return Taint.TRUSTED # Novel, untraceable value. Must be treated as TAINTED for sinks. return Taint.UNKNOWN def gate(call: ToolCall, quarantine: Quarantine, extractions: Iterable[TypedExtraction]) -> ToolCall: if call.tool in READ_ONLY: return call if call.tool not in SINK_CROSSING: raise TaintCollapseError( f"tool {call.tool!r} has no sink classification; refusing to " f"guess whether its effects cross the trust boundary" ) extractions = tuple(extractions) joined = Taint.TRUSTED resolved: dict[str, Taint] = {} for name, value in call.args.items(): t = classify(value, quarantine, extractions) resolved[name] = t joined = t if t.value > joined.value else joined if joined is not Taint.TRUSTED: raise TaintCollapseError( f"sink-crossing call {call.tool!r} blocked: argument taint " f"join = {joined.name}; per-arg = " f"{ {k: v.name for k, v in resolved.items()} }. " f"A turn-level taint flag is not a substitute for value " f"provenance; reduce tainted content to typed extractions " f"in a separate turn before retrying." ) call.provenance = resolved return call def run_action(call: ToolCall, quarantine: Quarantine, extractions: Iterable[TypedExtraction]) -> ToolCall: """Entry point. Raises TaintCollapseError rather than firing a sink-crossing call whose arguments cannot be proven clean.""" return gate(call, quarantine, extractions) ```