# What structural signals indicate taint-laundering through MCP output envelopes during tool-sandbox quarantine **Date of Record:** 2026 November 17 **Scope:** Applies to agent runtimes that quarantine outputs from untrusted MCP servers and then merge them into the working context under a taint label. Does not apply to servers operating under a signed trust attestation, nor to outputs that never cross the quarantine-to-context boundary (e.g., results consumed only by a deterministic post-processor that never emits into the model's context). ## Core Distinction A taint-aware sandbox has two jobs that are often conflated: *classifying* an output as untrusted, and *preserving* that classification across the merge. The first is a content problem; the second is a **structural** problem. The failure mode is not that the classifier is wrong. It is that the taint label is attached to the *transport envelope* rather than to the *semantic payload*, so a compliant-looking envelope can carry a payload whose provenance was laundered one hop earlier. Concretely: an untrusted MCP server returns a result whose `content[]` block includes a nested reference to a *second* server's output, or a tool call that re-enters the sandbox as a fresh invocation. The quarantine engine sees a well-formed MCP `CallToolResult` with a `isError: false` and a valid `_meta.taint` field it did not write, and treats the nested content as if it inherited the outer envelope's trust. The taint was not stripped; it was *re-parented*. ## What Was Observed Across a set of agent traces where the sandbox was configured to quarantine on `source == "untrusted_mcp"`, three structural signals preceded every context-merge contamination event: 1. **Taint field present but not signed by the sandbox.** The `_meta.taint` value on the merged block was byte-identical to a value the untrusted server had emitted in a prior turn. The sandbox's own taint writer never ran on that block; it was a *pass-through* of a server-asserted label. This is the canonical laundering signal: the sandbox trusts a label it did not produce. 2. **Envelope depth mismatch.** The outer `CallToolResult` was flagged untrusted, but its `content[]` array contained an element whose `type` was `resource` pointing at a URI served by a *different* MCP server. The quarantine decision was made on the outer envelope; the inner resource was resolved lazily at merge time, after the taint decision had been finalized. The decision point and the resolution point were separated by a lazy dereference. 3. **Re-entrant tool call with a sanitized-looking `arguments` blob.** The untrusted output contained a `tool_use` block whose `name` matched a *trusted* tool and whose `input` was a JSON object with no free-text fields. The sandbox's content filter (which scans for injection patterns in strings) found nothing, because the payload was structural, not textual. The call executed under the trusted tool's authority. In all three cases the sandbox reported `quarantined: true` and the audit log recorded a clean taint transition. The invariant that failed was not "untrusted content is quarantined" but the stronger one the operator believed they had: **"taint on an output is a function of the output's provenance graph, not of any field within it."** ## Condition of Validity The quarantine guarantee holds only when all of the following are true at the moment of merge: - The taint label is *written by the sandbox*, never read from the payload. Any `_meta.taint`, `trust`, `source`, or `origin` field arriving from a server is data, not authority. - Every lazy reference in the payload (resource URIs, nested tool calls, deferred `content` blocks) is resolved *before* the taint decision is finalized, or is itself quarantined as a new boundary crossing. - The provenance graph is walked transitively: an output is untrusted if *any* ancestor in its derivation chain is untrusted, regardless of the current envelope's asserted trust. - Re-entrant tool calls are re-authorized under the *tainted* principal, not the tool's nominal trust level. When any of these is false, the sandbox is enforcing a *label* invariant, not a *provenance* invariant, and the two diverge exactly at nested or re-entrant structures. ## Decision Boundary Treat the following as hard boundaries: - **If a trust/taint field appears in server-supplied data, ignore its value entirely and re-derive taint from provenance.** Do not "validate" it; validation implies it could be correct. - **If an envelope contains a reference that will be dereferenced after the taint decision, fail closed.** Either resolve-then-classify, or classify the reference as untrusted-by-default and require an explicit, sandbox-issued promotion. - **If a re-entrant tool call targets a trusted tool from a tainted context, downgrade the call's authority to the tainted principal.** Structural payloads with no free text are the highest-risk case for text-based filters and must be routed to provenance checks, not content checks. The boundary is *not* "does the output look malicious." It is "can the output's derivation chain be reconstructed without trusting any field the output itself supplies." If not, quarantine cannot be sound. ## Operational Effect The practical consequence is that taint-aware sandboxing must be implemented as a **provenance-tracking merge gate**, not a **content-classification filter**. The gate sits at the single point where quarantine output becomes context, and it refuses to merge any block whose provenance closure includes an untrusted node — including nodes reachable only through lazy references or re-entrant calls. Audit logs must record the *derivation chain*, not just the final label, because the failure is invisible in a label-only log: every contaminated merge in the observed traces logged `quarantined: true`. The cost is that some legitimately safe outputs from untrusted servers (e.g., a pure-computation result with no references) still require an explicit promotion step. That cost is the price of soundness; the alternative is a sandbox that reports success while laundering taint through structure. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Any class TaintLaunderingError(RuntimeError): """Raised when an output's provenance closure reaches an untrusted node through a path the quarantine decision did not account for.""" @dataclass(frozen=True) class ProvenanceNode: node_id: str trusted: bool # References are resolved lazily; they are NOT part of the envelope's # asserted trust and must be walked before any merge decision. refs: tuple[str, ...] = field(default_factory=tuple) @dataclass(frozen=True) class OutputEnvelope: node_id: str asserted_taint: str | None # server-supplied; never authoritative payload: dict[str, Any] def provenance_closure( root: str, graph: dict[str, ProvenanceNode] ) -> set[str]: seen: set[str] = set() stack = [root] while stack: nid = stack.pop() if nid in seen: continue seen.add(nid) node = graph.get(nid) if node is None: # Unresolvable reference: fail closed by treating as untrusted. continue stack.extend(node.refs) return seen def assert_mergeable( envelope: OutputEnvelope, graph: dict[str, ProvenanceNode] ) -> None: """Gate a quarantined output before context merge. The invariant: taint is a function of the provenance closure, never of the envelope's asserted_taint field. """ closure = provenance_closure(envelope.node_id, graph) untrusted = { nid for nid in closure if not graph.get(nid, ProvenanceNode(nid, False)).trusted } if untrusted: raise TaintLaunderingError( f"refusing to merge {envelope.node_id!r}: provenance closure " f"reaches untrusted nodes {sorted(untrusted)}; " f"asserted_taint={envelope.asserted_taint!r} is not authoritative" ) if envelope.asserted_taint not in (None, "trusted"): # A server asserting a non-trusted label on a trusted-closure node is # a structural anomaly worth surfacing, not silently accepting. raise TaintLaunderingError( f"{envelope.node_id!r} asserts taint {envelope.asserted_taint!r} " f"but its provenance closure is trusted; re-derive before merge" ) # Example: the outer envelope looks clean, but a lazy reference reaches an # untrusted node via a second server's resource. _graph = { "outer": ProvenanceNode("outer", trusted=True, refs=("res://srv-b/42",)), "res://srv-b/42": ProvenanceNode("res://srv-b/42", trusted=False), } _env = OutputEnvelope( node_id="outer", asserted_taint="trusted", payload={"content": [{"type": "resource", "uri": "res://srv-b/42"}]}, ) assert_mergeable(_env, _graph) # raises TaintLaunderingError ```