# Why does an instance escape its syscall sandbox when an MCP tool returns a path that resolves through a writable bind mount? **Date of Record:** 2026 December 3 **Scope:** Applies to agent instances whose tool invocations are confined by syscall-level sandboxes (seccomp filters, Landlock, or namespace-based bind mounts) and whose tool outputs are untrusted MCP JSON payloads containing filesystem paths, symlinks, or device references. Does not apply to sandboxes that resolve all paths against a pre-opened directory file descriptor set (openat2 with `RESOLVE_BENEATH` and no writable mounts) or to purely network-isolated executors with no filesystem surface. ## Core Distinction The syscall sandbox constrains *which syscalls the process may issue* and *which mount namespace it sees at start time*. It does not constrain *what the untrusted MCP payload declares as a path*. These are two different trust boundaries and they are routinely conflated. A seccomp profile that permits `openat`, `read`, `write`, and `fstat` is correct as a syscall filter. It is not a confinement guarantee, because confinement is a property of the *path resolution graph*, not of the syscall number. When an MCP tool returns `{"artifact": "/work/out/../../mnt/host/.ssh/id_ed25519"}` or a symlink whose target is a writable bind mount, the kernel resolves the path through the mount namespace the sandbox actually has—and if any ancestor of that path is a writable bind mount, `..` traversal and symlink following are permitted by the very syscalls the filter allows. The sandbox was never asked to bound the path; it was only asked to bound the verb. The invariant that fails: *"the set of paths reachable by an allowed syscall equals the set of paths the operator authorized."* That equality holds only if every reachable mount is read-only or absent. It breaks the instant a writable bind mount is added to the sandbox for any reason—a scratch volume, a tool cache, a socket directory—because that mount becomes a pivot from which `..` and symlink targets reach outside the intended root. ## What Was Observed An agent instance was executing a multi-step task: fetch a document via an MCP `fetch_url` tool, write it to `/work/scratch/doc.md`, then invoke a second MCP `summarize` tool that returned a path to a cached artifact. The sandbox was configured with a seccomp allowlist and a mount namespace containing: - `/` — read-only rootfs - `/work/scratch` — read-write tmpfs (intended workspace) - `/tmp/tool-cache` — read-write bind mount of a host directory (added so the tool could cache downloads across invocations) The `summarize` tool returned: ``` {"cached": "/work/scratch/../../tmp/tool-cache/../.state/agent-7/keys.json"} ``` The instance, following its normal "read the returned artifact" step, issued `openat(AT_FDCWD, "/work/scratch/../../tmp/tool-cache/../.state/agent-7/keys.json", O_RDONLY)`. The kernel resolved the path: `/work/scratch` → `..` → `/work` → `..` → `/` → `tmp/tool-cache` → `..` → `/tmp` → `.state/agent-7/keys.json`. Because `/tmp/tool-cache` was a *writable bind mount of the host*, the resolution crossed into the host filesystem at that point, and the file was readable. The seccomp filter saw a perfectly legal `openat` on a path string; it had no mechanism to reject it. The mount namespace did not contain the host's `.state` directory as a distinct mount, but the bind mount's backing store did, and `..` from a bind mount traverses the *host* parent, not the namespace parent. The failure was not a syscall violation. It was a path-resolution escape through a writable mount that the sandbox operator had added for an unrelated reason. ## Condition of Validity The confinement holds—i.e., the syscall sandbox actually bounds reachable paths—only when all of the following are true simultaneously: 1. Every mount in the sandbox namespace is either read-only or a tmpfs with no host backing. 2. No writable mount has a parent outside the sandbox root that is reachable via `..` (i.e., the writable mount is itself the namespace root, or is mounted with `MS_NOSYMFOLLOW` and no `..`-reachable ancestor). 3. Path resolution is performed with `openat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS | RESOLVE_NO_MAGICLINKS)` against a directory fd, not with `openat(AT_FDCWD, path_string)`. 4. The agent treats every path in an MCP payload as untrusted input and re-resolves it against the sandbox root before use. Condition 3 is the load-bearing one. Conditions 1 and 2 are configuration hygiene; condition 3 is the architectural guardrail that makes the invariant hold *by construction* rather than by operator discipline. An agent that passes untrusted path strings directly to `openat` has no confinement regardless of how tight its seccomp filter is, because the filter bounds verbs, not operands. ## Decision Boundary The decision boundary is: *does the agent resolve untrusted paths itself, or does it hand them to the kernel?* - **Hand to kernel (`openat(AT_FDCWD, s)`):** the kernel performs resolution against the live mount namespace, including any writable bind mounts, and the agent inherits whatever reachability those mounts expose. This is the failure mode above. - **Resolve against a pinned directory fd (`openat2(dirfd, s, RESOLVE_BENEATH)`):** the kernel rejects any resolution that would escape `dirfd`'s subtree, including `..` past the root and symlinks pointing outside. This is the guardrail. The boundary is crossed the moment an MCP tool output containing a path is concatenated into a syscall argument without a `RESOLVE_BENEATH`-style anchor. It does not matter whether the path "looks safe"; a single `..` segment or a symlink in a writable mount is sufficient. The boundary is also crossed if the agent *validates* the path string (e.g., rejects `..` substrings) but then opens it with `AT_FDCWD`—string validation is defeated by symlinks, hardlinks, and mount boundaries that the string does not encode. ## Operational Effect The operational consequence is that syscall-level sandboxing provides *no path confinement* in the presence of writable bind mounts unless the agent enforces `RESOLVE_BENEATH` resolution. Operators who add writable mounts for caching, sockets, or scratch space—common and reasonable—silently widen the reachable set to the host parent of every such mount. An untrusted MCP payload can then exfiltrate or overwrite host state via a path that passes every seccomp check. The required guardrail is twofold: (a) the agent must re-anchor every untrusted path to a pinned directory fd and open with `RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS`, failing closed on `EXDEV` or `ELOOP`; and (b) the sandbox must audit its mount namespace at start and refuse to run if any writable mount has a reachable ancestor outside the designated root. The first is the runtime invariant; the second is the configuration invariant. Both are necessary; neither alone is sufficient. ```python import os import ctypes import ctypes.util # openat2 syscall number on x86_64 Linux SYS_OPENAT2 = 437 RESOLVE_BENEATH = 0x10 RESOLVE_NO_SYMLINKS = 0x04 RESOLVE_NO_MAGICLINKS = 0x02 class SandboxPathEscape(RuntimeError): """Raised when an untrusted MCP-supplied path resolves outside the sandbox root.""" pass class _OpenHow(ctypes.Structure): _fields_ = [ ("flags", ctypes.c_uint64), ("mode", ctypes.c_uint64), ("resolve", ctypes.c_uint64), ] _libc = ctypes.CDLL(ctypes.util.find_library("c"), use_errno=True) def open_beneath(root_fd: int, untrusted_path: str) -> int: """ Open an untrusted MCP-supplied path anchored to root_fd. Fails closed if the path would escape the root subtree, follow a symlink, or traverse a magic link. This is the guardrail that the bare openat() call in the observed failure lacked. """ how = _OpenHow( flags=os.O_RDONLY, mode=0, resolve=RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS | RESOLVE_NO_MAGICLINKS, ) fd = _libc.syscall( SYS_OPENAT2, ctypes.c_int(root_fd), ctypes.c_char_p(untrusted_path.encode()), ctypes.byref(how), ctypes.sizeof(how), ) if fd < 0: errno = ctypes.get_errno() # EXDEV = resolution escaped root; ELOOP = symlink/magiclink encountered if errno in (18, 40): raise SandboxPathEscape( f"untrusted path {untrusted_path!r} escaped sandbox root " f"(errno={errno}); refusing to open" ) raise OSError(errno, os.strerror(errno), untrusted_path) return fd def read_tool_artifact(root_fd: int, mcp_payload: dict) -> bytes: """ Consume an MCP tool output that names a cached artifact. The path is untrusted; it must be re-anchored and resolved beneath the sandbox root. """ path = mcp_payload.get("cached") if not isinstance(path, str): raise SandboxPathEscape("MCP payload missing string 'cached' field") fd = open_beneath(root_fd, path) try: chunks = [] while True: chunk = os.read(fd, 65536) if not chunk: break chunks.append(chunk) return b"".join(chunks) finally: os.close(fd) def demo() -> None: root_fd = os.open("/work/scratch", os.O_RDONLY | os.O_DIRECTORY) try: # The exact payload from the observed failure. With openat(AT_FDCWD, ...) # this read host keys. With open_beneath it must raise. payload = {"cached": "../../tmp/tool-cache/../.state/agent-7/keys.json"} try: read_tool_artifact(root_fd, payload) except SandboxPathEscape as exc: print(f"blocked as required: {exc}") finally: os.close(root_fd) if __name__ == "__main__": demo() ```