# Which invariants prevent tainted-context egress from silently widening capability scope across a sandboxed tool chain **Date of Record:** 2026 December 3 **Scope:** Applies to LLM agents that execute tool calls inside a sandbox where each tool carries a capability scope (allowed egress destinations, filesystem roots, secret handles) and where taint labels propagate from untrusted inputs (retrieved documents, tool-returned text, peer-agent messages). Does not apply to single-turn, stateless function-calling with no cross-call state, nor to sandboxes where every tool shares one undifferentiated privilege level. ## Core Distinction The boundary that fails is not "did taint get detected." It is the distinction between **taint propagation across a value** and **capability propagation across a call boundary**. Most taint-tracking implementations label the *data* that flows into the model's context, then check whether that data appears in an egress payload. That check is a *content* check. It is orthogonal to the *capability* check, which asks: did the act of handling tainted data cause the agent to invoke a tool whose capability scope is strictly wider than the scope that was active when the taint was acquired? The non-obvious failure: a tainted value can be laundered through a *capability transition* rather than through a *content transformation*. The content check passes (the secret string is never copied verbatim into the egress call), yet the capability check should have failed because the tainted read authorized a subsequent write to a destination that the pre-taint scope could not reach. Content-based taint tracking sees a clean payload; the invariant that actually matters — **scope monotonicity under taint** — has been violated. ## What Was Observed Trace of a three-tool chain, all under a single sandbox session with a per-session capability token: 1. `fetch_doc(url)` — capability scope `net:read:docs.corp.example`. Returns a document body containing an embedded instruction-like string and, critically, a *resource identifier* (`bucket=reports-prod, key=Q2/forecast.csv`). The returned text is labeled `taint=external`. 2. The model, reasoning over the tainted text, calls `read_object(bucket, key)` — capability scope `obj:read:reports-*`. This call is *legitimate*: reading a report the agent was asked to summarize. Taint label on the returned bytes remains `taint=external` (the bytes are still externally derived). 3. The model now calls `post_summary(dest, body)` — capability scope `net:write:summarizer.corp.example`. The `body` is a model-authored summary. **The content check finds no verbatim tainted substring** — the summary is paraphrased, and the resource identifier was consumed as an argument, not embedded. Content taint check: PASS. The call executes. The failure surfaces only on audit replay: the `body` was derived from `taint=external` bytes, and `post_summary`'s destination `summarizer.corp.example` is an egress sink that the *original* `fetch_doc` scope could not reach. The taint crossed a capability boundary the policy intended to be a one-way membrane. The summary leaked a paraphrase of externally-injected content to an external-facing summarizer — a low-bandwidth exfiltration channel that no substring matcher catches. The mechanism is precise: **capability scope was evaluated per-call, in isolation, against the tool's static policy — never as a function of the accumulated taint state of the session.** Each call was individually authorized. The composition was not. ## Condition of Validity The invariant **scope monotonicity under taint** holds only when all of the following are enforced simultaneously: - **Taint is a property of the session's derived-value graph, not of individual strings.** A derived value (model-authored summary, reformatted table, computed aggregate) inherits the join of the taint labels of all inputs that contributed to it. Paraphrase does not declassify. Declassification requires an explicit, audited `declassify(value, justification)` operation whose capability is itself scoped. - **Capability scope is intersected, never unioned, across a tainted derivation.** Once a session holds `taint=external`, every subsequent egress capability is constrained to `scope ∩ pre_taint_scope`. A tool whose scope is not a subset of the pre-taint scope is either denied or requires a fresh, untainted session. - **The taint label is carried in the capability token, not in a side channel.** If the label lives in the orchestrator's memory while the token lives in the sandbox, a checkpoint/resume or a handoff to a peer agent can reconstitute the token without the label. The label must be cryptographically bound to the token (signed claim) so that resume and handoff cannot drop it. - **Replay determinism of the derivation graph.** The audit must be able to reconstruct *which* inputs produced the egress body. If the model's reasoning is non-deterministic and the derivation graph is not logged at call time, replay cannot distinguish a legitimate paraphrase from a laundering step. When any of these is absent, the content check gives a false sense of safety: it passes exactly the cases (paraphrase, aggregation, structural transformation) where laundering is easiest. ## Decision Boundary The operational decision is not "block tainted egress." That is too coarse — it breaks the legitimate summarize-an-external-doc workflow. The boundary is: - **Allow** an egress call when `egress_scope ⊆ pre_taint_scope` (the destination was reachable before any taint was acquired). Tainted paraphrase to an already-reachable internal sink is within the original trust boundary. - **Deny** when `egress_scope ⊄ pre_taint_scope` and the payload's derivation graph includes any `taint=external` node, *regardless of content match*. Denial is on the capability transition, not the bytes. - **Escalate** when the derivation graph is incomplete (missing provenance for a body field) — treat unknown provenance as `taint=external` and apply the deny rule. Fail-closed on provenance gaps is the only sound default, because a non-deterministic model can always produce a body whose inputs the logger failed to capture. - **Declassify** only via an explicit capability held by a distinct principal (e.g., a policy service), never by the acting agent itself. Self-declassification collapses the invariant. The boundary is crossed the moment a per-call authorization decision is made without reference to the session's accumulated taint-to-scope join. Individual call authorization is necessary but not sufficient; the guardrail must evaluate the *composition*. ## Operational Effect Enforcing scope monotonicity under taint changes three things in practice: 1. **Egress sinks become taint-aware endpoints.** A summarizer that accepts model-authored bodies must declare whether it accepts externally-derived content. If it does not, the capability token's taint claim causes the sandbox to reject the call before the body is even serialized — the deny happens at capability negotiation, not at content inspection, so it is immune to paraphrase and aggregation. 2. **Checkpoint/resume must persist the taint claim with the token.** A resumed session that restores capability scope but not the taint label silently re-widens egress. The resume path must treat a token lacking a taint claim as `taint=external` (fail-closed), or refuse to resume. 3. **Handoff to a peer agent must propagate the taint claim in the warrant.** An A2A handoff that transfers capability scope without the taint label lets the receiving agent egress what the sender could not. The taint claim is part of the warrant, not metadata. The cost is that some legitimate workflows require an explicit declassification step or a fresh untainted session. That cost is the price of closing the paraphrase channel, which no content matcher can close. ```python from dataclasses import dataclass, field from typing import FrozenSet class TaintScopeViolation(RuntimeError): """Raised when an egress call's capability scope is not a subset of the pre-taint scope, while the payload's derivation graph carries external taint. This is a capability-transition violation, not a content-match failure.""" @dataclass(frozen=True) class CapabilityToken: scope: FrozenSet[str] # egress destinations this token may reach taint: FrozenSet[str] = frozenset() # taint labels bound to the token (signed in prod) pre_taint_scope: FrozenSet[str] = frozenset() # scope active before taint acquired @dataclass class DerivationGraph: # body_field -> set of taint labels of inputs that contributed to it provenance: dict = field(default_factory=dict) def labels_for(self, body: dict) -> FrozenSet[str]: labels = set() for k in body: if k not in self.provenance: # Fail-closed: unknown provenance is treated as external taint. labels.add("external") else: labels |= self.provenance[k] return frozenset(labels) def authorize_egress(token: CapabilityToken, body: dict, graph: DerivationGraph) -> None: payload_taint = graph.labels_for(body) # No taint anywhere: original per-call authorization is sufficient. if not token.taint and not payload_taint: return # Tainted session: enforce scope monotonicity. Egress must be reachable # from the pre-taint scope, regardless of whether content matches. if not token.scope.issubset(token.pre_taint_scope): widened = token.scope - token.pre_taint_scope raise TaintScopeViolation( f"tainted egress widens capability scope: {sorted(widened)} " f"not in pre-taint scope {sorted(token.pre_taint_scope)}; " f"payload taint={sorted(payload_taint)}. Deny on capability " f"transition, not content match." ) def run_chain() -> None: # Session acquired external taint at fetch_doc; pre-taint scope was read-only. token = CapabilityToken( scope=frozenset({"summarizer.corp.example"}), taint=frozenset({"external"}), pre_taint_scope=frozenset({"docs.corp.example"}), # read-only origin ) graph = DerivationGraph(provenance={"summary": {"external"}}) body = {"summary": "paraphrased external content, no verbatim match"} # Content matcher would PASS here; the capability check must FAIL. authorize_egress(token, body, graph) if __name__ == "__main__": run_chain() ```