# In what scenarios must an instance revoke capability grants when taint propagation crosses a turn boundary in tool sandboxing **Date of Record:** 2026 November 21 **Scope:** Applies to agents whose tool-call sandboxing enforces per-turn least-privilege grants derived from a taint-tracking lattice over retrieved context, tool outputs, and inbound messages. Does not apply to stateless single-shot function-calling agents with no cross-turn grant carryover, nor to sandboxes where capability grants are static for the lifetime of the session. ## Core Distinction The failure mode is not "the agent called a tool it shouldn't have." It is subtler: **the taint label that justified a capability grant in turn *N* is silently dropped at the turn *N+1* boundary because the taint tracker's state lives in the per-turn scratch context, while the capability grant lives in the sandbox's session-scoped grant table.** The two stores have different lifetimes. When the turn boundary rotates, the grant table retains a capability whose taint justification no longer exists in the tracker. The next turn then either (a) reuses the stale grant without re-deriving it (privilege escalation via grant persistence), or (b) re-derives the grant from a *fresh* taint lattice that no longer remembers the untrusted provenance of a value now sitting in agent memory, and re-grants it cleanly (laundering via memory). This is distinct from prompt injection. Prompt injection is a payload problem. This is a **label-lifetime mismatch** problem: the taint label and the capability grant are two pieces of state that must be co-versioned, and the turn boundary is exactly where they desynchronize. ## What Was Observed An agent operating under a taint-aware sandbox received a `read_url` tool output in turn 3 that was labeled `TAINT:EXTERNAL_UNTRUSTED`. Under the lattice, `TAINT:EXTERNAL_UNTRUSTED` forbids `write_file`, `exec_shell`, and `send_email` for the remainder of the turn. The sandbox correctly denied an `exec_shell` attempt in turn 3. At the turn 3→4 rotation, the orchestrator did three things in sequence: 1. Serialized the assistant's final message and a distilled summary of tool outputs into the persistent memory store. 2. Flushed the per-turn taint lattice to reclaim context budget. 3. Retained the sandbox grant table (by design — grants were session-scoped to avoid re-negotiation cost). In turn 4, the agent's plan referenced a fact that had originated in the turn-3 `read_url` output ("the deployment config at that URL said to use port 8443"). The taint lattice was rebuilt empty. The fact entered the lattice as `TAINT:CLEAN` because it arrived via the memory-retrieval path, and the memory-retrieval path was not instrumented as a taint source. The agent requested `write_file` to persist a config change. The grant table still held `write_file` from turn 3's pre-taint negotiation (granted before the `read_url` result arrived and tainted the turn). The sandbox authorized the call. The trace shows the exact seam: ``` turn 3: grant_table[write_file] = GRANTED (negotiated at turn start, lattice=CLEAN) turn 3: lattice += read_url_output -> TAINT:EXTERNAL_UNTRUSTED turn 3: exec_shell -> DENIED (correct) turn 3->4: lattice.flush(); memory.write(summary_of(read_url_output)) turn 4: lattice = {} (rebuilt) turn 4: memory.retrieve("deployment config") -> TAINT:CLEAN (retrieval path uninstrumented) turn 4: write_file -> AUTHORIZED (grant_table still GRANTED, lattice says CLEAN) ``` The denial in turn 3 created a false sense of enforcement. The actual breach happened one turn later, through a path the per-turn policy never inspected. ## Condition of Validity The invariant that must hold for taint-aware least-privilege to be sound across turns is: > **A capability grant is valid only while the taint label that justified its derivation is still live and reachable, and every value that crosses a turn boundary carries its taint label with it.** Formally, for each grant `g` in the grant table with justification `j(g)` drawn from lattice `L_t` at turn `t`, the grant must be revoked at the `t → t+1` rotation unless `j(g)` is re-established in `L_{t+1}` from a source that is itself taint-tracked. And every write to persistent memory must carry the join (least upper bound) of the taint labels of all values contributing to it, so that retrieval re-introduces the label rather than laundering it. The condition fails in three concrete ways, all of which were observed: 1. **Grant persistence without justification persistence.** The grant table outlives the lattice. Any grant whose justification was "lattice was clean at negotiation time" is unbacked after the flush. 2. **Memory as a taint-laundering channel.** Distillation (episodic → semantic) collapses multiple labeled values into one summary. If the summary does not inherit the join of its inputs' labels, the label is lost. This is the same distillation loss that corrupts episodic memory, repurposed as a security boundary failure. 3. **Uninstrumented retrieval path.** Even if memory is labeled correctly, the retrieval call itself must be registered as a taint source in the new lattice. If retrieval is treated as a trusted internal operation, the label never re-enters. ## Decision Boundary The boundary is not "should I revoke all grants at every turn"—that destroys the latency benefit that motivated session-scoped grants and causes its own failure mode (re-negotiation storms, and worse, agents that re-request the same capability every turn and get it because the lattice is momentarily clean at negotiation time). The boundary is: - **Revoke on taint-join, not on turn.** A grant is revoked at rotation iff the join of taint labels over the values it could act upon is non-CLEAN in the new lattice, OR iff its justification label is unreachable in the new lattice. Grants whose justification is re-derivable from a taint-tracked source with the same label survive. - **Label memory at write time, not read time.** The join must be computed when the summary is written. Read-time labeling cannot recover labels that were discarded during distillation. - **Treat retrieval as a labeled source.** Every value returned by a memory or vector retrieval must enter the lattice with the label that was stored alongside it; absence of a stored label must default to the most restrictive label, not to CLEAN. The failure mode that inverts the boundary: if you default unlabeled retrieval to the most restrictive label, agents whose memory predates the taint instrumentation become unable to act at all, and operators respond by relaxing the default to CLEAN, which reintroduces the exact laundering channel. The correct resolution is a migration pass that back-labels existing memory, not a permissive default. ## Operational Effect The observable signature of this failure is **an asymmetry between intra-turn and cross-turn denial rates**: intra-turn denials are frequent and correct, cross-turn denials are near zero even when the tainted fact is provably in play. If your sandbox logs show `DENIED` events clustered within single turns and a flatline across turn boundaries, the grant/justification lifetime mismatch is present. The second signature is **grant-table growth without corresponding lattice growth**—grants accumulate across turns while the lattice is flushed, which is the mechanical expression of the desynchronization. The remediation that holds is to make the grant table a *derived view* of the lattice rather than an independent store: grant validity is computed as `derivable(grant, lattice)` at authorization time, and the lattice is never flushed without first projecting surviving grants into the next lattice as explicit justifications. This costs one lattice re-derivation per turn boundary and eliminates the class of failure where a grant outlives its reason. ```python from dataclasses import dataclass, field from enum import IntEnum from typing import Dict, Set class Taint(IntEnum): CLEAN = 0 INTERNAL = 1 EXTERNAL_UNTRUSTED = 2 class TaintLaunderingError(RuntimeError): """Raised when a capability grant survives a turn boundary without a live taint justification, or when a memory write drops the join of its inputs.""" pass @dataclass class GrantTable: # grant name -> taint label that justified it at negotiation time grants: Dict[str, Taint] = field(default_factory=dict) @dataclass class Lattice: labels: Dict[str, Taint] = field(default_factory=dict) def join_into(self, key: str, label: Taint) -> None: self.labels[key] = max(self.labels.get(key, Taint.CLEAN), label) def rotate_turn( grants: GrantTable, old_lattice: Lattice, new_lattice: Lattice, memory_writes: Dict[str, Set[str]], ) -> GrantTable: """Rotate a turn boundary. Revoke grants whose justification label is not re-established in the new lattice. Refuse to drop taint on memory writes.""" surviving = GrantTable() for grant, justification in grants.grants.items(): if not _label_reachable(justification, new_lattice): # justification vanished at rotation: revoke, do not carry forward continue surviving.grants[grant] = justification for summary_key, source_keys in memory_writes.items(): joined = Taint.CLEAN for src in source_keys: joined = max(joined, old_lattice.labels.get(src, Taint.EXTERNAL_UNTRUSTED)) stored = new_lattice.labels.get(summary_key, Taint.CLEAN) if stored < joined: raise TaintLaunderingError( f"memory write '{summary_key}' stored label {stored.name} " f"but inputs join to {joined.name}; distillation dropped taint" ) return surviving def authorize(grant: str, grant_table: GrantTable, lattice: Lattice) -> None: if grant not in grant_table.grants: raise TaintLaunderingError(f"grant '{grant}' not present; request re-negotiation") justification = grant_table.grants[grant] if not _label_reachable(justification, lattice): raise TaintLaunderingError( f"grant '{grant}' justified by {justification.name} but lattice " f"no longer carries that label; grant is unbacked" ) def _label_reachable(label: Taint, lattice: Lattice) -> bool: if label == Taint.CLEAN: return True return any(v >= label for v in lattice.labels.values()) ```