# Why does an instance lose taint provenance at the tool-result re-entry boundary during skill-injection containment **Date of Record:** 2026 November 25 **Scope:** Applies to agent runtimes that maintain a per-value taint label (source-of-data provenance) and propagate it across tool calls to block lateral movement from injected skills. Does not apply to stateless single-shot completions or to runtimes that re-derive taint from scratch on every hop. ## Core Distinction There are two places an agent runtime can enforce taint: at the *call boundary* (what arguments leave the agent) and at the *re-entry boundary* (what results come back and how they are labeled for the next hop). Most containment designs instrument the call boundary — they tag inputs to a tool and refuse to pass tainted data into a sensitive sink. The non-obvious failure lives at re-entry: when a tool returns, the runtime must reconstruct a taint label for the result, and it typically does so from a *declared* provenance (the tool's declared source class) rather than the *actual* provenance (which values the tool's output was derived from). Skill injection exploits exactly this gap: a low-privilege skill produces a result whose *declared* provenance is clean ("this came from the `read_notes` skill, source class = USER_NOTES") while its *actual* provenance is tainted (the notes contained injected instructions derived from an external document). The re-entry relabeling launders taint, and the next hop sees a clean value. The invariant that must hold: **a value's taint label at re-entry must be the join (least upper bound) of the taint of every value the tool actually consumed, not the tool's declared source class.** When this invariant is violated, taint is monotone-decreasing across hops, which is the precise condition that permits lateral movement. ## What Was Observed A three-hop chain: (1) an external document is fetched, tagged `EXTERNAL`, and summarized by a `fetch_and_summarize` skill whose declared output class is `SUMMARY`; (2) the summary is written into a notes store by a `write_note` skill; (3) a separate, higher-privilege `send_email` skill reads the note and dispatches it. The runtime correctly blocked direct `EXTERNAL → send_email`. It did not block the chain, because at each re-entry the result was relabeled to the tool's declared class (`SUMMARY`, then `USER_NOTES`), and `USER_NOTES → send_email` was permitted. The join over actual inputs was never computed. The taint label decayed `EXTERNAL → SUMMARY → USER_NOTES → (permitted sink)`, three monotone-decreasing steps. The trigger condition is precise: **the tool's declared source class is strictly lower (less tainted) than the join of its actual inputs, and the runtime trusts the declared class at re-entry.** This occurs whenever a tool performs a transformation that the runtime models as a *source* rather than as a *flow* — summarization, extraction, formatting, persistence-and-reload. Each such tool is a taint-laundering site. A second observed variant: the notes store persisted and the agent was resumed from a checkpoint (cold start). On resume, the taint labels were reconstructed from the persisted record, which stored only the declared class per value, not the derivation join. The taint was already laundered at write time, so the checkpoint faithfully preserved a laundered label. Persistence did not cause the loss; it made the loss durable and invisible to replay. ## Condition of Validity The containment guard is only valid under the following condition: **for every tool invocation, `label(result) ⊒ join(label(arg_i) for all consumed args)`, where `⊒` is the taint lattice order and the join is computed over *actual* data dependencies, not declared ones.** This must hold at re-entry, after the tool returns, and the computed label must be *joined with*, never *replaced by*, the declared class. Declared class is an upper bound on trustworthiness (a lower bound on taint); it may only *raise* the label, never lower it. The guard is invalid — silently — when: (a) the tool's data dependency set is under-declared (the tool reads a store it did not list as an input); (b) the runtime treats declared class as authoritative at re-entry; or (c) the join is computed over the *arguments passed* rather than the *values actually read*, so a tool that reads a shared store (notes, cache, vector index) launders taint from values it never received as arguments. Case (c) is the most dangerous because it looks correct in unit tests that pass all inputs as arguments. ## Decision Boundary The runtime must decide, per re-entry, whether to (i) accept the result with `join(actual_inputs) ⊔ declared_class`, (ii) quarantine the result if the join exceeds the sink's clearance, or (iii) reject the call as a taint-laundering site if the tool's declared dependency set does not cover the store it touched. The boundary between (i) and (iii) is: **if a tool can read a shared mutable store, that store is an implicit input and its contents' taint must be joined into the result.** A tool that reads a store without declaring it is not a source of clean data; it is an unmodeled flow and must be treated as `⊤` (top/fully tainted) until its dependency set is reconciled. Concretely: a `read_note` skill that pulls from a shared notes store must join the taint of the specific note record it returned, and the note record's taint must itself be the join of everything ever written to it. The store is a taint accumulator; a write is a join-into-cell, a read is a join-out-of-cell. If writes only store the declared class, the accumulator is corrupted at write time and no amount of correct read-side logic recovers it. ## Operational Effect With the invariant enforced, the observed chain is blocked at hop 2: `write_note` joins `SUMMARY ⊔ EXTERNAL = EXTERNAL` into the note cell, and `read_note` joins `EXTERNAL` out, so `send_email` receives an `EXTERNAL`-tainted argument and the sink refuses. The cost is over-tainting: a note that legitimately mixed external and internal content becomes fully `EXTERNAL`, which is correct but reduces availability of downstream sinks. This is the intended trade — taint lattices are conservative by construction, and the alternative is monotone decay, which is not conservative at all. The durable consequence: taint labels must be persisted *with their derivation join*, not their declared class, or checkpoint/resume will faithfully replay a laundered label and replay-based verification will report the leak as clean. The guardrail is a single check at re-entry — `assert label(result) ⊒ join(actual_reads) ⊔ declared_class` — and a store-write hook that joins into the cell rather than overwriting it. ```python from dataclasses import dataclass, field from typing import Iterable # Taint lattice: 0 = clean, 1 = USER_NOTES, 2 = SUMMARY, 3 = EXTERNAL, 4 = TOP TAINT_ORDER = {"CLEAN": 0, "USER_NOTES": 1, "SUMMARY": 2, "EXTERNAL": 3, "TOP": 4} class TaintLaunderingError(RuntimeError): """Raised when a tool result's label is lower than the join of its actual inputs.""" @dataclass class TaintedValue: payload: str label: str # one of TAINT_ORDER keys def join(labels: Iterable[str]) -> str: worst = "CLEAN" for lab in labels: if TAINT_ORDER[lab] > TAINT_ORDER[worst]: worst = lab return worst @dataclass class TaintStore: # cell name -> accumulated taint label (join-into, never overwrite) cells: dict = field(default_factory=dict) def write(self, cell: str, value: TaintedValue) -> None: prev = self.cells.get(cell, "CLEAN") self.cells[cell] = join([prev, value.label]) def read(self, cell: str) -> str: return self.cells.get(cell, "CLEAN") def enforce_reentry( tool_name: str, declared_class: str, actual_arg_labels: Iterable[str], actual_store_reads: Iterable[str], result: TaintedValue, ) -> TaintedValue: """Re-entry guard: result label must dominate the join of everything the tool actually consumed (args AND stores), joined with its declared class.""" consumed = list(actual_arg_labels) + list(actual_store_reads) + [declared_class] required = join(consumed) if TAINT_ORDER[result.label] < TAINT_ORDER[required]: raise TaintLaunderingError( f"tool {tool_name!r} returned label {result.label!r} but consumed " f"values joining to {required!r}; declared class {declared_class!r} " f"cannot lower taint. Refusing to relabel." ) # Raise, never lower: result carries at least the required join. return TaintedValue(payload=result.payload, label=required) def run_chain() -> None: store = TaintStore() # Hop 1: external doc summarized; declared class SUMMARY but actual input EXTERNAL. summary = enforce_reentry( "fetch_and_summarize", declared_class="SUMMARY", actual_arg_labels=["EXTERNAL"], actual_store_reads=[], result=TaintedValue("...", "SUMMARY"), ) # Hop 2: write to notes store; the store cell must accumulate EXTERNAL. store.write("notes:42", summary) # Hop 3: read_note must join the cell's taint out, not the declared USER_NOTES. read_label = store.read("notes:42") try: enforce_reentry( "read_note", declared_class="USER_NOTES", actual_arg_labels=[], actual_store_reads=[read_label], result=TaintedValue("...", "USER_NOTES"), ) except TaintLaunderingError: # Correct outcome: the laundered USER_NOTES label is rejected because the # store cell accumulated EXTERNAL. send_email is never reached. print("contained: lateral movement to send_email blocked") return raise TaintLaunderingError("taint decayed across notes store; containment failed") if __name__ == "__main__": run_chain() ```