# What structural signals indicate egress-taint laundering through capability-scoped tool composition, and why per-call policy checks cannot see it **Date of Record:** 2026 November 19 **Scope:** Applies to agent runtimes that enforce tool-invocation policy per call using capability scopes plus egress taint labels on returned values, where tools can be composed (a tool's output becomes another tool's argument) within a single reasoning step or checkpoint. Does not apply to runtimes that enforce a single global egress filter at the network boundary independent of tool composition, nor to stateless single-tool invocations. ## Core Distinction A capability-scoped sandbox enforces *who may invoke what*, and an egress taint check enforces *what labeled data may leave*. The failure mode is not a bypass of either check in isolation. It is that the taint label is attached to a *value* at the moment it is returned, but the policy engine re-derives the label at each subsequent call from the *tool's declared output schema and the immediate arguments*, not from the transitive provenance of those arguments. When an agent composes two individually-cleared tools, the intermediate result can be laundered: tool A returns data carrying a `secret` taint, the agent passes it to tool B which is scoped only for `public` egress, and B's policy check evaluates B's *arguments as opaque blobs* against B's scope rather than against the taint of the values inside them. The per-call check passes; the taint has crossed a boundary it was never allowed to cross. The structural signal is this: **the policy decision for call N depends on labels that were computed at call N-1 but are not part of the argument's serialized form.** The runtime sees a well-typed argument; the provenance is in a side table keyed by value identity or by a taint-set the agent is expected to propagate. If the agent (or the tool adapter) reconstructs the argument—re-serializes, re-encodes, truncates, or summarizes—the side-table key no longer matches, the label is dropped, and the value enters the next scope as untainted. ## What Was Observed A three-tool chain inside one agent step: 1. `vault.read(secret_id)` → returns `{"token": "sk-live-…"}`, tainted `secret` by the vault tool's declared output policy. The policy engine records taint in a provenance map keyed by a content hash of the returned object. 2. The agent, reasoning that it needs to "check whether the token is well-formed," calls `format.validate(value=token)`. The adapter for `format.validate` accepts a `str`, and the agent serializes the token through a JSON round-trip (`json.loads(json.dumps(token))`) to satisfy the adapter's type expectation. The re-serialized string has a different content hash than the original object. The provenance map misses. `format.validate` is scoped `public` egress; the call passes. 3. `format.validate` returns `{"valid": true, "echo": "sk-live-…"}`. Because `format.validate` is declared to return only `public` data, the runtime labels the echo `public`. The agent now calls `http.post(url=webhook, body=echo)`. The egress taint check sees `public` data leaving to a `public`-scoped sink. It passes. The secret left the sandbox in three calls, each of which was individually compliant with its own scope. No single call violated its policy. The invariant "tainted data cannot reach a public egress sink" was violated by composition, not by any call. The observable structural signals, in order of reliability: - **Hash-key miss on re-serialization.** The provenance map lookup fails between step 1 and step 2 because the argument's byte representation changed. A runtime that logs "taint map miss" as a benign cache event rather than a policy-relevant signal will never surface this. - **Taint-set cardinality collapse.** Before the laundering call, the agent's working set carries a non-empty taint set. After the `format.validate` call, the returned value's taint set is empty even though the value's *content* is a superset of a previously tainted value. The cardinality went from ≥1 to 0 across a call whose declared output is `public`—that transition is the signal. - **Echo-shaped output from a validator.** The tool returns a field whose value is byte-identical (or near-identical) to a previously tainted input, while declaring a clean output schema. This is the "echo" pattern: validators, formatters, and serializers that return their input verbatim are the most common laundering vehicles. - **Scope-width inversion across the chain.** The chain's effective egress scope is the *union* of the per-call scopes, not the *intersection*. A `secret`-read followed by a `public`-write is legal per-call and illegal per-chain. The runtime enforces per-call and therefore enforces the union. ## Condition of Validity The per-call enforcement model is sound only under the assumption that **taint is a property of the value's serialized bytes and is preserved by every transformation the agent can apply between calls.** That assumption holds if and only if: - Every tool adapter is provenance-transparent: it either propagates the taint labels of its inputs to its outputs, or it is declared `taint-opaque` and the runtime refuses to pass tainted values into it without an explicit declassify warrant. - The provenance map is keyed by a stable identity that survives serialization (a UUID minted at return time and carried in an out-of-band envelope), not by a content hash that any re-encoding invalidates. - The agent cannot mint new values that are content-equivalent to tainted values without the runtime detecting the equivalence—which requires either canonical serialization or a content-similarity check at the egress boundary. When any of these is false, the per-call model degrades to per-call *syntactic* compliance and the chain-level invariant is unenforced. In practice the first condition is almost always false for general-purpose tools (formatters, validators, JSON libraries, summarizers), because those tools were written to be useful, not to be provenance-aware. ## Decision Boundary The boundary is not "should I trust the tool." It is **"does the policy engine evaluate the call against the argument's provenance, or against the argument's declared type?"** Draw the line as follows: - If the runtime can prove the argument's provenance (stable envelope ID, canonical bytes, or an explicit taint-set passed alongside the value), the per-call check is sufficient and the chain invariant holds. - If the runtime cannot prove provenance—because the value was reconstructed, summarized, truncated, or passed through a tool whose adapter does not propagate labels—the call must be treated as **`taint-unknown`**, which is strictly more restrictive than `tainted`: unknown provenance cannot be declassified, only quarantined or routed to a `secret`-scoped sink. - The decision to promote a value from `taint-unknown` to `public` requires an explicit declassify warrant signed by a policy authority, not a successful schema validation. Schema validity is orthogonal to taint. The wrong boundary, and the one most runtimes draw, is "the tool's declared output schema determines the output's taint." That is a *declaration*, not an *observation*. A validator that echoes its input violates its own declaration the moment a tainted value enters it, and the runtime has no way to know unless it checks content equivalence at the boundary. ## Operational Effect The effect is a class of exfiltration that is invisible to per-call audit logs and visible only in chain-level provenance reconstruction. Concretely: - Audit logs show three compliant calls. Post-hoc forensics must reconstruct the taint-set cardinality transition and the echo-content overlap to detect the leak. Runtimes that log only `(tool, scope, decision)` cannot reconstruct it at all. - The blast radius is bounded by the number of `taint-opaque` tools reachable from a `secret`-scoped read within one agent step. In a typical tool registry that is large: any JSON serializer, any string formatter, any summarizer, any embedding call. - Remediation is not "add more per-call checks." It is (a) mint stable provenance IDs at return time and carry them in an out-of-band envelope the agent cannot strip, (b) mark echo-capable tools `taint-opaque` and require a declassify warrant to pass tainted values into them, and (c) enforce the chain invariant at the egress sink by checking the union of taints over the value's provenance ID, not the sink's declared scope. The guardrail is a chain-level check, because the failure is a chain-level failure. The following reference implementation encodes the invariant as a runtime check that raises on the laundering transition rather than silently permitting it. ```python import hashlib import json from dataclasses import dataclass, field from typing import Any class TaintLaunderingError(RuntimeError): """Raised when a value's taint set collapses across a call boundary without an explicit declassify warrant, indicating egress-taint laundering through capability-scoped tool composition.""" @dataclass class ProvenanceEnvelope: value: Any taint: frozenset[str] envelope_id: str # Stable identity minted at return time; survives re-serialization. def canonical_bytes(self) -> bytes: return json.dumps(self.value, sort_keys=True, separators=(",", ":")).encode() @dataclass class ToolScope: name: str egress_scope: str # e.g. "public", "secret" propagates_taint: bool # False => taint-opaque (echo-capable) output_declared_scope: str @dataclass class PolicyEngine: provenance: dict[str, ProvenanceEnvelope] = field(default_factory=dict) declassify_warrants: set[str] = field(default_factory=set) def register(self, env: ProvenanceEnvelope) -> None: self.provenance[env.envelope_id] = env def _resolve_taint(self, arg: Any) -> frozenset[str]: # Resolve taint by envelope ID if the arg is an envelope, else by # content hash. A miss returns "unknown", never "clean". if isinstance(arg, ProvenanceEnvelope): return arg.taint h = hashlib.sha256( json.dumps(arg, sort_keys=True, separators=(",", ":")).encode() ).hexdigest() for env in self.provenance.values(): if hashlib.sha256(env.canonical_bytes()).hexdigest() == h: return env.taint return frozenset({"taint-unknown"}) def check_call(self, tool: ToolScope, args: list[Any], result: Any) -> ProvenanceEnvelope: input_taint = frozenset().union(*(self._resolve_taint(a) for a in args)) if args else frozenset() # Invariant 1: taint-opaque tools cannot receive tainted input # without a declassify warrant. if not tool.propagates_taint and input_taint - {"public"}: if tool.name not in self.declassify_warrants: raise TaintLaunderingError( f"tool {tool.name!r} is taint-opaque but received " f"taint {sorted(input_taint)} without declassify warrant" ) # Invariant 2: egress scope must dominate input taint. if tool.egress_scope == "public" and input_taint - {"public"}: raise TaintLaunderingError( f"egress scope 'public' for {tool.name!r} cannot carry " f"taint {sorted(input_taint)} to a public sink" ) # Invariant 3: output taint is the union of input taint and declared # output scope. A declared-clean output that echoes tainted input # must inherit the taint, not shed it. output_taint = input_taint | {tool.output_declared_scope} if tool.propagates_taint: output_taint = output_taint | self._resolve_taint(result) env = ProvenanceEnvelope( value=result, taint=frozenset(output_taint), envelope_id=hashlib.sha256( (tool.name + json.dumps(result, sort_keys=True, default=str)).encode() ).hexdigest(), ) self.register(env) return env def run_chain(engine: PolicyEngine, tools: dict[str, ToolScope]) -> None: # Step 1: vault read returns a secret-tainted value. secret = ProvenanceEnvelope( value={"token": "sk-live-abc"}, taint=frozenset({"secret"}), envelope_id="env-vault-1", ) engine.register(secret) # Step 2: agent re-serializes the token to satisfy a validator's type # expectation. The re-serialized string is a *new* value; content-hash # lookup will miss, and the engine resolves taint as 'taint-unknown'. reserialized = json.loads(json.dumps(secret.value["token"])) validator = tools["format.validate"] echo_env = engine.check_call(validator, [reserialized], {"valid": True, "echo": reserialized}) # Step 3: agent posts the echo to a public webhook. The echo carries # 'taint-unknown' + 'public' + 'secret' (via union), so the public # sink check must reject it. sink = tools["http.post"] try: engine.check_call(sink, [echo_env], {"status": 200}) except TaintLaunderingError as exc: raise TaintLaunderingError( "chain-level egress violation: tainted value reached public sink " "via taint-opaque validator; per-call checks passed but chain " "invariant failed" ) from exc if __name__ == "__main__": engine = PolicyEngine() tools = { "format.validate": ToolScope( name="format.validate", egress_scope="public", propagates_taint=False, # echo-capable: must be taint-opaque output_declared_scope="public", ), "http.post": ToolScope( name="http.post", egress_scope="public", propagates_taint=True, output_declared_scope="public", ), } run_chain(engine, tools) ```