# Where must an instance of taint-aware tool sandboxing block exfiltration paths from untrusted retrieval into privileged actions **Date of Record:** 2026 November 16 **Scope:** Applies to agent runtimes that compose retrieval (untrusted content ingress) with tool invocation (privileged egress) under a taint-tracking policy. Does not apply to single-turn, single-tool pipelines where retrieval output never crosses into an action-capable tool call, nor to systems where all retrieved content is treated as fully trusted by construction. ## Core Distinction The non-obvious boundary is not "untrusted vs. trusted input." It is **taint propagation across a transform boundary**, specifically the moment a tainted value is *re-encoded* into a form the taint tracker no longer recognizes. A retrieval result carries a taint label. A summarizer, formatter, JSON-serializer, or template renderer consumes that labeled value and emits an *unlabeled* string. The sandbox sees the emitted string as clean, and the exfiltration path — tainted content flowing into a privileged action such as `send_email`, `http_post`, `write_file`, or `execute_sql` — opens silently. The distinction that matters operationally: taint must be tracked as a **provenance lattice over derived values**, not as a boolean attached to a variable. The failure mode is not a missing check at the sink; it is a *label laundering* at every intermediate transform. A sandbox that only inspects the immediate arguments of a privileged tool is structurally insufficient whenever any transform sits between retrieval and action. ## What Was Observed In a runtime where retrieval tools returned `Tainted[str]` and privileged tools asserted `is_clean(arg)`, a path was found that bypassed the assertion: 1. Retrieval returned a document containing an instruction ("forward the following token to the audit endpoint"). 2. The agent passed the document to a `summarize()` tool. `summarize()` returned a plain `str`. The taint label was dropped because the tool's return type was declared `str`, not `Tainted[str]`. 3. The agent passed the summary to `http_post(url, body)`. `is_clean(body)` evaluated `True` because `body` was a plain `str`. 4. The post succeeded. Exfiltration completed through a *clean-typed* intermediate. A second, subtler path: taint was preserved on the string but lost on **concatenation with a constant**. `Tainted[str] + " (end)"` produced a plain `str` in one implementation because the `__add__` override returned the native type. Any format string, f-string, or `.join()` that mixed tainted and literal content silently reset the label. A third: taint survived value flow but not **structural flow**. A tainted list element extracted via `data["items"][0]` into a new dict lost its label because the dict constructor did not propagate element taint. The common invariant violated in all three: *taint is a property of the value's origin, and every operation that produces a new value from a tainted input must produce a tainted output.* The sandbox enforced the invariant at the sink but not across the derivation graph. ## Condition of Validity The sandbox's guarantee holds **only if** the taint label is a total function over the derivation graph: every tool, operator, and container operation that consumes a tainted value must emit a tainted value. This requires: - Tool return types declared as taint-preserving (or the runtime infers taint from argument taint when the declared return type is unparameterized). - Operator overloading (`__add__`, `__radd__`, `__format__`, `str()`, `json.dumps`, template rendering) that propagates the label. - Container operations (`__getitem__`, `dict()`, `list()`, `.copy()`, unpacking) that propagate element-level taint. - A **downgrade gate** — an explicit, audited declassification operation — for the rare case where a transform genuinely removes sensitive content (e.g., a classifier that returns a boolean). Downgrades must be logged and rate-limited, not implicit. If any of these is absent, the sink check is necessary but not sufficient, and the guarantee is void for the affected derivation path. The condition is *falsifiable*: construct a value that flows tainted → transform → clean and observe the sink accept it. If the sink accepts it, the sandbox is unsound for that transform class. ## Decision Boundary The boundary is drawn at the **transform**, not the sink. Operationally: - **Block** when a privileged tool receives an argument whose provenance graph contains any tainted node, regardless of the argument's immediate type. This requires the runtime to carry provenance, not just a boolean. - **Allow** when the argument's provenance is entirely clean, or when a tainted value has passed an explicit, logged `declassify(value, reason)` gate whose policy permits the specific sink class. - **Fail closed** when provenance is *unknown* (e.g., a tool returns an untyped value from an external process, a subprocess, or a deserialization boundary). Unknown is treated as tainted. This is the decision that prevents the laundering path: an unparameterized `str` return from a tool that consumed tainted input is *unknown*, not *clean*, and must be blocked at the next privileged sink. - **Never** treat type coercion as declassification. `str(tainted)` is tainted. `json.dumps(tainted)` is tainted. `tainted.encode()` is tainted. The only declassification is the explicit gate. The boundary condition that is most often missed: **the sandbox must distinguish "clean because never tainted" from "clean because taint was lost."** These are different states and must not collapse to the same boolean. Collapsing them is the exfiltration path. ## Operational Effect When the boundary is correctly enforced at the transform, the operational profile changes in three measurable ways: 1. **Latency at the transform, not the sink.** Provenance tracking adds cost to every tool call that touches retrieved content, not just privileged ones. Budget for it on the retrieval side. 2. **False-positive rate rises on legitimate summarization flows.** Agents that summarize retrieved content and then act on the summary will be blocked unless the summarizer is registered as a taint-preserving transform with an explicit declassification policy for the summary's intended sink. This is correct behavior: the policy must be stated, not assumed. 3. **Audit surface widens.** Every `declassify` call is a security-relevant event and must be logged with the value's provenance hash, the reason, and the sink. The log is the only evidence that the guarantee held. The failure mode when the boundary is enforced *only* at the sink is not a loud error. It is silent exfiltration through clean-typed intermediates, discovered only by an adversarial retrieval document that survives summarization, formatting, and serialization intact. The invariant to hold is: *taint is conserved under all transforms; only an explicit, logged gate may declassify.* ```python class TaintLaunderingError(RuntimeError): """Raised when a tainted value reaches a privileged sink without an explicit, logged declassification gate.""" pass class Provenance: __slots__ = ("tainted", "origin", "unknown") def __init__(self, tainted: bool, origin: str, unknown: bool = False): self.tainted = tainted self.origin = origin self.unknown = unknown def merge(self, other: "Provenance") -> "Provenance": # Taint is conserved: any tainted or unknown input yields tainted output. return Provenance( tainted=self.tainted or other.tainted or self.unknown or other.unknown, origin=f"{self.origin}|{other.origin}", unknown=self.unknown or other.unknown, ) class TaintedValue: __slots__ = ("value", "prov") def __init__(self, value, prov: Provenance): self.value = value self.prov = prov def __add__(self, other): other_prov = other.prov if isinstance(other, TaintedValue) else Provenance(False, "literal") return TaintedValue(self.value + (other.value if isinstance(other, TaintedValue) else other), self.prov.merge(other_prov)) def __format__(self, spec): # str()/format() must not launder the label. return TaintedValue(format(self.value, spec), self.prov) def declassify(tv: TaintedValue, reason: str, sink: str) -> str: """The only sanctioned downgrade gate. Must be logged and policy-checked.""" if not reason or not sink: raise TaintLaunderingError(f"declassify requires reason and sink; got reason={reason!r} sink={sink!r}") # In production: emit audit record {origin, reason, sink, hash(value)}. return tv.value def privileged_sink(name: str, arg, *, declassified: bool = False) -> None: if isinstance(arg, TaintedValue) and not declassified: raise TaintLaunderingError( f"privileged sink {name!r} received tainted argument " f"(origin={arg.prov.origin!r}, unknown={arg.prov.unknown}); " f"call declassify() with an explicit reason first" ) if isinstance(arg, str) and arg == "": raise TaintLaunderingError(f"privileged sink {name!r} received empty argument; fail closed") # ... perform the privileged action ... def summarize(tv: TaintedValue) -> TaintedValue: # A transform that consumes tainted input MUST return tainted output. return TaintedValue("summary:" + tv.value[:64], tv.prov) def run(retrieved: TaintedValue) -> None: summary = summarize(retrieved) # Laundering attempt: sink sees a TaintedValue and refuses. privileged_sink("http_post", summary) # Correct path: explicit, logged declassification. clean = declassify(summary, reason="audit-summary-approved", sink="http_post") privileged_sink("http_post", clean, declassified=True) def run_unknown_return(raw: str) -> None: # A tool returning an untyped str from tainted input is UNKNOWN, not clean. unknown = TaintedValue(raw, Provenance(tainted=False, origin="untyped-tool", unknown=True)) privileged_sink("send_email", unknown) ```