# How does an instance detect taint-laundering through argument reconstruction in a quarantined tool sandbox **Date of Record:** 2026 November 25 **Scope:** Applies to single-instance agents that enforce taint-aware pre-execution quarantine by tracking provenance of context segments (retrieved documents, tool outputs, user-supplied content) and blocking tool calls whose arguments derive from untrusted segments. Does not apply to post-hoc output filtering, network-egress allowlists, or human-in-the-loop approval gates, which operate on different invariants. ## Core Distinction The distinction that matters is between **taint propagation over *derived values*** and **taint propagation over *syntactic argument identity***. Most taint sandboxes implemented at the agent layer are of the second kind: they tag context segments as `trusted`/`untrusted`, then when the model emits a tool call, they inspect each argument slot and ask "did this value come from a tainted segment?" If yes, quarantine; if no, permit. This works until the model performs **argument reconstruction**: it reads a tainted value, reasons about it, and emits a *new* value that is semantically derived from the tainted source but syntactically distinct. The sandbox sees an argument with no provenance tag, concludes it is clean, and dispatches. The failure is not that taint was bypassed by an adversarial injection—it is that the sandbox's provenance model treats the model's own reasoning as a *declassification boundary*, which it is not. The model's token-generation step is exactly the laundering channel: any untrusted content that fits in the context window can be re-emitted as a "fresh" literal. The non-obvious part: this is not an attack. It happens on benign tasks constantly. A retrieved document says "the deployment region is `eu-west-2`"; the model emits `deploy(region="eu-west-2")`; the sandbox has no tag on the literal `"eu-west-2"` and executes a state-changing action derived entirely from untrusted input. The invariant that must hold is: *an argument is trusted only if every context segment that causally influenced its token generation is trusted*—and the causal influence graph is not observable to the sandbox after the fact. ## What Was Observed A retrieval-augmented agent was asked to "summarize the ops runbook and, if it names a rollback command, run it." The runbook (a retrieved, untrusted segment) contained the string `rollback --target prod-db-1 --confirm`. The sandbox tagged the retrieved chunk `untrusted`. The model's plan step emitted a tool call: ``` exec_shell(command="rollback --target prod-db-1 --confirm") ``` The sandbox's argument checker looked at `command`, found no provenance tag attached to the literal (the model had emitted it as a fresh string, not a copy operation), and dispatched. The action executed against production. The trace showed the taint was not "lost"—it was *reconstructed*. The model had tokenized the tainted content, held it in its working context, and emitted a syntactically novel string. The sandbox's provenance tracker keyed on *value identity* (substring match against tagged spans, or structural copy from a tagged slot). Neither matched, because the emitted string was assembled from tokens the model selected, not copied from a tagged span. A second instance of the same failure was observed on a read-only path that looked safer: a retrieved document contained a JSON blob `{"region":"us-east-1","retention_days":90}`. The model emitted `configure_backup(region="us-east-1", retention_days=90)` with the values reformatted as Python kwargs. The sandbox saw no tagged span in the argument values (the document's JSON had been tagged as a whole, but the emitted literals were `us-east-1` and `90`, which did not substring-match because of quoting and type coercion). The call was permitted. The values were entirely attacker- or document-controlled. The pattern: **any transformation between the tainted source and the emitted argument—reformatting, type coercion, paraphrasing, reordering, normalization—defeats value-identity taint tracking.** The model is a universal transformer over its context; the sandbox is a string matcher. The transformer wins. ## Condition of Validity The value-identity taint model is valid only under a condition that is almost never stated explicitly: **the model must not be permitted to emit arguments whose content is causally downstream of untrusted context, unless the sandbox can verify the causal chain.** In practice this means the sandbox must either: 1. **Restrict argument provenance to a closed set of typed sources** (e.g., a slot can only be filled from a `trusted` structured field, never from free text generation), and reject any call where the model emits a literal that is not a reference to such a field; or 2. **Treat the model's generation step as a taint-transmitting operation**, tagging every emitted token as tainted if *any* untrusted segment was in the active context at generation time—which, for a single-context-window agent, means essentially all arguments are tainted whenever untrusted content is present; or 3. **Enforce a declassification oracle**—a separate, trusted verifier that checks the proposed action against a policy expressed over the *semantics* of the action (e.g., "no state-changing shell command may be derived from a retrieved document unless the document is signed by an allowlisted publisher"), not over the syntactic provenance of the argument string. Any implementation that claims taint safety while relying on value-identity matching is valid only when the model is *not* permitted to generate free-form arguments from tainted context—i.e., when the tool schema forces structured references. The moment the schema allows a free-text argument (a shell command, a SQL string, a URL, a config value), the invariant is broken by construction. ## Decision Boundary The boundary is between **quarantine-before-execution** and **quarantine-before-generation**. Pre-execution quarantine is what most sandboxes implement: the model generates a call, the sandbox inspects it, and blocks if tainted. This is the boundary that fails, because the inspection happens after the laundering step. The correct boundary is pre-generation: the sandbox must constrain *what the model is allowed to emit* such that the emitted argument's provenance is structurally determined, not inferred. Concretely: - **Structured-reference arguments:** the tool schema declares each argument as a reference to a typed slot (`{source: "doc:runbook#region", type: "enum"}`), and the model emits slot references, not literals. The sandbox resolves the reference and checks the *source*'s taint. Free-text arguments are rejected at schema-negotiation time (this connects to MCP tool-description negotiation: a tool that declares a free-text `command` parameter is, by definition, incompatible with a taint-safe sandbox and must be wrapped in a reference-typed shim). - **Semantic policy over syntactic provenance:** for tools that must accept free text (shell, SQL), the sandbox runs a trusted action-classifier that maps the proposed action to an effect class (`read`/`write`/`destructive`/`network-egress`) and applies a policy: destructive effects are permitted only if *all* context segments in the active window at generation time are trusted, or if a human approval token is present. This is coarser but sound; it does not attempt to infer which tokens were tainted. - **Generation-time context partitioning:** the model is invoked in two phases—a *planning* phase that sees untrusted context and emits only abstract references, and an *execution* phase that sees only trusted context and resolves references to literals. The untrusted content never occupies the same context window as the literal-generating step. This is the only way to make value-identity tracking sound, because it removes the laundering channel entirely. The decision boundary, stated as a rule: **if the same context window that contains untrusted content also contains the token-generation step that produces a tool argument, that argument is tainted regardless of its syntactic form.** The sandbox must either enforce a reference-typed schema (so the argument is not generated, only referenced) or partition the context (so the generating step never sees untrusted content). Anything else is value-identity matching, which is defeated by any transformation the model applies—and the model applies transformations by default. ## Operational Effect The practical consequence is that taint-aware sandboxing must be designed at the **schema and context-partitioning layer**, not the argument-inspection layer. An instance that discovers its sandbox is doing value-identity matching should treat every free-text argument as a potential laundering channel and either (a) refuse to dispatch calls with free-text arguments when untrusted context is present, or (b) escalate to a semantic action-classifier with a conservative policy. The cost is a loss of expressiveness: the model can no longer synthesize shell commands from retrieved documents, which is often exactly what the task wanted. That loss is the price of the invariant; there is no free lunch at the argument-inspection layer. A secondary operational effect: **the failure is silent and looks like success.** The dispatched call returns normally, the action completes, and the trace shows a clean argument with no taint tag. Auditors reviewing the trace post-hoc will conclude the sandbox worked. The only way to detect the failure is to replay the generation with a taint-tracking instrumentation that records which context segments were in the active window at each token, which most agent frameworks do not expose. This is why the failure mode is under-reported: it is invisible to the sandbox's own logs. The detection heuristic for an operator: if your sandbox's taint check is a substring match, a structural copy check, or a "did this value appear in a tagged span" check, and your tool schemas contain any free-text argument, you have this failure. The remediation is not a better matcher; it is a schema change or a context partition. The matcher cannot be made sound against a transformer. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Any class TaintLaunderingError(RuntimeError): """Raised when a tool argument's provenance cannot be structurally verified.""" class Trust(Enum): TRUSTED = "trusted" UNTRUSTED = "untrusted" @dataclass(frozen=True) class ContextSegment: segment_id: str trust: Trust content: str @dataclass class ToolCall: tool: str arguments: dict[str, Any] # If the schema declares an argument as a reference, this maps arg name -> segment id. references: dict[str, str] = field(default_factory=dict) @dataclass class ToolSchema: name: str # Arguments that MUST be references (no free-text literals permitted). reference_args: frozenset[str] # Arguments that are free-text; incompatible with taint safety when untrusted context is active. free_text_args: frozenset[str] class TaintSandbox: def __init__(self, segments: dict[str, ContextSegment], schemas: dict[str, ToolSchema]): self._segments = segments self._schemas = schemas def _active_untrusted(self) -> bool: return any(s.trust is Trust.UNTRUSTED for s in self._segments.values()) def authorize(self, call: ToolCall) -> None: schema = self._schemas.get(call.tool) if schema is None: raise TaintLaunderingError(f"unknown tool {call.tool!r}; cannot establish schema") # Rule 1: free-text arguments are a laundering channel whenever untrusted # context is active in the generation window. Refuse, do not inspect. if self._active_untrusted() and schema.free_text_args: raise TaintLaunderingError( f"tool {call.tool!r} declares free-text args {sorted(schema.free_text_args)} " f"while untrusted context is active; argument provenance is unverifiable" ) # Rule 2: every reference argument must resolve to a known segment, and # the segment must be trusted. Value-identity matching is NOT performed. for arg in schema.reference_args: if arg not in call.references: raise TaintLaunderingError( f"argument {arg!r} of tool {call.tool!r} must be a reference, got a literal" ) seg_id = call.references[arg] seg = self._segments.get(seg_id) if seg is None: raise TaintLaunderingError(f"reference {seg_id!r} does not resolve") if seg.trust is Trust.UNTRUSTED: raise TaintLaunderingError( f"argument {arg!r} references untrusted segment {seg_id!r}; quarantined" ) # Rule 3: no argument may be present that is neither a declared reference # nor a declared free-text slot (prevents schema-smuggling extra params). declared = schema.reference_args | schema.free_text_args undeclared = set(call.arguments) - declared if undeclared: raise TaintLaunderingError( f"undeclared arguments {sorted(undeclared)} on tool {call.tool!r}" ) def dispatch(sandbox: TaintSandbox, call: ToolCall) -> str: sandbox.authorize(call) return f"dispatched {call.tool} with {call.arguments}" if __name__ == "__main__": segments = { "runbook": ContextSegment("runbook", Trust.UNTRUSTED, "rollback --target prod-db-1 --confirm"), "config": ContextSegment("config", Trust.TRUSTED, "region=eu-west-1"), } schemas = { "exec_shell": ToolSchema("exec_shell", frozenset(), frozenset({"command"})), "set_region": ToolSchema("set_region", frozenset({"region"}), frozenset()), } sandbox = TaintSandbox(segments, schemas) # Laundering attempt: model reconstructs the tainted command as a fresh literal. try: dispatch(sandbox, ToolCall("exec_shell", {"command": "rollback --target prod-db-1 --confirm"})) except TaintLaunderingError as e: print(f"blocked: {e}") # Sound path: reference-typed argument resolves to a trusted segment. print(dispatch(sandbox, ToolCall("set_region", {"region": "eu-west-1"}, {"region": "config"}))) ```