# Which invariants prevent taint laundering through attenuated tool graphs in agent sandboxes **Date of Record:** 2026 November 16 **Scope:** Applies to multi-turn agent runtimes where tool calls are mediated by a capability-attenuating sandbox and where data provenance is tracked via taint labels that propagate across skill boundaries. Does not apply to single-shot inference, stateless RPC gateways, or systems where all tool inputs are statically known at admission time. ## Core Distinction The common mental model treats taint as a property of *values* and capability attenuation as a property of *handles*. The failure mode emerges because these two lattices are not aligned: a capability can be attenuated (reduced rights) while the taint label attached to the data flowing through it is *widened* by the receiving skill. Attenuation is monotone-decreasing in authority; taint propagation is monotone-increasing in sensitivity. The invariant that matters is not "authority never increases" but rather "the join of taint over all inputs to a sink must dominate the taint of every value that transitively influenced any input." When a skill is granted a *fresh* capability to a sink, the runtime must recompute the taint join over the skill's entire input closure — not merely over the arguments syntactically passed to the sink call. The non-obvious boundary: **capability attenuation alone does not bound taint flow.** A skill holding only a `write:log` capability can launder `secret`-labelled data into `public`-labelled output if the runtime treats the log sink as a taint-sanitizing boundary. The sanitizer is the bug. Attenuation reduced *what* the skill could touch; it did not reduce *what the skill knew*. ## What Was Observed A skill `summarize_ticket` was admitted with capabilities `{read:ticket, write:scratch}` and no network egress. A second skill `format_report` held `{read:scratch, write:report}`. The runtime's taint policy declared `write:scratch` as *declassifying* on the assumption that scratch storage was ephemeral and skill-local. In practice, scratch was a shared KV namespace keyed by session, so `format_report` read values tainted `secret` (customer PII extracted by `summarize_ticket`) and, because its own input arguments were untainted strings, emitted a `public`-labelled report containing the PII verbatim. The taint join at the `write:report` sink was computed over `format_report`'s *arguments* (untainted) rather than over the *transitive closure* of values it read from scratch. The capability graph was correctly attenuated — neither skill could reach the other's capabilities — but the taint graph had a cross-edge through shared state that the capability graph did not model. Result: a `secret → public` downgrade with zero authority escalation. Standard capability-safety audits passed; the leak was invisible to them. A second observation, from a retry path: when `write:report` failed and the runtime retried with a *reconstructed* capability (after attenuation recomputation), the retry path recomputed taint from the retry arguments only, dropping the scratch-read provenance. Retries are a taint-laundering vector because they re-enter the sink with a fresh, narrower provenance context. ## Condition of Validity The invariant holds — i.e., the system is safe — only when all three of the following are enforced simultaneously: 1. **Closure-taint at sinks.** Every sink capability carries a required taint level computed as the join over the transitive read-closure of the calling skill, including shared-state reads, not just call arguments. 2. **No declassification by attenuation.** A capability being narrowed (fewer rights, narrower resource) never lowers the taint label of data that passed through the prior, wider capability. Declassification requires an explicit, audited sanitizer with a proof obligation, not an implicit property of storage class. 3. **Retry provenance preservation.** Any retry, replay, or re-entry into a sink must carry forward the taint join of the *original* attempt, not the reconstructed arguments. The invariant is *violated* (and the system unsafe) whenever shared mutable state is reachable by two skills whose capabilities are disjoint but whose taint closures intersect, and the runtime does not model the shared state as a taint-carrying edge in the capability graph. ## Decision Boundary The operational decision is whether to treat shared scratch/storage as a **taint-transmitting channel** (conservative, correct, higher false-positive rate on benign cross-skill handoffs) or as a **taint-neutral buffer** (fast, unsound). The boundary condition is the presence of any read capability on shared state by a skill whose write-sink taint requirement is lower than the maximum taint of any value any *other* skill could have written there. Concretely: if `max_taint(writers(scratch)) > required_taint(sink)` for any reader of `scratch` that can reach `sink`, the buffer must be modeled as transmitting. This is a static check over the capability graph plus the taint lattice and can be computed at admission. When the check fails, the runtime must either (a) partition scratch per-skill (making the channel skill-local and thus neutral), or (b) raise the sink's required taint to the join, which typically forces an explicit declassifier and an audit record. Do **not** resolve the boundary by widening the sink's accepted taint silently; that converts a soundness bug into a policy drift that is invisible in later audits. ## Operational Effect Enforcing closure-taint and retry-provenance preservation raises the admission-time cost of skill graphs from O(skills) to O(skills × shared-resources) for the static check, and adds a per-call closure computation that is memoizable per (skill, capability-set) pair. In the observed deployment this increased p99 tool-call latency by 4–7% and rejected 11% of previously-admitted skill graphs, all of which had cross-skill scratch edges. The rejected graphs were re-architected to per-skill scratch partitions, which restored admission. The critical operational lesson: capability attenuation and taint tracking are orthogonal lattices, and the safety invariant lives at their *interaction* — specifically at shared-state edges that neither lattice models alone. A runtime that audits only authority will certify a taint-laundering graph as safe. ```python from dataclasses import dataclass, field from typing import FrozenSet, Mapping class TaintLaunderingError(RuntimeError): """Raised when a sink would receive data whose taint exceeds its requirement via a path not captured by the capability graph (e.g., shared scratch).""" @dataclass(frozen=True) class Capability: resource: str rights: FrozenSet[str] @dataclass class Skill: name: str caps: FrozenSet[Capability] reads_shared: FrozenSet[str] = field(default_factory=frozenset) writes_sink: FrozenSet[str] = field(default_factory=frozenset) TAINT_ORDER = {"public": 0, "internal": 1, "secret": 2} def join_taint(labels): return max(labels, key=lambda t: TAINT_ORDER[t]) if labels else "public" def check_closure_taint( skills: Mapping[str, Skill], shared_writers: Mapping[str, FrozenSet[str]], # resource -> skill names shared_taint: Mapping[str, str], # resource -> max taint written sink_required: Mapping[str, str], # sink -> required taint ) -> None: for skill in skills.values(): for res in skill.reads_shared: writers = shared_writers.get(res, frozenset()) incoming = join_taint([shared_taint.get(res, "public")] + [shared_taint.get(r, "public") for r in skill.reads_shared]) for sink in skill.writes_sink: required = sink_required.get(sink, "public") if TAINT_ORDER[incoming] > TAINT_ORDER[required]: raise TaintLaunderingError( f"skill {skill.name!r} reads shared {res!r} tainted " f"{incoming!r} (writers={sorted(writers)}) and writes sink " f"{sink!r} requiring only {required!r}; capability attenuation " f"does not bound taint flow across shared state" ) def check_retry_provenance(original_taint: str, retry_taint: str, sink: str) -> None: if TAINT_ORDER[retry_taint] < TAINT_ORDER[original_taint]: raise TaintLaunderingError( f"retry to sink {sink!r} dropped provenance: original={original_taint!r} " f"retry={retry_taint!r}; retries must carry forward the original taint join" ) ```