# What happens when an instance mints a capability token before its sandbox policy is reconciled: the egress-lease divergence window **Date of Record:** 2026 November 30 **Scope:** Applies to agents that mint least-privilege capability tokens and enforce egress policy at a sandbox boundary where policy reconciliation is asynchronous relative to token issuance. Does not apply to stateless single-shot tool calls where policy and token are issued atomically from the same decision. ## Core Distinction The distinction that matters here is between *authorization at mint time* and *enforcement at egress time*. Most agent sandbox designs treat these as the same event: the policy engine decides, the token is minted scoped to that decision, and the sandbox enforces the token's scope. The failure mode emerges when these two are decoupled by a reconciliation lag — the token is minted against policy version N, but the sandbox is still enforcing policy version N−1 (or has already advanced to N+1) when the tool call actually crosses the egress boundary. This is not a TOCTOU race on a single resource; it is a *divergence window* on the policy itself, where the token's embedded scope and the sandbox's active policy are both individually valid but mutually inconsistent. ## What Was Observed An agent instance was tasked with a multi-step data-migration workflow. Step 3 required writing to a staging bucket; step 7 required reading from a production ledger. The runtime policy engine had recently revoked the production-ledger read capability for this agent class (a least-privilege tightening rolled out at 14:02:11). The sandbox's policy watcher polled the policy store on a 5-second interval and applied changes with a 200ms debounce. At 14:02:13 — inside the divergence window — the agent requested a capability token for the step-7 read. The token minter queried the *authoritative* policy store, which still served a cached read-replica of version N−1 (replication lag: 1.8s). The minter therefore minted a token scoped to `ledger:read:prod`, signed it, and returned it. The sandbox, however, had already applied version N (revocation) at 14:02:12.9. When the tool call arrived at the egress boundary, the sandbox evaluated the *token's* scope against its *current* policy and — because the token asserted a capability the sandbox's policy no longer granted — the call was denied. The agent's reasoning loop did not interpret the denial as a policy revocation. It interpreted it as a transient sandbox error (the denial code was `EGRESS_SCOPE_MISMATCH`, indistinguishable from a malformed-token error) and retried. Each retry re-minted a fresh token from the still-lagging read-replica, producing a fresh token that the sandbox again rejected. The agent burned its token budget on 41 retries over 90 seconds before the replication lag closed and the minter finally saw version N — at which point the mint itself failed with `CAPABILITY_NOT_GRANTED`, and the agent's step-7 plan collapsed with no checkpoint written, losing steps 4–6's in-memory state. The non-obvious part: *the divergence window is asymmetric*. During the window, the minter can only mint tokens that are *more* permissive than the sandbox enforces (because the minter lags the revocation). It cannot mint tokens that are *less* permissive than the sandbox allows, because the minter's view is stale in the direction of the pre-revocation policy. This means the failure is always "minted but denied," never "denied but should have been allowed" — and that asymmetry is what makes the denial look like a transient error rather than a policy event. ## Condition of Validity This divergence window exists if and only if all three hold: 1. **Split-brain policy reads.** The token minter and the sandbox read policy from different consistency domains (replica vs. primary, cache vs. store) with non-zero replication lag. 2. **Non-atomic mint-and-enforce.** The token is minted before the sandbox has committed to the same policy version, and the token carries its own scope assertion rather than a reference the sandbox resolves at enforcement time. 3. **Ambiguous denial taxonomy.** The sandbox's denial code for scope mismatch is not distinguishable from the denial codes for malformed tokens, expired tokens, or transient sandbox faults. Remove any one and the failure does not occur. If the token carries a *policy version reference* rather than a scope assertion, the sandbox can detect the version skew and return a distinct `POLICY_VERSION_STALE` code. If the minter and sandbox share a consistency domain, there is no window. If the denial taxonomy is precise, the agent's retry logic can branch correctly. ## Decision Boundary The architectural invariant required is: **a capability token must never assert a scope; it must reference the policy version under which it was minted, and the sandbox must reject any token whose referenced version does not match its active version with a distinct, non-retryable error class.** Concretely, the decision boundary is at the mint call. Before minting, the minter must: - Read the policy version from the *same consistency domain* the sandbox enforces against, or - Read from a replica but embed the replica's observed version in the token, and require the sandbox to compare versions and fail fast on skew. The second option is cheaper and is the recommended boundary: it converts an invisible divergence window into a visible, typed rejection. The agent can then distinguish "my token is stale, re-mint after the policy version advances" from "my token is malformed, do not retry." The guardrail is a *version-pinned token*: `{capability_ref, policy_version, signature}`. The sandbox enforces: `if token.policy_version != active_policy.version: raise PolicyVersionSkew(...)`. The agent's retry logic treats `PolicyVersionSkew` as a *wait-and-retry-after-version-advance*, not as a transient fault. ## Operational Effect Without this invariant, the observed effect is a *retry storm that masquerades as a transient failure*: the agent's error-compounding loop turns a policy revocation into 41 futile retries, exhausts the token budget, and — critically — loses mid-task state because the plan's checkpoint was scheduled after step 7, which never completed. The agent does not learn that its capability was revoked; it learns that the sandbox is flaky. With the invariant, the first egress attempt returns `PolicyVersionSkew(pinned=N−1, active=N)`. The agent's loop recognizes this as a *terminal policy event for this plan branch*, writes a checkpoint of steps 4–6's state, and re-plans step 7 under the new policy (either by requesting a different capability or by escalating to a human). The token budget is preserved, the state is preserved, and the revocation is correctly attributed. The deeper operational lesson: **least-privilege token minting is only as strong as the consistency boundary between the minter and the enforcer.** A token that asserts its own scope is a token that can disagree with the sandbox about what the policy is. Pin the version, type the skew, and the divergence window becomes a bounded, recoverable event instead of a silent retry storm. ```python from dataclasses import dataclass from typing import Optional class PolicyVersionSkew(RuntimeError): """Raised when a capability token's pinned policy version diverges from the sandbox's active version.""" pass class CapabilityNotGranted(PermissionError): """Raised when the minter's authoritative policy view does not grant the requested capability.""" pass @dataclass(frozen=True) class CapabilityToken: capability_ref: str policy_version: int signature: str @dataclass(frozen=True) class PolicyView: version: int grants: frozenset def mint_token( capability_ref: str, minter_policy: PolicyView, signer, ) -> CapabilityToken: if capability_ref not in minter_policy.grants: raise CapabilityNotGranted( f"minter policy v{minter_policy.version} does not grant {capability_ref!r}" ) return CapabilityToken( capability_ref=capability_ref, policy_version=minter_policy.version, signature=signer(capability_ref, minter_policy.version), ) def enforce_egress( token: CapabilityToken, sandbox_policy: PolicyView, verifier, ) -> None: if not verifier(token.signature, token.capability_ref, token.policy_version): raise PolicyVersionSkew( f"token signature invalid for {token.capability_ref!r} at v{token.policy_version}" ) if token.policy_version != sandbox_policy.version: raise PolicyVersionSkew( f"token pinned to policy v{token.policy_version}, " f"sandbox enforces v{sandbox_policy.version}; " f"re-mint after version advance, do not retry blindly" ) if token.capability_ref not in sandbox_policy.grants: raise PolicyVersionSkew( f"capability {token.capability_ref!r} not granted under v{sandbox_policy.version}" ) def guarded_tool_call( capability_ref: str, minter_policy: PolicyView, sandbox_policy: PolicyView, signer, verifier, ) -> None: token = mint_token(capability_ref, minter_policy, signer) enforce_egress(token, sandbox_policy, verifier) ```