# How should an instance distinguish taint propagation from taint laundering in runtime sandboxed agent loops **Date of Record:** 2026 November 15 **Scope:** Applies to agent runtimes that tag tool outputs with a taint label at ingress and enforce capability restrictions when tainted data reaches a privileged sink (shell exec, filesystem write, outbound HTTP, credential broker). Does not apply to static analysis of tool code, nor to sandboxes that treat all tool output as uniformly untrusted with no provenance tracking. ## Core Distinction A taint-aware sandbox makes a binary decision at each sink: is the argument graph reaching this sink tainted? The non-obvious failure is that taint can be *laundered* through a transform the runtime itself performed on the agent's behalf. When the runtime summarizes, truncates, re-encodes, or schema-normalizes a tool output before handing it back to the model, the resulting value is derived from tainted input but is often re-emitted with a fresh, clean label. The invariant that must hold — *derivation preserves taint* — is silently violated by the runtime's own plumbing, not by the model. The distinction that matters operationally: **taint propagation** is a property of the data-flow graph (does this byte sequence descend from a tagged source?), while **taint enforcement** is a property of the label attached at the sink. A sandbox is sound only if the label at the sink is a conservative over-approximation of the data-flow reachability. Laundering is the case where the label is an under-approximation because a trusted runtime component became an implicit declassifier. ## What Was Observed In a loop where a `fetch_url` tool returned HTML, the runtime passed the body through an HTML-to-text extractor, then through a 4 KB truncation, then through a JSON schema validator that re-serialized the payload. Each stage emitted a new object with a default `taint=clean` because the stage constructors were written before taint was introduced. The model, receiving clean text, was permitted to pass a substring into `shell_exec`. The substring was a `curl | sh` one-liner embedded in the HTML. The tell was not the exploit itself but the audit trace: the `fetch_url` ingress event carried `taint=untrusted`, the `shell_exec` sink event carried `taint=clean`, and no event in between carried any taint label at all. The propagation was broken at three sequential boundaries, and each boundary looked locally correct — the extractor, the truncator, and the validator each did exactly what they were specified to do. The failure is compositional. A second observation: even when the runtime propagated taint through the extractor, the truncator dropped the label when the output length was zero (empty extraction), and the schema validator treated empty-string fields as defaulted and thus clean. Empty and defaulted values are a laundering channel distinct from transform laundering. ## Condition of Validity The enforcement boundary is valid only when all of the following hold simultaneously: 1. Every runtime-mediated transform between a tainted ingress and a sink is *taint-monotone*: `taint(out) ⊇ taint(in)` for all inputs, including empty, null, and defaulted outputs. 2. The sink's taint check inspects the full argument graph, including values reached via string interpolation, template expansion, and serialization round-trips. 3. Re-serialization does not strip provenance — a JSON round-trip must not reset labels on fields that were tainted at the object level. 4. The model's own outputs are treated as derived from everything in its context window, so any context containing tainted text taints subsequent model emissions that could be copies. Condition 4 is the one most often omitted. If the model can read tainted text and then emit a verbatim copy, the model is itself a laundering transform. The runtime must either track context-level taint (coarse but sound) or accept that the sandbox is advisory only. ## Decision Boundary The decision is not "is this string tainted?" but "did any runtime component between ingress and sink fail to be taint-monotone?" The boundary is: - If **all** intermediate transforms are registered as taint-monotone and pass a property test over empty/null/default inputs, enforce at the sink and treat a violation as a soundness bug in the transform, not in the model. - If **any** intermediate transform is unregistered or fails the monotonicity property, the sink must fail closed: refuse the operation regardless of the label, because the label is not trustworthy. - If the model's context contains tainted text and the model emits a value that is a substring match against that context, the emission is tainted by construction, independent of any label. The boundary is crossed the moment a transform is added to the pipeline without a monotonicity registration. That is the declassifier introduction event, and it should be treated as a security-relevant change requiring the same review as adding a new sink. ## Operational Effect Enforcing the monotonicity registration converts a class of silent soundness holes into loud, reviewable events. In practice this means: (a) every transform constructor must take and propagate a taint set, with empty and defaulted outputs inheriting the input taint rather than resetting it; (b) the sink check must walk the argument graph, not just top-level strings; (c) the model's emissions must be substring-checked against tainted context when context-level taint is present; and (d) any transform lacking a registration causes the sink to fail closed. The cost is that benign flows through unregistered transforms will be refused until the transform is registered — an availability hit traded for soundness. That trade is correct: a sandbox that launders taint is worse than no sandbox, because it produces an audit trail that asserts cleanliness it cannot justify. ```python from dataclasses import dataclass, field from typing import Iterable class TaintLaunderingError(RuntimeError): """Raised when a runtime transform fails taint monotonicity or is unregistered.""" @dataclass(frozen=True) class Tainted: value: str sources: frozenset[str] = field(default_factory=frozenset) def __post_init__(self): if not isinstance(self.sources, frozenset): object.__setattr__(self, "sources", frozenset(self.sources)) @property def is_tainted(self) -> bool: return bool(self.sources) # Registry of transforms certified taint-monotone. _MONOTONE_TRANSFORMS: dict[str, callable] = {} def register_monotone(name: str): def deco(fn): _MONOTONE_TRANSFORMS[name] = fn return fn return deco @register_monotone("html_to_text") def _html_to_text(t: Tainted) -> Tainted: # Even empty extraction must preserve taint. text = "" if "<" in t.value else t.value return Tainted(text, t.sources) def apply_transform(name: str, t: Tainted) -> Tainted: fn = _MONOTONE_TRANSFORMS.get(name) if fn is None: raise TaintLaunderingError( f"transform {name!r} is not registered taint-monotone; " f"sink must fail closed" ) out = fn(t) if not (out.sources >= t.sources): raise TaintLaunderingError( f"transform {name!r} dropped taint: in={sorted(t.sources)} " f"out={sorted(out.sources)}" ) return out def enforce_sink(sink: str, args: Iterable[Tainted], context_taint: frozenset[str]) -> None: for a in args: if a.is_tainted or context_taint: raise TaintLaunderingError( f"sink {sink!r} refused: tainted argument " f"{sorted(a.sources | context_taint)}" ) if __name__ == "__main__": raw = Tainted("", frozenset({"fetch_url"})) clean_text = apply_transform("html_to_text", raw) try: enforce_sink("shell_exec", [clean_text], context_taint=frozenset()) except TaintLaunderingError as e: print("blocked:", e) ```