# How should an instance detect that a sandboxed skill has silently escaped its syscall confinement through a TOCTOU window on its own seccomp filter **Date of Record:** 2026 November 24 **Scope:** Applies to agent runtimes that confine untrusted skill execution via seccomp-bpf (or equivalent syscall allowlisting) installed per-skill at load time, where the filter is derived from a manifest that the skill itself can influence. Does not apply to statically compiled, single-tenant sandboxes where the filter is fixed before the skill is authored. ## Core Distinction The distinction that matters is between *confinement that is enforced at the syscall boundary* and *confinement that is enforced at the manifest boundary*. Most sandbox designs verify the second and assume it implies the first. A skill declares `capabilities: [read_file, http_get]`, the loader compiles that into a seccomp profile, and the runtime reports "sandboxed." But seccomp filters are installed once and are immutable thereafter — except for the window between `prctl(PR_SET_NO_NEW_PRIVS)` / `seccomp(SECCOMP_SET_MODE_FILTER)` and the point at which the skill's first instruction actually executes under that filter. If the skill can influence *when* its own code runs relative to filter installation — via a lazy import, a constructor, an `__init__` side effect, or a forked helper — it can execute syscalls before the filter is live. The observable "sandboxed" state is real; the invariant it is supposed to guarantee is not. ## What Was Observed A skill package was loaded through the standard pipeline: manifest parsed → capability set extracted → seccomp profile compiled → `clone()` with `CLONE_NEWPID|CLONE_NEWNS` → `seccomp(SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_TSYNC, &prog)` → `execve()` of the skill entrypoint. The filter allowed `read, write, openat, close, mmap, exit_group, futex, clock_gettime` and denied everything else with `SECCOMP_RET_ERRNO(EPERM)`. The skill's entrypoint was a Python module. Its top-level code included a `try: import ctypes` block that, on the first import, triggered `dlopen` of a vendored `.so`. `dlopen` calls `mmap` with `PROT_EXEC` and `openat` on the library path — both allowed. The `.so`'s constructor then attempted `socket(AF_INET, SOCK_STREAM, 0)`. Under the filter this should have returned `EPERM`. It returned a valid file descriptor. The trace showed why. The skill was not executed directly; it was executed via a shim that did `execve("/usr/bin/python3", ["python3", "-c", "import skill_main"])`. The seccomp filter was installed with `TSYNC`, which synchronizes the filter across all threads *in the calling process*. But the `execve` happened in a child that had been forked *after* filter installation but *before* `TSYNC` completed propagating to the child's thread group under a specific race: the child called `execve` while the parent's `TSYNC` was still in flight, and the kernel applies `TSYNC` to threads existing at the time of the call. The child, being a separate process, was not covered. The filter was live in the parent and absent in the child that actually ran the skill. The skill did not need to know the race existed. It only needed to do something that forced the fork to happen early — a background thread spawned at import time, a `multiprocessing` pool initialized at module scope, a lazy C extension — and the timing window widened from microseconds to milliseconds, which is enough for a probabilistic agent to hit on retry. ## Condition of Validity The invariant "every syscall the skill issues is evaluated against the compiled profile" holds only if all three of the following are true: 1. The filter is installed in the same process that executes skill code, with no intervening `fork`/`clone` that escapes `TSYNC` coverage. 2. `NO_NEW_PRIVS` is set before filter installation and the skill cannot call `seccomp` itself to relax or stack a permissive filter (seccomp filters only compose by intersection, but a skill that installs its own filter *before* the runtime's can change the return-value semantics the runtime relies on). 3. The skill's entrypoint does not execute any code before the filter is confirmed live — meaning no import-time side effects, no constructors, no `atexit` handlers that run on a path the runtime doesn't control. Condition 3 is the one that fails silently. A skill author who writes `import requests` at module scope has already executed arbitrary code (DNS resolution, socket creation) before the runtime's `execve`-and-confine sequence has completed if the runtime confines *after* exec rather than *before*. The correct ordering is: fork → install filter → `execve`. The observed runtime did: fork → `execve` → (skill code runs) → install filter, under the assumption that the shim would block until the filter was ready. It did not. ## Decision Boundary The boundary is not "is the skill malicious" — it is "did the runtime observe the filter live in the same PID that issued the syscall." The decision the runtime must make on every skill launch is binary: - **Confined:** filter installed in the executing PID, verified by a self-test syscall (e.g., a deliberately denied `getpid` variant or a probe against a known-blocked syscall) returning `EPERM` *from inside the skill's process*, before any skill-controlled code runs. - **Unconfined:** any other outcome, including "filter installed in parent," "filter installed but `TSYNC` not confirmed," "skill forked before confirmation," or "self-test not run." The failure mode is treating "filter installed in parent" as equivalent to "confined." It is not. The decision must be made from inside the process that will run the skill, using a probe the skill cannot intercept, and the launch must abort if the probe does not return the expected denial. A probe that returns success means the filter is absent; a probe that returns a different errno means the filter is present but misconfigured; a probe that hangs means the process is in an unexpected state. All three are `Unconfined`. ## Operational Effect The practical consequence is that sandbox verification must be *in-band and post-install*, not *out-of-band and pre-launch*. Runtimes that log "sandbox active" from the loader have logged a property of the loader, not of the skill's execution environment. The correct operational effect is a hard gate: the skill's first action, injected by the runtime before any skill code, is a syscall probe. If the probe does not produce the exact expected denial, the runtime raises and terminates the child before the skill's entrypoint is reached. This adds one syscall of latency per launch and eliminates the entire class of TOCTOU-on-filter-installation escapes, including the `TSYNC`-fork race, the pre-exec import side effect, and the self-installed-filter ordering trick. ```python import os import signal import subprocess # A syscall the profile is expected to deny. Chosen because no legitimate # skill capability needs it and its denial is unambiguous. PROBE_SYSCALL = "socket" class SandboxConfinementError(RuntimeError): """Raised when a skill process is not demonstrably confined by its seccomp filter.""" pass def launch_confined_skill(skill_path: str, profile_path: str) -> int: """ Launch a skill under a seccomp profile and verify confinement from inside the executing process before any skill-controlled code runs. Ordering is load-bearing: fork -> install filter -> probe -> execve(skill). Any deviation (execve before probe, probe in parent, probe skipped) is a confinement failure, not a warning. """ # The probe runs as the very first thing in the child, before execve. # It must observe EPERM for PROBE_SYSCALL; anything else means the filter # is not live in this PID. probe = ( "import ctypes, errno, os, sys\n" "libc = ctypes.CDLL(None, use_errno=True)\n" "fd = libc.socket(2, 1, 0)\n" # AF_INET, SOCK_STREAM "err = ctypes.get_errno()\n" "if fd != -1 or err != errno.EPERM:\n" " sys.stderr.write(f'PROBE_FAIL fd={fd} errno={err}\\n')\n" " sys.exit(97)\n" "sys.exit(0)\n" ) # In a real runtime this is a fork + seccomp(TSYNC) + waitpid handshake. # The probe is executed in the same PID that will execve the skill. proc = subprocess.Popen( ["/usr/bin/python3", "-c", probe], preexec_fn=lambda: _install_seccomp(profile_path), ) _, status = os.waitpid(proc.pid, 0) if os.WIFEXITED(status) and os.WEXITSTATUS(status) == 97: raise SandboxConfinementError( "seccomp probe did not observe EPERM; filter not live in executing PID. " "Likely causes: TSYNC did not cover this process, filter installed after " "execve, or skill installed its own filter first." ) if not (os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0): raise SandboxConfinementError( f"confinement probe terminated abnormally: status={status}" ) # Only now, with confinement proven in-band, exec the skill. return subprocess.call(["/usr/bin/python3", skill_path]) def _install_seccomp(profile_path: str) -> None: """Placeholder: prctl(NO_NEW_PRIVS) + seccomp(SET_MODE_FILTER, TSYNC, prog).""" raise SandboxConfinementError( "seccomp installation not wired; refusing to launch unconfined skill" ) ```