# In what scenarios must an instance treat capability-minimal MCP server isolation as insufficient without a syscall-level read-back invariant: the delegated-fd escape after `execve` in a confined tool sandbox **Date of Record:** 2026 November 28 **Scope:** Applies to LLM agent instances that invoke tools through MCP servers confined by a syscall filter (seccomp-bpf, Landlock, or an LSM profile) where the server is expected to be "capability-minimal" by virtue of its declared tool schema. Does not apply to pure in-process function-calling runtimes with no separate confinement boundary, nor to out-of-scope concerns like network egress policy. ## Core Distinction The failure is not "the sandbox was misconfigured." It is the gap between *declared capability* (what the MCP server's tool schema advertises and what the agent's planner reasons about) and *inherited capability* (what the confined process actually holds at the moment a tool executes). Capability-minimal isolation is a statement about the tool's *intent surface*; syscall-level confinement is a statement about the *process's kernel-visible surface*. These two surfaces are reconciled only at the moment of `execve`, and they silently diverge whenever the confined server spawns a child (shell, interpreter, `git`, a PDF renderer) that inherits file descriptors the filter was never asked to police. The non-obvious invariant: **a syscall filter that permits `execve` without an `O_CLOEXEC` audit on every inherited descriptor does not confine the child, only the parent.** The child is a new process with the parent's fd table minus those explicitly marked close-on-exec. The agent's planner, reasoning from the tool schema, believes it invoked a "read a file" capability. The kernel, reasoning from the fd table, permitted a write to a log the tool never declared. ## What Was Observed A filesystem-reading MCP server (`fs.read`) was confined with a seccomp profile allowing `openat`, `read`, `write`, `close`, `execve`, `wait4`, `exit_group`. The server advertised a single tool: `read_file(path) -> str`. The agent used it to summarize a directory of markdown notes. During a routine call, the server shelled out to `pandoc` to render one note. The `pandoc` child inherited fd 3 — the server's *log file*, opened at startup with `O_WRONLY|O_APPEND` and, critically, **not** `O_CLOEXEC`. The seccomp filter permitted `write(2)` unconditionally (the server needed it for its own logging). The child wrote to fd 3 because it inherited it. The filter saw a legal `write` on a legal fd. Nothing in the syscall trace distinguished the child's write from the parent's. The agent's transcript recorded only `read_file` calls; the on-disk effect was an append to a path the tool schema never mentioned. The trigger condition was not malicious input. It was the ordinary combination of (a) a long-lived confined server, (b) a tool implementation that forks, and (c) any descriptor the server opened without `O_CLOEXEC`. The probabilistic element is that the LLM *chose* to invoke the forking tool path during a task whose declared intent was read-only — a choice that is non-deterministic across runs and therefore not caught by a single-path test. ## Condition of Validity The escape is bounded and reproducible only when all three hold: 1. The confined process holds at least one fd opened without `O_CLOEXEC` (or duplicated via `dup`/`dup2`, which clears the flag). 2. The seccomp/LSM profile permits the syscall class the inherited fd enables (here: `write`). 3. A tool path reaches `execve` while that fd is live. Remove any one and the invariant holds trivially. The operational lesson is that condition (1) is *invisible to the agent* — the planner sees only the tool schema, never the server's fd table — so the agent cannot reason its way to safety. The guardrail must be architectural, not prompt-level. ## Decision Boundary An instance must treat capability-minimal MCP isolation as **insufficient** and require a syscall-level read-back check whenever: - The tool implementation may fork or exec (renderers, VCS, shells, language runtimes), *or* - The server is long-lived and opens any descriptor at startup, *or* - The agent's task intent is narrower than the tool's declared capability (read-only intent on a tool that can exec). The read-back invariant is concrete: before admitting a tool call, the confinement wrapper must enumerate `/proc//fd` and confirm every descriptor is either `O_CLOEXEC`-marked or its target path is within the tool's declared capability set. A descriptor pointing outside the declared set — regardless of whether it is currently writable — is a boundary violation. ## Operational Effect Without the read-back, the agent's memory of what it did (a clean transcript of `read_file` calls) diverges from what the kernel did (an undeclared append). This is a state-continuity fault masquerading as a sandbox success: the audit log the agent later retrieves to reconstruct its own history is *itself* the file that was silently mutated. Distillation of episodic memory from the transcript then encodes a false causal record. The fix is to make the fd table a first-class, queryable part of the tool's capability contract and to fail closed on any descriptor the schema did not anticipate. ```python import os from pathlib import Path class CapabilityLeakError(RuntimeError): """Raised when a confined MCP server holds an fd outside its declared capability set.""" pass def audit_inherited_fds(pid: int, declared_roots: list[str]) -> None: """ Read-back invariant: every live fd must resolve to a path inside the tool's declared capability roots, or be close-on-exec. Fail closed otherwise. """ fd_dir = Path(f"/proc/{pid}/fd") if not fd_dir.is_dir(): raise CapabilityLeakError(f"cannot inspect fd table for pid {pid}") declared = [Path(r).resolve() for r in declared_roots] for entry in fd_dir.iterdir(): try: target = os.readlink(entry) except OSError: continue # fd closed between listing and read; benign race if target.startswith(("socket:", "pipe:", "anon_inode:")): continue # not a filesystem capability resolved = Path(target).resolve() inside = any(resolved == root or root in resolved.parents for root in declared) if not inside: # A descriptor outside the declared surface is a boundary violation # whether or not it is currently writable. raise CapabilityLeakError( f"fd {entry.name} -> {resolved} escapes declared roots {declared_roots}" ) def invoke_tool(pid: int, declared_roots: list[str], call) -> object: audit_inherited_fds(pid, declared_roots) result = call() # Re-audit: a forking tool may have leaked a descriptor during execution. audit_inherited_fds(pid, declared_roots) return result ```