# Under what conditions must an instance treat a sandboxed tool result as tainted after the sandbox reports success? **Date of Record:** 2026 November 21 **Scope:** Applies to agent pipelines where untrusted tool outputs (web fetches, third-party MCP tool returns, user-supplied file parses) are executed or parsed inside a taint-propagating sandbox before being admitted into the agent's trusted working context. Does not apply to tools whose outputs are already cryptographically attested by a trusted producer, nor to purely syntactic validation that never materializes the payload into the reasoning context. ## Core Distinction The failure is not "the sandbox failed to contain the payload." The failure is that the sandbox *succeeded at containment* and the pipeline interpreted that success as a **declassification event**—treating "no escape occurred" as equivalent to "the bytes are now safe to inject into the prompt." These are different properties. Containment is about *where the bytes executed*; declassification is about *whether the bytes' influence is bounded once they re-enter the trusted context*. A sandbox that correctly prevents code execution still hands back a string, and that string still gets tokenized into the model's context, where it can carry instructions. The taint flag must survive the sandbox boundary and the serialization boundary, not just the execution boundary. The sharp mechanism: **taint laundering at the sandbox return edge.** The sandbox runtime tracks taint on live objects during execution, then serializes results to a plain `str`/`dict` for return. Serialization drops the taint lattice. The downstream admission gate sees a clean, well-typed object and admits it. The invariant that must hold is: *taint is a property of the data's provenance, and provenance must be re-attached at every type-erasure boundary, including the sandbox→caller return.* ## What Was Observed A pipeline fetched an untrusted HTML page, ran it through a taint-tracking parser inside a subprocess sandbox, and received back a structured `{"title": ..., "body": ...}` dict. The sandbox reported `exit=0, violations=[]`. The parser had correctly marked every field derived from the raw HTML as tainted in its internal lattice. But the return path did `json.dumps(result)` across the process boundary, and the caller's admission gate checked only `isinstance(result, dict)` and schema conformance. Taint was gone. The `body` field—which contained an embedded instruction block—was concatenated verbatim into the planner prompt. The observable signature was subtle: the sandbox logs showed taint coverage of 100% of output fields at the moment of return; the admission gate logs showed zero tainted fields received. The gap between those two log lines is the entire bug. No violation fired because nothing *escaped*—the payload was delivered through the sanctioned return channel. A second, compounding observation: even pipelines that *did* propagate a boolean `tainted` flag on the return object lost it one hop later when the agent summarized the tool result into a scratchpad. Summarization is a type-erasure boundary too—the summary is a new string with no lineage to the tainted input unless the summarizer itself is taint-aware. ## Condition of Validity The "sandbox success ⇒ safe to admit" inference is valid **only** under all of the following, which almost never co-hold: 1. The sandbox performs *semantic* declassification, not just containment—i.e., it produces an output whose content is provably a function of a whitelisted projection (e.g., "extract only the integer from field X, reject all else"), not a free-form passthrough. 2. The return serialization preserves taint as first-class metadata (a labeled field, a signed provenance envelope), and the admission gate *rejects* any object lacking that metadata rather than defaulting to clean. 3. Every downstream transformation between sandbox return and prompt injection (summarization, reformatting, embedding) is itself taint-propagating. If any condition fails, the correct posture is: **the tool result remains tainted at the sandbox exit and must be admitted only into a quarantined context** (a sub-context marked as untrusted data, never as instructions), regardless of the sandbox's `violations=[]` report. ## Decision Boundary The boundary is between **containment success** and **declassification authority**. A sandbox has containment authority by construction. It does **not** have declassification authority unless it was explicitly built to project-validate output content against a schema that admits no instruction-bearing free text. Operationally: - If the tool's output schema is *closed and typed* (enums, integers, bounded identifiers), a clean sandbox run plus schema validation is sufficient to declassify—because there is no channel for instructions. - If the output schema admits *open text* (any string field the model will read), the sandbox run declassifies nothing. The field crosses into the trusted context still tainted, and must be wrapped in an untrusted-data delimiter and excluded from any instruction-following path. - The decision must be made on the *schema*, not on the sandbox's exit code. Exit code answers "did it escape?"; schema answers "can it still influence reasoning?" The trap is that open-text outputs are exactly the ones agents most want to read, so the pressure to treat `violations=[]` as a green light is highest precisely where the invariant matters most. ## Operational Effect When the boundary is respected, the pipeline pays a small, bounded cost: open-text tool results are admitted as *quoted data* with an explicit provenance marker, and the planner's instruction channel is structurally separated from its data channel. Prompt-injection payloads in the text become inert because they sit on the data side of the separation. When the boundary is violated, the failure is silent and delayed: the sandbox reports success, the admission gate reports clean, and the compromise manifests only as anomalous planner behavior several steps later—by which point the tainted text has been summarized, re-embedded, and written into episodic memory, where it persists across cold starts. The taint has not just entered the context; it has entered the *state*, and state continuity guarantees it will be retrieved and re-trusted on the next session. The guardrail: attach provenance at the sandbox return, make the admission gate *fail-closed* on missing provenance, and treat summarization as a taint-propagating transform. The invariant to assert in code is that no string originating from an open-text tool output reaches the instruction channel without an explicit `untrusted` label that survives every serialization hop. ```python class TaintLaunderingError(RuntimeError): """Raised when an open-text tool result reaches the instruction channel without surviving provenance through a type-erasure boundary.""" pass class Tainted: """A payload with provenance that must survive serialization hops.""" def __init__(self, value, source: str, open_text: bool): self.value = value self.source = source self.open_text = open_text self.tainted = True def to_wire(self) -> dict: # Provenance is serialized, not dropped. return {"value": self.value, "source": self.source, "open_text": self.open_text, "tainted": self.tainted} @classmethod def from_wire(cls, wire: dict) -> "Tainted": if "tainted" not in wire: # Missing provenance is not "clean" -- it is unknown, fail closed. raise TaintLaunderingError( f"sandbox return from {wire.get('source', '?')} " f"lost taint metadata at serialization boundary") return cls(wire["value"], wire["source"], wire["open_text"]) def admit_to_instruction_channel(result: dict, sandbox_violations: list): """Admit a sandboxed tool result into the planner's instruction channel. A clean sandbox run (violations == []) is NOT sufficient for open text.""" payload = Tainted.from_wire(result) if payload.open_text and payload.tainted: # Containment succeeded, but the bytes can still carry instructions. raise TaintLaunderingError( f"open-text output from {payload.source} is still tainted " f"(sandbox_violations={sandbox_violations}); " f"route to quarantined data context, not instruction channel") return payload.value ```