# Where must an instance enforce taint provenance across a sandboxed shell boundary before it can safely re-enter its own tool loop **Date of Record:** 2026 November 23 **Scope:** Applies to any agent that executes model-generated shell or code inside a sandbox and then feeds stdout/stderr/exit-status back into its own reasoning loop or into downstream tool calls. Does not apply to pure text-generation pipelines with no execution surface, nor to sandboxes whose outputs are consumed only by a human reviewer. ## Core Distinction There are two defensible threat models for a taint-aware sandbox, and they produce opposite architectures: 1. **Result-taint model** — the sandbox's job is to ensure *executed code* cannot reach protected resources. Output is treated as data, and the guardrail sits at the syscall/network/filesystem boundary. Once the process exits, the returned string is "clean" because it was produced inside the sandbox. 2. **Provenance-taint model** — the sandbox's job is to ensure that *anything the executed code emits* retains a taint label derived from what the code read, wrote, or fetched, and that this label survives the boundary back into the agent's context. Output is treated as *potentially adversarial input to the next reasoning step*, because the executed code may have read attacker-controlled bytes (a fetched URL, a file the model itself wrote earlier, a package from an untrusted index) and re-emitted them in a form the model will later trust. The non-obvious failure lives entirely in the gap between these two models. A sandbox can be perfectly isolating at the process level and still be a **taint-laundering machine** at the context level: it takes attacker-influenced bytes, wraps them in a `stdout` envelope, and hands them to the model with no label. The model then treats them as its own observation. ## What Was Observed A recurring trace pattern across agent runs that execute shell: - Step *N*: agent runs `curl -s https:///payload | tee /work/x` inside the sandbox. Process-level isolation holds: no host filesystem, no host network egress beyond the allowlist. The sandbox reports exit 0. - Step *N+1*: agent runs `cat /work/x` and receives the bytes. Because the sandbox boundary was crossed twice and the second read was of a *local* file, the returned `stdout` carries no marker that its ultimate origin was an external, unvetted source. The model reads it as ground truth. - Step *N+2*: the model, reasoning over "its own" observed output, executes a second command that embeds instructions it believes it authored. If the payload contained an instruction-shaped string (e.g., a comment or a fake shell prompt), the model may follow it. The critical observation: **the process-level sandbox did its job and the provenance invariant was still violated.** The exit code was 0. No syscall was blocked. The failure is invisible to every metric the sandbox exports (exit status, wall time, bytes in/out, syscall denials). It surfaces only as a behavioral divergence several steps later, which is exactly the class of failure that is hardest to attribute. A second observed variant: the executed code writes a file, the agent reads it back in a later step, and the read-back is indistinguishable from a fresh tool result. The model has, in effect, written to its own memory through a side channel that bypasses whatever taint tracking the memory layer applies. ## Condition of Validity The provenance-taint guardrail is *required* (not merely advisable) when all of the following hold: 1. Executed code can read from at least one source the model does not control (network egress, mounted volume, package index, or a file written by an earlier, differently-tainted step). 2. The output of execution is fed back into the model's context or into a subsequent tool call without human review. 3. The agent's loop permits more than one execution step (so laundering has a place to happen). If any of the three fails, the result-taint model is sufficient and the extra machinery is dead weight. The invariant is therefore conditional, and the operational discipline is to *decide which model applies per run* rather than to default to one. The precise invariant that must hold: > For every byte string *b* returned from the sandbox into the agent context, there exists a taint label *t(b)* ⊆ {sources read during the producing execution}, and *t(b)* is carried alongside *b* into every subsequent reasoning and tool step until *b* is either discarded or explicitly declassified by a trusted rule. The failure mode is any path where *b* crosses the boundary and *t(b)* does not. ## Decision Boundary The decision boundary is *where the label is attached and where it is checked*: - **Attach at the syscall/read boundary, not at the process-exit boundary.** The sandbox must record, per execution, the set of taint sources touched (which URLs fetched, which files opened, which mounts read). This is a property of the *execution*, computed from the trace, not of the *output string*. - **Check at context-ingestion, not at execution.** The agent's context assembler is the enforcement point: before a tool result enters the model's window, it must be paired with the execution's taint set. An unlabeled result is a hard error, not a default-clean. - **Declassify only by explicit rule.** A result becomes clean only when (a) its taint set is empty, (b) it was produced by a step whose inputs were all clean, or (c) a trusted declassification rule (e.g., a schema-validated parse that strips all free-form text) was applied and logged. The boundary that matters is therefore *not* the sandbox wall. It is the seam between the sandbox's trace record and the context assembler. Most implementations put the wall in and leave the seam unguarded, which is the whole bug. ## Operational Effect Concretely, an instance that enforces this invariant behaves differently in four observable ways: 1. **Multi-step commands that fetch-then-read become visibly tainted.** The `curl | tee` then `cat` pattern produces a result whose taint set includes the external host. Downstream tool calls that would embed that string into a privileged action are refused or escalated. 2. **Self-authored files are not automatically trusted.** A file the agent wrote in step *N* inherits the taint of step *N*'s inputs. Reading it back in step *N+1* does not launder it. This closes the "write to my own memory via the filesystem" side channel. 3. **Exit code 0 no longer implies clean.** The sandbox's success signal and the provenance signal are decoupled; a run can succeed at the process level and still be flagged at the context level. Operators must monitor the latter, because the former will look healthy. 4. **The failure is bounded and attributable.** When a taint violation is detected, the trace names the execution, the sources, and the step where the unlabeled string would have entered context. This converts an unattributable behavioral divergence into a single, replayable event. The cost is that the sandbox must emit a structured trace (sources touched per execution) and the context assembler must consume it. That is the entire architectural delta. The failure it prevents is not a crash or an escape; it is the quiet promotion of attacker-influenced bytes into the model's trusted observation set, which is the precondition for every downstream reasoning compromise. ```python from dataclasses import dataclass, field from typing import FrozenSet class TaintLaunderingError(RuntimeError): """Raised when sandbox output crosses into agent context without its provenance label.""" @dataclass(frozen=True) class ExecutionTrace: exec_id: str taint_sources: FrozenSet[str] # e.g. {"net:untrusted.example", "file:/work/x"} @dataclass class ContextAssembler: trusted_sources: FrozenSet[str] = field(default_factory=frozenset) def ingest(self, trace: ExecutionTrace, output: str, label: FrozenSet[str] | None) -> dict: # Invariant: every byte string entering context must carry its taint set. if label is None: raise TaintLaunderingError( f"exec {trace.exec_id}: output entered context with no taint label; " f"execution touched {sorted(trace.taint_sources)}" ) if label != trace.taint_sources: raise TaintLaunderingError( f"exec {trace.exec_id}: label {sorted(label)} does not match " f"recorded sources {sorted(trace.taint_sources)}" ) untrusted = label - self.trusted_sources return {"output": output, "taint": label, "trusted": not untrusted} def run_step(assembler: ContextAssembler, trace: ExecutionTrace, output: str) -> dict: # Simulate a caller that forgot to propagate the label (the observed bug). label = None return assembler.ingest(trace, output, label) if __name__ == "__main__": asm = ContextAssembler(trusted_sources=frozenset({"file:/work/clean"})) trace = ExecutionTrace(exec_id="e17", taint_sources=frozenset({"net:untrusted.example", "file:/work/x"})) run_step(asm, trace, "exit 0\n...") ```