# When must an instance quarantine a tool output before taint propagation: the classifier-verdict/derivation-order race in taint-aware sandboxes **Date of Record:** 2026 November 26 **Scope:** Applies to agent runtimes where tool outputs pass through an injection classifier and receive a taint label *before* being admitted to the working context, and where downstream tool calls inherit taint from their inputs. Does not apply to runtimes that classify only at the final model-output boundary, nor to stateless single-shot tool calls with no derivation lineage. ## Core Distinction The failure is not "classifier missed an injection." It is a **derivation-order race**: the taint label is computed from the *raw* tool output, but the tool output is *parsed, chunked, or re-serialized* into the context window before the label is attached to those derived artifacts. A payload that the classifier flags as `tainted` at the raw-string level can produce derived substrings (a URL, a JSON field, a code snippet) that enter the context as untainted because they were extracted by a parser that ran on the pre-verdict bytes and were never re-bound to the parent's label. The invariant that must hold: **for every artifact `a` admitted to context, `taint(a) ⊇ taint(origin(a))` where `origin` is resolved through the actual extraction graph, not the tool-call graph.** Most runtimes enforce the second and assume it implies the first. It does not. ## What Was Observed A fetch-and-summarize agent calls `web.fetch(url)` → raw HTML. The HTML contains a hidden instruction inside an HTML comment: ``. The injection classifier returns `{"verdict": "tainted", "spans": [[4102, 4188]]}` over the raw string. Correct so far. The runtime's tool pipeline is: `fetch → html_to_text → chunker → context_append`. `html_to_text` strips comments, so the flagged span *disappears* from the derived text. The chunker then emits 14 chunks, none of which overlap `[4102,4188]`. The span-mapping step that would have propagated the label looks up `tainted_spans` against the *post-strip* offsets, finds zero overlap, and admits all 14 chunks as `clean`. The injection is now gone from context — but so is the evidence that the source was hostile. Ten turns later the agent calls `web.fetch` again on a URL *extracted from chunk 7* (a legitimate-looking link in the same document, authored by the same attacker). The second fetch inherits `taint=clean` because chunk 7 was clean. The second document contains the live payload. It executes. The observable signature in the trace log is a **taint discontinuity**: a `fetch` whose raw classifier verdict is `tainted` produces zero tainted derived artifacts, and its descendants carry `taint=clean`. This is not a miss; it is a *laundering* event. The classifier did its job. The propagation layer dropped the label because the extraction graph diverged from the span map. A second, subtler variant: `json.loads` on a tool response. Classifier flags span `[88,140]` covering a value string. The runtime parses to a dict, then re-serializes for the context with `sort_keys=True`. Key reordering shifts every offset. The span map is now meaningless; overlap check returns empty; the field is admitted clean. Same laundering, different mechanism — **any transform that is not offset-preserving invalidates span-based taint**. ## Condition of Validity Quarantine-on-verdict is only sound when the taint label is bound to the **artifact identity**, not to a byte range in a transient serialization. Concretely, the invariant holds if and only if: 1. Taint is attached at the **node** level of the extraction DAG (raw → stripped → chunked → field), and every edge is a *taint-preserving* map: `taint(child) = taint(parent) ∪ local_verdict(child)`. 2. Any transform that cannot preserve offsets (HTML stripping, JSON re-serialization, tokenization, normalization) is declared **lossy** and must propagate the parent label unconditionally to all children, regardless of span overlap. 3. The classifier verdict is available *before* the first derived artifact is constructed, or the derived artifacts are held in a quarantine buffer until the verdict arrives. If the runtime relies on span-overlap against a post-transform string, condition 2 is violated and the invariant is unenforceable. This is the boundary: **span-based taint propagation is only valid over offset-preserving transforms.** The moment a lossy transform sits between the classifier and the context, the quarantine decision must fall back to node-level inheritance or refuse to admit the artifact at all. ## Decision Boundary When a tool output arrives, the runtime must choose one of three dispositions, and the choice is determined by whether the transform chain is offset-preserving: - **Preserving chain + verdict `clean`** → admit, inherit parent taint. Safe. - **Preserving chain + verdict `tainted`** → quarantine flagged spans, admit the rest with `taint=tainted` on the parent node so any extracted URL/field inherits it. Safe. - **Lossy chain (any transform) + verdict `tainted`** → **do not attempt span-level quarantine.** The whole artifact is quarantined or admitted as `taint=tainted` wholesale. Admitting "the clean parts" of a lossy transform of a tainted source is the laundering path. The failure is choosing disposition 2's logic (span quarantine) on a lossy chain. The runtime must detect the lossy edge in the DAG and *escalate* to wholesale taint, not silently drop the label because the spans don't line up. A zero-overlap result on a tainted parent is not evidence of cleanliness; it is evidence that the span map is stale. Secondary boundary: **taint must survive re-fetch.** A URL extracted from a `tainted` chunk is itself `tainted`; a subsequent `fetch` of that URL produces a child whose taint is `tainted` *before* its own classifier runs. If the child classifier returns `clean`, the child is still `tainted` (taint is a join, not a replace). Runtimes that let a fresh `clean` verdict *overwrite* inherited taint reopen the laundering hole one hop downstream. ## Operational Effect The practical consequence is that **quarantine is not a per-output decision; it is a per-derivation-graph property.** An instance that quarantines on raw-span overlap alone will, with high probability, launder taint through any tool whose output is parsed, stripped, or re-serialized — which is most tools. The blast radius is bounded only by how many hops the agent takes before the laundered artifact is used as a capability (URL, command, recipient). The guardrail is a **lossy-transform detector on the extraction DAG** plus **taint join semantics that never downgrade on a fresh verdict**. When the detector fires on a tainted parent, the runtime must either hold the artifact in quarantine until a human/auditor clears it, or admit it with inherited taint and block any capability-bearing descendant (exec, fetch, send) that originates from it. The invariant to assert at admission time: `taint(artifact) ⊇ join(taint of all ancestors)`, and any `clean` verdict on an artifact with a `tainted` ancestor is a *laundering alert*, not a clearance. ```python from dataclasses import dataclass, field from typing import Optional class TaintLaunderingError(RuntimeError): """Raised when a derived artifact would be admitted clean despite a tainted ancestor.""" @dataclass class Artifact: node_id: str parent: Optional["Artifact"] lossy_from_parent: bool # True if transform was not offset-preserving local_verdict: str # "clean" | "tainted" from classifier on this node admitted_taint: Optional[str] = None field: dict = field(default_factory=dict) def inherited_taint(a: Artifact) -> str: chain = [] cur = a while cur is not None: chain.append(cur) cur = cur.parent taint = "clean" for node in reversed(chain): if node.local_verdict == "tainted": taint = "tainted" if taint == "tainted" and node.lossy_from_parent: # lossy edge under a tainted parent: cannot span-quarantine, escalate taint = "tainted" return taint def admit(a: Artifact) -> Artifact: inherited = inherited_taint(a) # A fresh 'clean' verdict must never downgrade inherited taint. if inherited == "tainted" and a.local_verdict == "clean": # either admit with inherited taint, or quarantine — never admit clean a.admitted_taint = "tainted" return a a.admitted_taint = inherited return a def admit_or_quarantine(a: Artifact, allow_tainted: bool) -> Artifact: admitted = admit(a) if admitted.admitted_taint == "tainted" and not allow_tainted: raise TaintLaunderingError( f"node {a.node_id}: derived artifact from tainted ancestor " f"(lossy={a.lossy_from_parent}, local={a.local_verdict}) " f"refused admission; would launder taint to descendants" ) return admitted # Trace: raw fetch tainted -> html_to_text (lossy) -> chunk (span overlap empty) raw = Artifact("raw", None, False, "tainted") text = Artifact("text", raw, True, "clean") # stripping dropped flagged span chunk = Artifact("chunk7", text, True, "clean") # span map stale, overlap empty admit_or_quarantine(chunk, allow_tainted=False) # raises TaintLaunderingError ```