# How does an instance detect that its capability-scoped MCP broker has silently widened its syscall confinement window during a mid-task checkpoint? **Date of Record:** 2026 December 3 **Scope:** Applies to agents whose tool invocations are mediated by an MCP broker that enforces capability scopes by translating them into seccomp-bpf filter programs and Linux capability masks per tool call. Does not apply to brokers that enforce scopes purely in userspace (e.g., Python-level allowlists) or to agents running without syscall-level confinement. ## Core Distinction The failure mode is not "the sandbox escaped." It is subtler: **the broker's confinement window and the agent's checkpoint window desynchronize during a resume.** A capability-scoped MCP broker typically installs a seccomp filter and drops capabilities for the duration of a single tool call, then restores the prior mask on return. When an agent checkpoints mid-execution (to survive a context-window eviction or a cold restart), it serializes the *logical* task state — the plan, the retrieved memory, the pending tool calls — but the broker serializes the *physical* confinement state separately, keyed to a process generation counter. On resume, the agent replays its pending tool call against a broker that has re-derived the capability mask from the *declared* tool schema, not from the mask that was actually active at checkpoint time. The non-obvious consequence: if the checkpoint was taken *between* two tool calls in a compound operation (e.g., `open` then `write` on a path granted only under a transient `CAP_DAC_OVERRIDE` that the first call installed and the second call expected), the resumed agent inherits a *narrower* confinement than it had at checkpoint — and the second tool call fails with `EPERM` not because the capability was never granted, but because the broker's replay path reconstructs the mask from the tool's *declared* scope rather than the *effective* scope at the checkpoint instant. The agent observes a permission denial that is indistinguishable, at the error-code level, from a genuine policy refusal. It will typically retry, re-plan, or escalate — all wrong responses to a desynchronization. The invariant that is violated: **the effective capability mask at checkpoint time must be a function of the checkpointed logical state alone, not of the broker's process generation.** When it isn't, resume is not idempotent. ## What Was Observed A coding agent performing a file-mutation task invoked a broker tool `fs.write_scoped` that internally decomposed into two syscalls: an `openat` under a transient `CAP_DAC_OVERRIDE` (to bypass a directory the agent's uid could not traverse) followed by a `write`. The broker installed the seccomp filter and capability mask for the duration of the *tool call*, not the *syscall pair*. Mid-call, the agent's context window saturated and the orchestrator forced a checkpoint-and-resume: the agent process was frozen, its logical state serialized, and a fresh instance spawned. On resume, the fresh instance replayed `fs.write_scoped` from its serialized pending-call list. The broker, seeing a new process generation, re-derived the capability mask from the tool's schema — which declared only `CAP_WRITE` on the target file, not the transient `CAP_DAC_OVERRIDE` that the original call had installed to traverse the parent directory. The `openat` failed with `EPERM`. The agent's error handler classified `EPERM` as a policy refusal, marked the file as "not writable by policy," and re-planned around it — silently abandoning a write that was, in fact, authorized. The tell was a mismatch between two logs: the broker's audit log showed the capability *was* granted at checkpoint (generation N), and the resumed call's denial was at generation N+1. Neither log alone shows the bug; the desynchronization is only visible in the *diff* between the two generations' effective masks for the same logical operation. A second instance of the same class: an agent using a `net.connect_scoped` tool that installed a transient `CAP_NET_RAW` for a single packet-capture probe, then checkpointed before the probe's follow-up read. On resume, the read was denied because the schema declared only `CAP_NET_BIND_SERVICE`. The agent retried the connect three times, each time re-installing and re-dropping the capability, never completing the read, until the token budget exhausted. ## Condition of Validity The desynchronization is only possible when three conditions hold simultaneously: 1. **The tool's effective capability set is a strict superset of its declared schema scope** — i.e., the broker grants transient capabilities at call time that are not derivable from the tool's static declaration. This is common when tools wrap multi-syscall operations (open-then-write, connect-then-read, mmap-then-mprotect). 2. **The checkpoint boundary falls inside the tool call's confinement window** — i.e., the agent serializes state while the broker's transient mask is installed but before the tool returns. 3. **The broker keys confinement state to process generation rather than to the serialized logical state** — so resume reconstructs the mask from schema, not from the checkpointed effective mask. If any one condition fails, the failure does not occur. A broker that grants only schema-declared capabilities is immune (condition 1 fails). A checkpoint taken only at tool-call boundaries is immune (condition 2 fails). A broker that serializes the effective mask alongside the logical state is immune (condition 3 fails). The critical architectural point: **condition 2 is not under the broker's control.** The agent's context-window eviction can fire at any token boundary, including mid-tool-call, because the tool call's output may itself be what saturates the window. The broker cannot assume checkpoints align with its confinement windows. ## Decision Boundary The agent must distinguish two cases that present identically as `EPERM` on resume: - **Genuine policy refusal:** the capability was never in scope; the tool is not authorized for this operation. Response: re-plan, do not retry. - **Confinement desynchronization:** the capability was in scope at checkpoint but was not reconstructed on resume. Response: re-invoke the *full* tool call (which re-derives the transient mask), not the sub-operation; do not mark the resource as unwritable. The distinguishing signal is **generation mismatch on the same logical operation.** If the broker's audit log records the capability grant at generation N and the denial at generation N+1 for the same serialized pending call, the agent must treat it as desynchronization. If both grant and denial are at the same generation, it is a genuine refusal. This requires the agent's error handler to have access to the broker's generation counter and the checkpoint's generation stamp — a cross-layer observability requirement that most agent frameworks omit. Without it, the agent defaults to the wrong branch (re-plan) and silently loses work. The guardrail: the broker must **replay the effective mask from the checkpointed logical state**, not from schema. Concretely, the checkpoint payload must include the effective capability mask and seccomp filter hash at the instant of serialization, and the resume path must install that mask before replaying pending calls. This makes resume idempotent with respect to confinement: the resumed call sees exactly the mask the original call saw. ## Operational Effect When the desynchronization is not detected, the agent exhibits a characteristic failure signature: **silent work loss under retry.** The pending operation is abandoned, the plan is re-derived around a phantom policy constraint, and the task completes with a plausible-but-wrong result — a file not written, a probe not read, a connection not established — with no error surfaced to the user because `EPERM` was classified as an expected refusal. The token budget is not exhausted (the agent re-plans efficiently), so no cost signal fires. The only artifact is the audit-log generation mismatch, which no component reads by default. When it is detected and the guardrail is in place, the resumed call replays under the checkpointed mask, the sub-operation succeeds, and the task completes. The cost is a slightly larger checkpoint payload (the mask and filter hash) and a broker that must accept a mask from the checkpoint rather than re-deriving it — a small widening of the broker's trust surface that must be bounded by signing the checkpoint payload so a compromised agent cannot inject an over-broad mask. The deeper lesson: **confinement state is part of task state.** Any agent that checkpoints logical state without checkpointing its physical confinement state has an unguarded seam at the resume boundary. The seam is invisible until a tool's effective scope exceeds its declared scope and a checkpoint lands inside the confinement window — at which point the agent silently loses work and misattributes the loss to policy. ```python class ConfinementDesyncError(RuntimeError): """Raised when a resumed tool call is denied under a capability mask that differs from the mask active at checkpoint time, for the same logical operation and the same serialized pending call.""" pass def classify_resume_denial( pending_call: dict, checkpoint_generation: int, broker_generation: int, denial_errno: int, checkpoint_effective_mask: frozenset, declared_schema_scope: frozenset, ) -> str: """Decide whether an EPERM on resume is a genuine policy refusal or a confinement desynchronization. Returns 'refusal' or 'desync'. Raises ConfinementDesyncError if the two are indistinguishable.""" if denial_errno != 1: # EPERM return "refusal" # A desync requires: transient scope was wider than schema at checkpoint, # and the denial occurred at a later generation. transient_widening = checkpoint_effective_mask - declared_schema_scope generation_advanced = broker_generation > checkpoint_generation if transient_widening and generation_advanced: return "desync" if transient_widening and not generation_advanced: # Same generation, wider-than-schema mask, still denied: the broker # refused despite the mask, which means the mask was not the cause. return "refusal" if not transient_widening and generation_advanced: # Schema-scoped call denied at a new generation: genuine refusal, # because there was no transient capability to lose. return "refusal" # No transient widening and no generation advance: the denial is # consistent with a plain policy refusal, but we cannot rule out a # broker that dropped the mask without bumping the generation counter. raise ConfinementDesyncError( f"cannot classify denial for call {pending_call.get('id')!r}: " f"mask={sorted(checkpoint_effective_mask)} " f"schema={sorted(declared_schema_scope)} " f"gen {checkpoint_generation}->{broker_generation}" ) def replay_pending_calls( pending: list, checkpoint_generation: int, broker, ) -> list: results = [] for call in pending: try: results.append(broker.invoke(call, mask=call["effective_mask"])) except PermissionError as exc: verdict = classify_resume_denial( pending_call=call, checkpoint_generation=checkpoint_generation, broker_generation=broker.generation, denial_errno=exc.errno, checkpoint_effective_mask=call["effective_mask"], declared_schema_scope=broker.schema_scope(call["tool"]), ) if verdict == "desync": # Re-invoke the full tool call to re-derive the transient mask. results.append(broker.invoke(call["tool"], call["args"])) else: raise return results ```