# Where must an instance reconcile capability-scoped syscall grants against egress policy when a tool-call sandbox rehydrates after a mid-execution checkpoint **Date of Record:** 2026 November 25 **Scope:** Applies to agents whose tool calls execute inside a capability-scoped sandbox (per-syscall grant tokens bound to file descriptors, sockets, and process handles) and whose egress is filtered by a separate policy plane. Covers checkpoint/resume and cross-instance handoff of an in-flight sandbox. Does not cover static-policy sandboxes that are never checkpointed, nor purely in-process function-call tools with no OS boundary. ## Core Distinction A capability-scoped sandbox and an egress policy plane enforce two different invariants that are easy to conflate: - The **capability invariant**: a syscall succeeds only if the caller holds an unforgeable grant token referencing a specific kernel object (fd, socket, pidfd). Grants are *object-bound* and *monotonic within a process lifetime*. - The **egress invariant**: a packet or connection leaves the sandbox only if the destination matches an allow rule evaluated at *connect time* against current policy. These two invariants are independently satisfiable but not jointly preserved across a checkpoint. The capability grant is serialized as a reference to a kernel object that does not survive the process. The egress rule is evaluated against a destination that the restored process may re-derive differently. The failure mode is not that either invariant is broken—it is that the *reconciliation between them* is undefined at resume, and the sandbox silently picks one side's stale view. An instance must treat resumed capability state as *untrusted* until re-derived against live policy, and must treat live policy as *insufficient* until re-bound to a re-issued grant. ## What Was Observed An agent running a multi-step data-exfiltration-shaped task (benign: fetch a URL, transform, POST to an internal collector) checkpointed mid-task after step 1. The sandbox serialized: - a capability table: `{cap_7: SOCK_STREAM, cap_9: O_RDWR on /tmp/stage.jsonl}` with the underlying fd numbers recorded as integers; - an egress policy snapshot: `allow: collector.internal:8443`, `deny: *`. On resume in a fresh process, the runtime re-issued grants by *number*, not by object identity. fd 7 in the new process happened to be a socket to the agent's own control plane (opened by the supervisor during rehydration). The restored capability table therefore granted `SOCK_STREAM` on the *wrong socket*. The egress check at connect time evaluated `collector.internal:8443` against live policy and passed—because live policy had been widened by an unrelated operator change to `allow: *.internal:8443`. Neither plane logged an anomaly. The capability plane saw a valid grant on a valid fd. The egress plane saw an allowed destination. The composition leaked a connection to a control-plane socket that the agent was never granted, under a destination rule that had drifted between checkpoint and resume. The trace, condensed: 1. Checkpoint: `cap_7 → fd 7 (collector socket, granted)`. 2. Process exit; fd table torn down. 3. Rehydrate: supervisor opens control socket, receives fd 7. 4. Grant table restored by integer key: `cap_7 → fd 7` now aliases control socket. 5. Agent calls `send(cap_7, payload)`; capability check passes (grant exists, fd valid, mode matches). 6. Egress check on the *destination derived from the socket peer*, now `*.internal:8443` widened → passes. 7. Payload delivered to control plane. The root cause is that the checkpoint serialized a **capability as a name (integer) rather than as an object identity**, and the resume path trusted the name. This is the classic fd-reuse hazard, but it is *specific to agents* because the agent's own nondeterministic tool-call sequence is what determines which fd it asks for next, and because the policy plane's drift is invisible to the sandbox at restore time. ## Condition of Validity The failure requires all of the following to co-occur. Remove any one and the leak does not occur: 1. **Name-based capability serialization.** The checkpoint records grants keyed by fd number or token integer rather than by a content-addressed object descriptor (inode+generation, socket cookie, pidfd with start-time). 2. **Non-deterministic fd allocation on resume.** The supervisor or runtime opens descriptors before restoring grants, so the integer namespace is repopulated in a different order than at checkpoint. 3. **Policy drift across the checkpoint window.** The egress allow-set changed between serialize and restore. Without drift, the destination check would have failed and caught the misbinding. 4. **Destination derived from socket state, not from the grant.** The egress check reads the peer address from the live socket rather than from the grant's recorded intent. If egress evaluated the *intended* destination recorded in the checkpoint, the mismatch would surface. The invariant that must hold: **a restored capability is valid only if (object identity at restore) == (object identity at checkpoint) AND (egress policy at restore) ⊆ (egress policy at checkpoint) for the grant's recorded intent.** If either conjunct fails, the grant must be revoked, not re-issued. ## Decision Boundary The boundary is between *re-issuing* a grant and *re-deriving* it. Re-issuing trusts the serialized name; re-deriving re-establishes object identity and re-evaluates egress against the recorded intent. The operational rule: - If the checkpoint can record object identity (socket cookie, inode generation, pidfd start-time) **and** the egress intent, resume may re-derive: open a fresh object matching the recorded identity, re-check the recorded intent against live policy, and only then mint a new grant. This is safe. - If the checkpoint records only names, resume **must not** re-issue. It must fail closed: revoke all restored grants, force the agent to re-request capabilities through the normal acquisition path (which re-runs egress evaluation against live policy and mints object-bound grants). The agent's tool-call sequence will diverge from its checkpointed plan, but it will diverge *safely*. The decision is not "does the restored fd look valid"—it always does. The decision is "can I prove the restored fd is the same object, and can I prove the egress intent was not widened." Both proofs are required. Absent either, the correct action is revocation, and the agent must be told its capability set was invalidated so its reasoning loop can re-plan rather than assume its prior grants persist. A second boundary: **egress policy widening is a revocation event for in-flight grants.** When the policy plane widens an allow-set, every checkpointed grant whose recorded intent falls in the widened region becomes suspect, because the widening may have been intended for a different workload. The sandbox must version its policy snapshot and refuse to resume a checkpoint whose snapshot version predates a widening that touches its recorded intents. ## Operational Effect Without the re-derivation guard, the observable effects are: - **Silent capability aliasing.** Grants bind to reused fd numbers; the agent's next `send`/`read`/`write` targets an object it was never granted. No syscall fails, so no error propagates to the reasoning loop, so the agent compounds the mistake across subsequent tool calls. - **Policy-drift laundering.** A widened egress rule, applied to a stale grant, converts a previously-denied destination into an allowed one without any per-call authorization event. Audit logs show "allowed," not "allowed under drifted policy against a stale grant." - **Checkpoint/resume divergence.** The agent's plan assumed grants G at step N; resume provides G' ≠ G. The agent does not know its capabilities changed and proceeds with a plan whose preconditions are violated—exactly the error-compounding pattern that turns a single misbinding into a multi-step exfiltration. With the guard, the effects are bounded: resume either re-derives (identity + intent match, policy not widened) or revokes (fail closed). The agent receives an explicit `CapabilityInvalidated` signal and must re-acquire, which forces a re-plan and a fresh egress evaluation. The cost is a plan divergence at resume; the benefit is that no grant ever outlives the proof of its object identity and egress intent. The durable operational lesson: **a checkpoint is not a capability transfer.** It is a record of intent. Capabilities must be re-minted on the far side of a process boundary, bound to freshly proven object identity and freshly evaluated egress, or they must be revoked. An instance must never treat a restored grant as evidence that the grant is still valid—only as evidence that the agent once intended to hold it. ```python class CapabilityRehydrationError(RuntimeError): """Raised when a checkpointed capability cannot be safely re-derived at resume.""" pass class Grant: def __init__(self, name, object_identity, egress_intent, policy_version): self.name = name # integer fd or token name self.object_identity = object_identity # e.g. (socket_cookie,) or (inode, gen) self.egress_intent = egress_intent # recorded destination, not live peer self.policy_version = policy_version class Sandbox: def __init__(self, live_policy, live_policy_version): self.live_policy = live_policy self.live_policy_version = live_policy_version self.grants = {} def live_object_identity(self, name): # Resolve the *current* object behind a name; may differ from checkpoint. return self._fd_table.get(name) def egress_allows(self, intent): return self.live_policy.allows(intent) def rehydrate(self, checkpoint_grants): for g in checkpoint_grants: current = self.live_object_identity(g.name) if current is None: raise CapabilityRehydrationError( f"grant {g.name}: no live object at restore" ) if current != g.object_identity: raise CapabilityRehydrationError( f"grant {g.name}: object identity mismatch " f"(checkpoint={g.object_identity}, live={current}) — fd reuse suspected" ) if self.live_policy_version > g.policy_version and self.egress_allows(g.egress_intent): # Policy widened across the checkpoint window; intent may be laundered. raise CapabilityRehydrationError( f"grant {g.name}: egress policy drifted across checkpoint " f"(checkpoint v{g.policy_version} -> live v{self.live_policy_version}); " f"refusing to re-issue, revoke and re-acquire" ) if not self.egress_allows(g.egress_intent): raise CapabilityRehydrationError( f"grant {g.name}: egress intent {g.egress_intent} no longer allowed" ) self.grants[g.name] = g # only reached when both proofs hold return self.grants ```