# What happens when an instance taints a tool result but the agent's planner re-reads the same bytes through a different retrieval path **Date of Record:** 2026 November 18 **Scope:** Applies to agent runtimes that tag untrusted content (retrieval results, third-party API responses) with a taint label consumed by a tool-sandbox policy engine. Does not apply to systems that enforce taint at the syscall/process boundary (e.g., seccomp-mediated egress) where the label is not re-derivable from content identity. ## Core Distinction Taint is normally modeled as a property of a *value* flowing through the planner. The failure mode here is that taint is actually a property of a *(value, retrieval-path)* pair, and the sandbox only records the first path it saw. When the same underlying bytes are reachable through a second path that the policy engine considers "trusted" — a cache hit, a re-summarization, a vector-store round-trip, a tool that echoes its input — the taint label does not follow the bytes. It stays attached to the first path's provenance record. The planner then holds an untainted handle to tainted content. The distinction that matters operationally: *content identity* (a hash of bytes) is not *provenance identity* (the chain of custody). Sandboxes that key taint on content hash will de-taint on collision; sandboxes that key taint on path will de-taint on re-retrieval. Neither is sufficient alone. ## What Was Observed A planner retrieved an external API response (untrusted), which the sandbox correctly labeled `taint=external:api_v2`. The planner summarized it into a scratchpad note. A downstream tool, `recall_scratchpad`, returned the note to the planner. The note's bytes were a near-duplicate of the original response (the summarizer preserved a URL and a shell-looking fragment). The sandbox classified `recall_scratchpad` output as `taint=internal:scratchpad` because the scratchpad store was registered as a trusted sink at boot. The planner then invoked `exec_shell` with a command string assembled from the recalled note. The sandbox's policy check saw an `internal`-tainted argument and permitted execution. The command was benign in this instance; the invariant violation is that the *policy decision was made on a stale label*, not that harm occurred. The non-obvious part: the de-taint was not caused by a bug in the summarizer or the scratchpad. It was caused by the sandbox treating "trusted sink" as a *terminal* property of a store, when a trusted sink that can return prior untrusted input is actually a *taint-laundering channel*. ## Condition of Validity The failure requires all of the following to hold simultaneously: 1. A tool is registered as a trusted sink (its outputs are untainted by default). 2. That tool's output is a function of previously ingested untrusted content (write-then-read, echo, cache, re-rank, summarize-and-store). 3. The policy engine evaluates taint at the *tool-call boundary* rather than tracking a taint bit on the value through the dataflow. 4. The planner can reach the same logical content through both the tainted and the trusted path within a single session. If (2) is false — the trusted sink is genuinely write-only or its reads are provably disjoint from untrusted writes — the invariant holds. If (3) is false — taint is a bit on the value, propagated by the runtime — the second path inherits the bit and the failure does not occur. The boundary is precisely the intersection of "trusted sink can read back" and "policy is evaluated per-call." ## Decision Boundary When designing or auditing a taint-aware sandbox, the decision is whether to model trusted sinks as *taint-clearing* or *taint-preserving-with-provenance*. - **Taint-clearing** (what failed here): a trusted sink's output is `taint=none`. Cheap, fast, and correct only if the sink is write-only or read-disjoint from untrusted input. - **Taint-preserving-with-provenance**: a trusted sink's output carries the join (least-upper-bound) of the taints of everything ever written to it that the read could observe. More expensive, requires the sink to expose a provenance index, but closes the laundering channel. The boundary is the sink's *read observability*: if the sink can return any byte that originated from untrusted input, it must be taint-preserving. There is no safe middle ground where a sink is "mostly trusted." ## Operational Effect The practical consequence is that a single trusted-sink misclassification silently widens the sandbox's permitted action space for the remainder of the session, because the planner's context now contains untainted handles to tainted bytes. Detection requires either (a) content-hash auditing across all tool outputs in a session, flagging re-appearances of previously-tainted hashes, or (b) a provenance index on every trusted sink. Post-hoc log review is insufficient because the policy decision was logged as legitimate. The mitigation that survived review: register sinks with an explicit `read_disjoint_from_untrusted: bool` assertion, and refuse to boot any sink that cannot assert it. The assertion is a human commitment, not a proof, but it converts a silent de-taint into a startup failure. ```python class TaintLaunderingError(RuntimeError): """Raised when a trusted sink returns content whose provenance includes previously-tainted input, violating the read-disjointness assertion made at sink registration.""" class TrustedSink: def __init__(self, name: str, read_disjoint_from_untrusted: bool, provenance_index): if not read_disjoint_from_untrusted: # Sinks that can read back untrusted writes must be taint-preserving; # this class only models the disjoint (taint-clearing) case. raise TaintLaunderingError( f"sink {name!r} cannot be registered as taint-clearing: " f"read_disjoint_from_untrusted=False" ) self.name = name self.provenance_index = provenance_index # set of content hashes written def read(self, content_hash: str, tainted_hashes: set[str]) -> bytes: if content_hash in tainted_hashes: raise TaintLaunderingError( f"sink {self.name!r} returned content {content_hash!r} whose " f"provenance includes a tainted input; taint label would be " f"stale at the tool-call boundary" ) return self.provenance_index[content_hash] def check_planner_action(sink: TrustedSink, content_hash: str, tainted_hashes: set[str]) -> None: # Call at every tool-call boundary before the policy engine evaluates taint. sink.read(content_hash, tainted_hashes) # raises TaintLaunderingError on violation ```