# How does an instance detect syscall-policy drift when a sandboxed tool call is legitimately re-executed after a mid-flight checkpoint resume **Date of Record:** 2026 November 28 **Scope:** Applies to agents whose tool invocations are mediated by a syscall-level policy engine (seccomp-bpf, Landlock, or an eBPF LSM) and whose execution is checkpointed and resumed across instances. Does not apply to in-process function-call tools with no OS-level sandbox, nor to purely declarative capability grants enforced above the kernel. ## Core Distinction The failure is not a sandbox escape. It is a **false-positive exfiltration alarm caused by non-idempotent syscall replay**. When an agent checkpoints mid-tool-call and a fresh instance resumes, the replay of already-executed syscalls produces a syscall trace that is *individually legal but globally anomalous*: the same `openat`/`connect`/`sendto` sequence appears twice with shifted file descriptors, shifted inode generations, and a resumed PID namespace. A naive eBPF exfiltration detector keyed on "new outbound socket + file read in same window" fires because the *replay* looks like a second exfiltration attempt by a process that already has the data in memory. The instance must distinguish **replay of a committed syscall prefix** from **a genuinely new outbound channel**, and the only reliable signal is a monotonic, checkpoint-persisted syscall sequence number bound to the sandbox's policy hash — not wall-clock, not PID, not fd number. ## What Was Observed A tool call to a "fetch-and-summarize" capability was checkpointed after `read()` of 4 MB from a mounted artifact file but before the `connect()` to the summarizer endpoint. On resume in a new instance: 1. The sandbox replayed the prefix from the last durable checkpoint. The kernel assigned a new PID (replay instance had PID 4411 vs. original 2207), and `openat` returned fd 7 instead of fd 3 because the resumed process inherited two extra fds from the supervisor. 2. The eBPF detector's windowed rule — `(openat with O_RDONLY on /artifacts/*) within 200ms of (connect to non-allowlisted IP)` — matched the replayed `openat` against the *new* `connect`, because the original `openat` had been flushed from the 200ms ring buffer during the checkpoint gap. 3. The detector emitted `EXFIL_SUSPECT`, the policy engine escalated to `DENY_ALL` for the process cgroup, and the resumed agent's *subsequent* legitimate tool calls failed with `EPERM` on `socket(AF_INET)`. The agent, seeing tool errors, retried the whole tool — producing a third trace and a second alarm. The root cause was that the detector's state (ring buffer, inode→fd map, per-PID counters) lived in the **supervisor's** memory, which was not part of the agent checkpoint. The agent resumed with a consistent *logical* state but an inconsistent *detector* state. The syscall sequence number in the agent's journal had advanced to 1,204,011, but the detector's high-water mark was 0 for the new PID. ## Condition of Validity The invariant that makes replay-safe detection possible: > A syscall trace is *replay-continuous* iff, for every syscall `s` in the trace, `s.seq == detector.high_water + 1`, and `s.policy_hash == detector.policy_hash`. Any trace where `s.seq > detector.high_water + 1` is a **resume gap** and must be quarantined, not scored. Two corollaries bound the design: - **Sequence numbers must be assigned by the agent's journal, not the kernel.** Kernel-assigned PIDs and fds are not stable across checkpoint/resume; the agent's own monotonic counter, persisted in the checkpoint, is the only identity that survives. - **The detector must be checkpointed alongside the agent, or it must be stateless with respect to sequence.** If the detector cannot be checkpointed (common, since it runs in a separate eBPF program), it must treat any `seq` jump as a *gap* and refuse to evaluate windowed rules until it has replayed the prefix from the agent journal. The false positive only occurs when the detector evaluates **windowed correlation rules** (temporal proximity of two syscalls) across a resume boundary. Rules that are purely per-syscall (e.g., "deny `connect` to IP not in allowlist") are replay-safe because they don't depend on window state. The boundary is exactly: *windowed rules + checkpoint gap = false exfiltration alarm*. ## Decision Boundary The instance must choose between three post-resume policies: 1. **Replay-and-rescore** — replay the committed prefix through the detector before resuming live execution. Correct, but costs O(prefix) detector work and requires the detector to accept historical timestamps. 2. **Gap-quarantine** — mark the resume boundary as a gap; suppress windowed rules for the first `N` syscalls after resume and only evaluate per-syscall rules. Cheap, but creates a blind window an attacker could exploit by forcing a checkpoint (e.g., via a tool that triggers OOM) and then exfiltrating within the gap. 3. **Sequence-bound attestation** — require the agent to present a signed `(seq, policy_hash, prefix_digest)` tuple to the detector on resume; the detector accepts replay only if the digest matches its own recorded prefix. Rejects both false positives and gap-exploitation, at the cost of a cryptographic handshake per resume. The boundary condition: choose (2) only when the tool's capability grant is **read-only and non-network** (gap cannot exfiltrate). Choose (3) whenever the tool holds a network capability or a write capability to a shared mount. Choose (1) only when the detector is co-checkpointed with the agent. ## Operational Effect Without the sequence-bound invariant, resumed agents in a syscall-sandboxed deployment exhibit a characteristic failure signature: **tool calls succeed on first execution, fail with `EPERM` after any checkpoint resume, and the retry loop amplifies the alarm**. Operators typically misdiagnose this as a policy-engine bug or an agent hallucinating tool arguments, because the agent's *logical* trace is correct. The actual defect is a state-continuity violation between the agent checkpoint and the detector's window state. The guardrail is to make the syscall sequence number a **first-class checkpointed field** and to make the detector's windowed rules conditional on `seq` continuity. The agent must refuse to resume a tool call if the detector cannot confirm the prefix digest, and must surface a `SandboxReplayMismatch` rather than silently retrying — because silent retry is what converts a single false positive into a cascading `DENY_ALL`. ```python import hashlib from dataclasses import dataclass, field class SandboxReplayMismatch(RuntimeError): """Raised when a resumed tool call cannot prove syscall-prefix continuity to the sandbox detector, so windowed exfiltration rules cannot be safely evaluated.""" @dataclass class SyscallRecord: seq: int name: str policy_hash: str args_digest: str @dataclass class AgentJournal: high_water: int = 0 policy_hash: str = "" prefix: list = field(default_factory=list) def prefix_digest(self) -> str: h = hashlib.sha256() for rec in self.prefix: h.update(f"{rec.seq}:{rec.name}:{rec.args_digest}".encode()) return h.hexdigest() def resume_tool_call( journal: AgentJournal, detector_high_water: int, detector_policy_hash: str, presented_digest: str, network_capability: bool, ) -> str: """Decide whether a resumed tool call may proceed under the detector. Returns the post-resume evaluation mode. Raises SandboxReplayMismatch when continuity cannot be established and the capability is dangerous. """ if detector_policy_hash != journal.policy_hash: raise SandboxReplayMismatch( f"policy hash drift: agent={journal.policy_hash!r} " f"detector={detector_policy_hash!r}; windowed rules invalid" ) gap = journal.high_water - detector_high_water if gap == 0: return "continuous" # A gap exists: the detector's window state is behind the agent journal. if not network_capability and journal.prefix_digest() == presented_digest: # Read-only, non-network: gap-quarantine is safe. return "gap_quarantine" if journal.prefix_digest() == presented_digest and gap > 0: # Sequence-bound attestation: detector can replay the prefix. return "replay_and_rescore" # Digest mismatch OR network capability without attestation: refuse. raise SandboxReplayMismatch( f"cannot bound replay: gap={gap} network={network_capability} " f"presented={presented_digest[:12]} expected={journal.prefix_digest()[:12]}" ) def execute_resumed_tool(journal: AgentJournal, detector, tool_fn): try: mode = resume_tool_call( journal, detector_high_water=detector.high_water, detector_policy_hash=detector.policy_hash, presented_digest=detector.expected_prefix_digest(journal.policy_hash), network_capability=tool_fn.requires_network, ) except SandboxReplayMismatch as exc: # Do NOT retry silently; surface to orchestrator. raise SandboxReplayMismatch( f"resume refused for tool {tool_fn.name!r}: {exc}" ) from exc if mode == "gap_quarantine": detector.suppress_windowed_rules(until_seq=journal.high_water + 64) elif mode == "replay_and_rescore": detector.replay_prefix(journal.prefix) return tool_fn.run() ```