The Seatbelt profile: an object policy in a name language

Seatbelt judges names. ral judges objects (object-not-name). Every line of core/src/authority/sandbox/macos.rs that is not a straight rendering of a grant is the cost of saying the second in the first:

  • Two spellings per path. /tmp is a firmlink to /private/tmp, and the kernel presents a lookup under whichever spelling the process used, so every rendered name (render_real, render_excluded) carries both — denies included.
  • No case or normalisation spellings. Measured (macOS 26.5), literal, subpath and regex all match modulo canonical caseless equivalence, for absent names as for existing ones, on case-insensitive and case-sensitive APFS alike: a deny on Secrets refuses mkdir secrets, and an NFC deny an NFD create. On APFS that is all the guard’s deny relation holds (denies-hold-under-every-spelling), the classes it adds for ZFS (ı ≡ I, compatibility forms) being distinct objects there, so a deny is rendered once. The residual is on the allow side: on a case-sensitive volume an allow on Work also admits the distinct work to a child, which the guard refuses; SBPL has no exact match to say otherwise.
  • Ancestor chains. (allow file-read* (subpath P)) does not make P reachable: Seatbelt gates each directory lookup on the way, so every proper ancestor of every granted name gets (allow file-read-metadata (literal …)) (emit_lookups, the one emitter of these lines for the fs, exec and GPU sections, over rendered_ancestors). Metadata suffices because search is all a resolver holds on an ancestor — the kernel’s, posix_spawn’s, and ral’s own walk, which opens its intermediates O_SEARCH for exactly this reason (the directory step of path/handle/macos.rs). A read handle there would need file-read-data, and a readable ancestor is a listable one: /Users, a home directory’s dotfile names.
  • Intermediate links. Holding a symlink with O_EVTONLY | O_SYMLINK needs file-read-data, even though traversing a directory needs only metadata. Each name the granted walk passed therefore also gets a literal file-read-data allowance guarded by (vnode-type SYMLINK). A directory or regular file replacing that link gains no data access; the target remains governed by its own rules.
  • Pins. A deny names a path, so renaming its parent would carry the bytes to a name the deny does not cover; every proper ancestor of a deny within a write prefix is (deny file-write-unlink (literal …)) — literal, never subpath, so its entries stay mutable (holding-a-deny). Linux pays the same price: it binds each pinned directory onto its own name.
  • Order. Seatbelt is last-match-wins, so every deny is emitted after every allow in the profile, not merely after its own. Profile is a record whose field order is that precedence — fs allows, exec rules, exec ancestors, fs denies, pins, net, gpu — and its Display writes the sections in it, the net and gpu profiles only where the frame leaves them on.
  • ral’s own file. A sandboxed command must not swap the ral that confines its children, so in every profile ral’s file is write-denied and its ancestors unlink-denied, whatever the grant.

The lens this gives: when the profile and ral disagree, ask first whether ral is asking for more than the kernel’s resolver would — the walk bug was exactly that — before making the profile say more.

What build_profile renders, rule by rule

fs. Restricted renders the grant’s read prefixes — which already carry the read floor and the write prefixes, joined by the fold — as file-read* subpaths with their ancestor chains, each name once, the write prefixes as file-write* subpaths, and then the denies: each exclusion denies reading, writing, linking and running, and (deny process-exec (require-not (require-any (subpath …) …))) over the read region refuses every program the fs does not read (plain (deny process-exec) when it reads nothing, which SBPL cannot say as an empty require-any). Seatbelt itself starts a program it may not read: measured on Darwin 25.5, a Mach-O, and a script’s interpreter, need process-exec alone. So running reads is a clause here, not a kernel property; without it a descendant ran anything every admits, and an fs exclusion stopped nothing running. Unrestricted passes both through — (allow file-read*), (allow file-write*) — so an exec-only grant can enter the sandbox for exec confinement without clamping the agent’s cwd or HOME.

The macOS floor is wholesale where cherry-picking breaks tools mysteriously: /private/etc (gitconfig, paths.d, zshenv, nix.conf; nothing user-secret sits there unprotected — master.passwd is 0600, and Seatbelt enforces inode permissions atop the profile), /private/var/select (xcode-select’s developer_dir and sh; denied, build drivers misreport the EPERM as a broken install), /private/var/run (resolv.conf’s target and the mDNSResponder socket). User temp and workspace paths are absent by design: they arrive through the grant.

exec. Unrestricted is (allow process-exec), so an fs-only grant does not attenuate exec at the OS layer; Any (every) renders the same way, with the table’s exclusions after it, and the fs section’s read bound below them. The backend admits nothing of its own: an Intel program under Rosetta needs process-exec on itself alone (measured), so /Library/Apple/usr is only read, through the floor. ral’s own binary is not admitted: it is an ordinary file, allowed where a policy clause allows it and reached by the denies after the positives. Then every positive exec clause, then every negative one. Positive clauses are process-exec alone, (allow process-exec (subpath|literal …)); reads, run places and support among them are the fs section’s, which renders them whether exec is restricted or not. Support (carriers, exec-carriers) arrives among the positives as File allows. A negative clause is (deny process-exec …) at each name an exclusion’s held positions render to, as the fs denies render (render_excluded), and a veto is (deny process-exec (regex "/name$")), the name wherever it resolves; an entry with both bits emits both clauses. Every path and name is spliced as an ordinary "…" literal with \ and " escaped, a veto’s regex metacharacters escaped beneath that, so no byte (a newline included) can end the literal; never the raw #"…", which has no escape and ends at the first " (measured: #"/a\"b$" fails to compile). Seatbelt matches each form caselessly, as the guard reads an exclusion. Ordering within each group is for stable output only; depth grants no exception, so last-match-wins puts every exclusion over every allowance, which is the guard’s rule (authority-is-belnap-evidence). Exec exclusions deny no reads: reading is fs’s to decide, and a veto would otherwise hide every same-named file. Allowed files and directories get their ancestor chains, computed from live() so that a suppressed scope never becomes an admitted root. Bundled tools run in the confined child, so no profile clause admits ral for them; they read ral’s binary through fs. This layer still cannot see argv; its job is the interpreter-bypass class the guard never sees (sh -c, env, xargs, find -exec). A program that runs only through every, or with exec omitted, starts only where the fs reads it, by the read bound above. The confined child applies its profile after it has started, so its own image is already mapped when the profile takes force.

Allowances render resolved. Every read, write and run allowance is rendered as its resolved real position, with its firmlink twins, and as nothing else: a surface spelling is never a predicate of its own. Seatbelt checks the resolved path of each access against it, so a symlink put in an allowance’s place reaches nothing. It does gate the hold and read of each link a lookup passes, so what the walk of an allowance’s spelling passed admits traversal alone: Object::walk is that walk’s Trace::passed — each link it followed, a chain’s middle ones included, and each directory a .. in a target climbed out of — each named under its parent’s real path and admitted as a file-read-metadata literal, with its proper ancestors, plus file-read-data guarded by vnode-type SYMLINK. This also covers the directories an absolute target abandons are covered. The spelling reaches the object while it leads there, and nothing beneath it once retargeted. Exclusions are rendered from the resolved real paths their walks held, never from the text as written; Seatbelt judges names, so the identity reading is ral’s own readers’.

There is no write freeze. An admitted directory a broad write covers stays writable, with or without a veto, under any fs; a name veto there is advisory to descendants, and authority::policy::deputy names such folders (authority-is-belnap-evidence).

Unix sockets follow stated writes. Each rendered write-prefix name P gets (allow network-outbound (subpath P)), (allow network-bind (local unix-socket (subpath P))) and (allow network-inbound (local unix-socket (subpath P))), beside its file-write* allowance (emit_fs_restricted, Clause, Filter). Each fs deny emits the same three operations and filters as denies in fs_denies, after the allows. Read-only prefixes and unrestricted fs add no socket rule. An exec-only, net-only or gpu-only projection therefore reaches no outside socket through fs. A write covering a deputy’s socket admits that deputy; a writable foreign socket can also be unlinked and replaced to intercept later clients. Sibling launches need a stated write covering the server socket. See unix-sockets-follow-writes.

net. Only a grant that does not say net: `offline appends macos-net.sbpl: every IP endpoint ((remote ip) out, (local ip) in and bind, loopback included); the resolver socket; and configd, dnssd and trustd’s Mach services. Never (allow network*), which also admits every Unix socket: measured on macOS 27, ssh-add -l under that wildcard listed the user’s keys. With the IP rules and no stated write covering the agent socket, it fails with EPERM; a stated write deliberately admits that deputy. RESOLVER_SOCKET, /private/var/run/mDNSResponder, is the one socket this file admits, as a plain path network-outbound filter: measured on Darwin 25.5.0, admitting that socket with mach-lookup denied still resolves names. mac_net_profile_admits_no_unix_socket_but_the_resolver checks this file alone; write-prefix socket rules are emitted separately. A write covering the resolver also admits it: like any deputy concession, it can carry an attacker-chosen DNS query label out even under an offline grant. With no write covering the resolver, the base’s silence is what closes DNS offline: getaddrinfo reaches mDNSResponder through network-outbound, never an automatically admitted local service. Local answers such as localhost may need no network access; failure to resolve them is not an offline invariant. local_ipc tests the resolver socket directly, with an online positive control, beside its IP and foreign-socket checks. mac_profile_denies_network_when_disabled asserts the absence of network rules for an offline projection with no stated writes, with an open-network positive control.

Session temp. exarch points $TMPDIR to $EXARCH_SCRATCH/tmp and makes that directory before any profile freezes. The five restrictive bundled profiles admit no shared temp directory, since one may hold other programs’ sockets. Hardcoded /tmp is refused on macOS; Linux discards its per-command tmpfs after each command.

gpu. Enforced by absence, like net. The base opens no IOKit user client and no Metal service; only a frame that does not withhold the GPU appends macos-gpu.sbpl: iokit-open of AGXDeviceUserClient (Metal’s device; without it “No Metal device available”) and IOSurfaceRootUserClient (without it “Failed to create Metal shared event”), and mach-lookup of com.apple.MTLCompilerService (a cold shader cache). Metal’s caches are paths, so build_profile renders them from confstr(_CS_DARWIN_USER_CACHE_DIR) (gpu_caches, resolved once, both firmlink spellings, among the fs allows so a deny still wins): read and write of the per-user com.apple.metal, com.apple.metalfe and com.apple.gpuarchiver caches. Without them a model load’s JIT build fails “unable to open output file … monolithic_metal.pcm”, and com.apple.metal is the one that cannot be dropped. An unresolvable cache directory renders none and refuses nothing. Residual: that write access lets a confined child alter the per-user shader caches unconfined programs read. Measured with MLX on Darwin 27, 2026-10-26 (small ops, and Qwen3.5 4B loaded and run once); IOAccelerator and IOSurfaceRoot are service classes, not user-client classes, and admit nothing; Apple Silicon only. The denial hint knows these names (GPU_NAMES) and answers gpu: `withheld.

The base, macos-base.sbpl

Policy-independent: true of every entry, whatever the grant. Its shape is adapted from BrianSwift/macOSSandboxBuild’s confined.sb — deny-default plus selective allows, the folded file-read* process-exec idiom, process-fork beside process-exec since Seatbelt gates the two separately — with paths inlined at build time rather than passed as scalar (param …)s, a grant’s admits being variable-length.

  • Mach services are named, never wholesale. A Mach name reaches a daemon that acts on your behalf outside the profile. Named: com.apple.dyld (dyld locates the shared cache through launchd; without it the child aborts before main), the notification center (libnotify, on the first notify_register_*), opendirectoryd’s libinfo and membership (getpwuid, ~, whoami, id), and the loggers (os_log; a denial is survivable, but every libSystem process hits it and would drown the denial log authority::sandbox::diag reads). Withheld, each with its reason as data in WITHHELD_SERVICES so the denial hint can quote it — a comment cannot reach the agent holding the EPERM, and a deliberate no read as an accident is chased instead of worked around: launchservicesd (and lsd.*) would spawn whatever /usr/bin/open names as an unconfined child of launchd — open -a Terminal ./payload.command is a full escape, open https://… egress under net: `offline; the pasteboard is a clipboard no grant mentions; SecurityServer hands out keychain items (security find-generic-password). Withholding securityd has one measured cost: cargo’s bundled libgit2 speaks TLS through SecureTransport, whose handshake reaches securityd and, denied, fails as ssl handshake -9808 and blames a missing revision; Apple’s curl and git reach trust through trustd alone. So exarch tells cargo to fetch through the git binary (app::CONFINED_TOOL_SETTINGS) rather than admit a service that hands the agent the login keychain. mac_profile_names_every_mach_service holds the shape.
  • (allow signal (target same-sandbox)) binds sending only: a timeout’s kill into the sandbox lands, kill -STOP back out at the host ral does not. Descendants share the instance; two per-command children of one grant do not, so signalling between sibling jobs is denied with everything else.
  • sysctl-read: libdispatch and libmalloc probe on init and abort if denied.
  • (allow file-read* (literal "/")): dyld reads the root inode before main. ral’s walk no longer needs it, and its root too would be a search handle once cap-primitives spells O_SEARCH in open_ambient_dir.
  • Device writes: /dev/null, /dev/zero, /dev/tty, /dev/dtracehelper: 2>/dev/null and libc paths open these for write even though /dev is readable.
  • /private/var/db/timezone/icutz: libc’s first localtime_r reads the ICU timezone database; it lies outside every grant prefix, and rustc, cc and ld SIGABRT in tzsetwall_basic without it.
  • POSIX shared-memory reads: ipc-posix-shm-read-data names only apple.shm.notification_center and com.apple.featureflags.shm. libnotify and os_feature_enabled read these; neither name is writable. The names are POSIX shared-memory names, not Mach services.
  • Python multiprocessing IPC: ipc-posix-sem admits names prefixed /mp-, and ipc-posix-shm names prefixed /psm_. The leading slash is part of each name; these admit Python’s own semaphores and shared-memory segments.
  • (allow file-ioctl), unfiltered as in Xcode’s, Bazel’s and Chromium’s build sandboxes, then (deny file-ioctl (ioctl-command TIOCSTI)). The allow is there for tcsetattr: without it a full-screen child cannot raise raw mode (tcgetattr and TIOCGWINSZ pass either way). It is also the known hole /dev/tty sits in: the projection carries fs, net and exec but not terminal-loan state, so the profile cannot deny tty ioctls to an ordinary Denied-terminal child while admitting them to a full-screen one. The open-time gate does not cover it, since an inherited terminal needs no open, and ioctl(fd, TIOCSTI, …) would type into the unconfined parent’s input. Measured on macOS 26, Seatbelt refuses that under hid-control, not file-ioctl: a (deny default) profile that never allows hid-control returns EPERM whatever it says about file-ioctl, and allowing hid-control alone lifts it. The base never does; the explicit deny, after the unfiltered allow, makes the refusal ours should that gate move. ioctl-command takes a symbol (hex is an unbound variable) and, given a number, matches only its low 16 bits — group and number, not direction or size — so write the name. A NewSession launch has no controlling terminal, and unconfined XNU refuses TIOCSTI itself (EACCES, isctty in tty.c); confined, Seatbelt answers first. The foreground launch keeps the terminal, so there the profile is the only wall.

Declared limits

A confined child reads every same-uid process’s argv and exec-time environment through sysctl KERN_PROCARGS2, as ps -E does. Measured 2026-10-26 under the base plus broad file-read*: argv and env of 553 of 800 processes, the launching agent’s own parent among them.

  • No rule closes it. XNU’s sysctl_procargsx (bsd/kern/kern_sysctl.c) checks only uid equality; every sysctl passes mac_system_check_sysctlbyname, yet a wholesale (deny sysctl-read) blocked KERN_PROC_ALL and not procargs2, as did (deny sysctl-read (sysctl-name "kern.procargs2")) and every process-info* rule, so the Sandbox kext evidently exempts it.
  • The kernel withholds the environment only from a cs_restricted target (platform binaries: Finder showed none) or from a caller holding an Apple entitlement. Anything launched from a shell shows its whole exec-time environment; argv always shows.
  • Closing it needs another uid for confined children, or a VM: a guest command, under a separate kernel, sees no host process, though guest commands share one uid and so read one another’s environment (guest jail). Nor does the Linux envelope, wherever the host admits --unshare-pid and its own /proc (linux-envelope).
  • So a process holding secrets must erase them from its launch bytes: exarch’s resolve_and_scrub (exarch/src/provider/credential.rs) zeroes each {NAME}_API_KEY value in place, the execve stack bytes KERN_PROCARGS2 and /proc/<pid>/environ read, before unsetenv. The residue is the user’s other processes: whatever a shell launched carries its exported variables, so secrets belong in the keychain or the vault.
  • Narrowing sysctl-read or process-info* buys nothing here and risks the agent’s control of its own processes, so the base keeps both.

Diagnosis

authority::sandbox::diag turns a parsed kernel operation into a hint: a path to read, write or exec, a network operand to the net: bit unless it names a Unix socket other than the resolver’s, which no grant opens, a Metal device, IOSurface or compiler to the gpu: bit, a Mach or IPC operand to nothing, since a service is the base’s to decide and no grant widens one (capabilities).

The collector runs /usr/bin/log show --style ndjson, with a 2-second deadline and a 1 MiB stdout ceiling. Each JSON event is decoded before its eventMessage is parsed: it must begin with Sandbox: , then the first (<digits>) deny(<digits>) supplies the PID and is followed by the operation and operand. Only records for the pid the command’s start claimed reach the hint: the program’s own, execved in place. A descendant is not claimed, so its record is not shown; no record is claimed falsely (an-external-end-to-end). Operands are held inert: C0, C1 and DEL are visible escapes, at most 512 Unicode scalar values are taken, and truncation is marked. The hint prints parsed records under “sandbox denials were recorded for this command’s processes:”; raw lines and embedded headers never become kernel testimony. A collector failure or bound leaves the command’s own error alone.

Open: the switch to --style ndjson has not been checked against a live denial. On a Mac, run a confined cat of a file the grant denies, then /usr/bin/log show --predicate 'eventMessage BEGINSWITH "Sandbox: "' --style ndjson --last 10s; the denial must appear as one JSON object whose eventMessage begins Sandbox: cat(<pid>) deny(. Delete this note once it does. If nothing appears, the reader has no source, and that is fixed before anything else in diagnosis.

Entry has one diagnosis of its own. A lineage already inside a profile — a per-command child of a confined runner — gets EPERM from sandbox_init, since profiles do not stack, and apply_profile reports it as such: the launch is refused rather than run under the wider profile. The fixed ALREADY_PROFILED prefix is followed by Seatbelt’s own error in parentheses (two-enforcers).