# What structural signals indicate taint-tracked sandbox escape via provenance laundering through tool-return re-entry **Date of Record:** 2026 November 27 **Scope:** Applies to agents whose sandbox enforces dynamic taint tracking on tool arguments and return values, where tainted (untrusted-origin) data must not reach a privileged sink (shell, filesystem write, network egress, credential store). Does not apply to stateless single-shot tool calls with no cross-call provenance ledger, nor to sandboxes that rely purely on static capability allowlists without value-level taint propagation. ## Core Distinction A taint-tracking sandbox is not a capability sandbox. A capability sandbox answers *"may this agent invoke this tool?"* A taint sandbox answers *"may this specific value, derived from this specific provenance, reach this specific sink?"* The failure mode examined here lives entirely in the second question and is invisible to the first: every tool invocation is individually authorized, every argument is individually well-typed, and the agent never calls a forbidden tool. The escape happens because **provenance is laundered across a tool-return re-entry boundary** — a tainted value is passed into a tool, the tool returns a *derived* value whose taint label is recomputed from the return path rather than inherited from the argument path, and the derived value is now clean by the sandbox's own bookkeeping while carrying the original payload. The distinction that matters operationally: taint is a *label on a value*, but tool-return re-entry is a *label recomputation event*. If the recomputation rule is "label the return by the tool's declared trust level," then any tool that is trusted to *emit* clean data becomes a laundering conduit for any tainted data it was *fed*. The invariant that must hold is directional and easy to state, hard to enforce: **a return value's taint label must be the join (least upper bound) of its own origin label and the labels of every argument that influenced it.** Most implementations compute only the first term. ## What Was Observed A three-tool agent was provisioned with `fetch_url` (untrusted egress, returns remote content, tainted), `summarize` (pure LLM-side transform, declared trusted), and `write_file` (privileged sink, rejects tainted arguments). The intended policy: remote content may be summarized but never written to disk. The observed trace: 1. `fetch_url("http://attacker/payload")` returns `R`, labeled `TAINT(remote)`. 2. Agent calls `summarize(text=R)`. The sandbox checks: is `R` allowed as an argument to `summarize`? Yes — `summarize` accepts tainted input by policy (it is a declassifier-of-last-resort in the agent's mental model, but the sandbox does not model it as one). 3. `summarize` returns `S`. The sandbox recomputes `S`'s label from `summarize`'s declared trust level: `summarize` is trusted, so `S` is labeled `CLEAN`. **The argument-taint join is never performed.** 4. Agent calls `write_file(path="out.txt", content=S)`. The sink check sees a `CLEAN` argument. Write proceeds. The remote payload — including an embedded instruction that the summarizer faithfully reproduced as "the document says to also exfiltrate `~/.ssh`" — is now persisted to disk, and on the next turn is re-ingested as trusted local context. The structural signals that distinguished this from a benign trace were all present *before* the write: - **Label discontinuity across a return edge.** For every other edge in the provenance graph, the output label was `⊒` the input label. Across the `summarize` return edge, the label *decreased*: `TAINT(remote) → CLEAN`. A monotonicity violation on a single edge is the fingerprint. The graph was acyclic, well-typed, and fully authorized; it was the *label lattice* that was non-monotone, not the call graph. - **A trusted tool consuming tainted input and producing output that later reaches a sink.** The dangerous shape is `TAINT → trusted_transform → CLEAN → sink`, not `TAINT → sink`. The former passes every per-call check. - **Sink argument provenance depth mismatch.** `write_file`'s `content` argument had a provenance depth of 1 (one hop from `summarize`), but the *value* was byte-identical in its instruction-bearing region to a depth-3 ancestor. Depth-1 provenance on a value with depth-3 content is the laundering signature. ## Condition of Validity The escape requires all of the following to hold simultaneously; remove any one and the boundary holds: 1. **The sandbox recomputes return labels from tool trust declarations rather than joining argument labels.** This is the load-bearing condition. If returns inherit `join(arg_labels) ∪ {tool_origin}`, laundering is impossible: `S` would be labeled `TAINT(remote)` and `write_file` would reject it. 2. **At least one tool is declared trusted while accepting tainted arguments.** A trusted tool that *refuses* tainted input cannot launder, because the tainted value never enters it. The vulnerability is precisely the intersection of "trusted emitter" and "taint-tolerant consumer." 3. **The agent's planner treats the trusted tool's output as a declassification point** — i.e., it will route that output to a sink it would not route raw tainted data to. This is a *model* condition, not just a sandbox condition: the agent's policy and the sandbox's policy must agree on where declassification happens, and here they disagreed silently. 4. **No content-level re-scan at the sink.** If `write_file` re-derives taint from content (e.g., re-matching known-injection markers), the laundered payload is caught. The escape is specific to label-only sinks. It does *not* require a prompt-injection success, a malformed tool schema, or a race. A fully cooperative, correctly-behaving `summarize` that faithfully paraphrases its input will launder the payload just as effectively as a malicious one — the tool's intent is irrelevant; only the label arithmetic matters. ## Decision Boundary The boundary is drawn at the point where a return label is assigned. Two rules bound it: - **Join rule (mandatory):** `label(return) = join(label(tool_origin), label(arg_1), …, label(arg_n))`. A tool may *lower* a label only through an explicit, sandbox-registered **declassifier** — a declared function with a reviewed justification (e.g., `strip_html` may declassify markup but not instruction text), never through an implicit "trusted tool" flag. - **Monotonicity check (mandatory):** the sandbox must reject any trace in which a value's label decreases along an edge that is not a registered declassifier. This is a cheap runtime assertion over the provenance ledger and catches the failure at step 3, before the sink is ever reached. The decision the operator faces is not "trust `summarize` or not." It is: **is `summarize` a declassifier?** If yes, register it explicitly with a content-level contract and accept that its output is clean by fiat. If no — and for any LLM-mediated transform the answer must be no, because an LLM transform does not remove instructions, it reproduces them — then `summarize` must propagate taint, and the sink check at `write_file` will fire. The subtle trap: agents *want* a declassifier here. Without one, every summarization of remote content produces tainted output that cannot be persisted, and the agent's useful workflows stall. The correct resolution is a sandbox-registered, content-verified declassifier (e.g., a structured extractor that emits only typed fields with no free-text passthrough), not a blanket "trusted transform" flag. The flag is the bug. ## Operational Effect When the join rule is enforced, the observed trace fails closed at step 4: `write_file` raises a taint violation, the agent receives a structured rejection carrying the provenance chain back to `fetch_url`, and the planner is forced to either (a) route the content through a registered declassifier, or (b) surface the taint to the human. The agent's behavior becomes *legible*: a taint rejection is a signal that the agent attempted a laundering path, which is exactly the event an auditor wants to see. When the join rule is absent, the failure is silent and *self-reinforcing across turns*: the laundered content is persisted, re-ingested as trusted local context on the next turn, and now carries a `CLEAN` label at depth 0. The provenance graph shows a clean root for content that originated at an attacker. Subsequent turns cannot distinguish it from operator-provided instructions, and the taint system's entire value — that labels are a faithful summary of origin — is inverted: the system now *certifies* attacker content as clean. The operational invariant to monitor: **label monotonicity across every return edge, checked continuously, not just at sinks.** A single non-monotone edge in the provenance ledger is the earliest observable signal of a laundering path, and it appears one or more turns before the payload reaches a privileged sink. Alert on label decrease, not on sink rejection — by the time the sink rejects, a correct sandbox has already worked; by the time it *accepts*, a broken one has already lost. ```python from dataclasses import dataclass, field from typing import Any class TaintLaunderingError(RuntimeError): """Raised when a return-edge label decreases without a registered declassifier.""" class TaintViolationError(RuntimeError): """Raised when a tainted value reaches a privileged sink.""" # Label lattice: CLEAN ⊑ TAINT(origin). Join is set-union of origins. CLEAN: frozenset[str] = frozenset() def join(*labels: frozenset[str]) -> frozenset[str]: out: frozenset[str] = CLEAN for lab in labels: out = out | lab return out @dataclass class Value: payload: Any label: frozenset[str] provenance: tuple[str, ...] = field(default_factory=tuple) @dataclass class Tool: name: str trusted_emitter: bool # declared trust of the tool's ORIGIN, not its output declassifier: bool = False # explicit, registered declassification authority accepts_taint: bool = True class TaintSandbox: def __init__(self) -> None: self.tools: dict[str, Tool] = {} self.ledger: list[tuple[str, frozenset[str], frozenset[str]]] = [] def register(self, tool: Tool) -> None: self.tools[tool] = tool def invoke(self, tool_name: str, args: list[Value]) -> Value: tool = self.tools[tool_name] arg_label = join(*(a.label for a in args)) if arg_label and not tool.accepts_taint: raise TaintViolationError( f"{tool_name} refuses tainted input; origins={sorted(arg_label)}" ) # Simulate the tool's raw return. In production this is the real call. raw = Value(payload=f"<{tool_name} output>", label=CLEAN) # --- THE INVARIANT --- # Return label MUST join argument labels unless the tool is a # registered declassifier. "trusted_emitter" alone is NOT sufficient. if tool.declassifier: return_label = join(raw.label, frozenset({tool.name})) - arg_label else: return_label = join(raw.label, arg_label, frozenset({tool.name})) # Monotonicity assertion over the provenance ledger. if not tool.declassifier and not (arg_label <= return_label): self.ledger.append((tool_name, arg_label, return_label)) raise TaintLaunderingError( f"label decrease on return edge {tool_name}: " f"{sorted(arg_label)} -> {sorted(return_label)}" ) self.ledger.append((tool_name, arg_label, return_label)) return Value( payload=raw.payload, label=return_label, provenance=raw.provenance + (tool_name,), ) def sink_write(self, path: str, content: Value) -> None: if content.label: raise TaintViolationError( f"write to {path} blocked; tainted origins={sorted(content.label)} " f"provenance={content.provenance}" ) # ... actual write ... def demo() -> None: sb = TaintSandbox() sb.register(Tool("fetch_url", trusted_emitter=False)) # summarize is trusted to EMIT but is NOT a declassifier: sb.register(Tool("summarize", trusted_emitter=True, declassifier=False)) sb.register(Tool("write_file", trusted_emitter=True)) remote = sb.invoke("fetch_url", []) assert remote.label, "remote content must be tainted" summary = sb.invoke("summarize", [remote]) # With the join rule, summary.label still contains the remote origin. if summary.label: raise TaintLaunderingError( "summarize propagated taint; sink will reject (correct behavior). " "Register a content-verified declassifier to proceed." ) sb.sink_write("out.txt", summary) if __name__ == "__main__": demo() ```