Skip to content

X23 - Self-sandboxed Go daemons on macOS

Purpose: Find out whether wb-netd, wb-proxyd and wb-hostd can confine themselves with a sandbox profile at start, as S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves. says, without breaking the Go runtime or the work each one does.

Requirements: SEC12-least-privilegeSEC12-least-privilege: Least privilege on the hostNo root or administrator rights at run time and no extra host user accounts., and the “Each host daemon is self-sandboxed” decision of S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves.

Brief: B34-sandboxed-daemonsB34-sandboxed-daemons: Can the Go daemons confine themselves on macOS?Yes, with conditions.

wb-proxyd with the Keychain and the Secure Enclave (I61)

Section titled “wb-proxyd with the Keychain and the Secure Enclave (I61)”

Can wb-netd, wb-proxyd and wb-hostd confine themselves at start with a sandbox profile, as S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves. says, while the Go runtime, inherited descriptors, and Keychain and Secure Enclave access in wb-proxyd keep working?

This result covers approach steps 1 and 2 of I34I34 (closed): X23-sandboxed-daemons: Self-sandboxed Go daemons on macOSX23-sandboxed-daemons (added to S11-verification-and-spikes in #14). Step 3, the wb-proxyd profile with Keychain and Secure Enclave access, is I61I61 (closed): X23-sandboxed-daemons: wb-proxyd profile with Keychain and Secure EnclaveSplit from #34 (X23-sandboxed-daemons) during triage on 2026-10-04., in “wb-proxyd with the Keychain and the Secure Enclave (I61I61 (closed): X23-sandboxed-daemons: wb-proxyd profile with Keychain and Secure EnclaveSplit from #34 (X23-sandboxed-daemons) during triage on 2026-10-04.)”.

Yes, with conditions.

Daemon Answer Profile
wb-netd Yes (deny default) and nothing else
wb-hostd Yes, with conditions its state directories, its Unix socket, and running git
wb-proxyd Yes (I61I61 (closed): X23-sandboxed-daemons: wb-proxyd profile with Keychain and Secure EnclaveSplit from #34 (X23-sandboxed-daemons) during triage on 2026-10-04.) outbound TCP, DNS, certificate checks, the Keychain and the Secure Enclave

The conditions:

  1. In process, without cgo. The daemon calls sandbox_init_with_parameters from libsystem_sandbox as its first act in main. A Go assembly trampoline makes the call, the way golang.org/x/sys/unix calls the C library. The binary builds with CGO_ENABLED=0 and cross-compiles from any OS. The cgo version behaves the same. Starting the daemon under sandbox-exec also works but needs a larger profile (below). Nothing before the call reads an inherited descriptor, the arguments or the environment. Right after the call, the daemon tries one operation its profile denies, and exits if that succeeds. wb-hostd is the exception to “first act in main”: condition 6 lists what it does first.

  2. Set GOMAXPROCS before confining. Go 1.25 and later re-read the CPU count (hw.ncpu) every second to adjust GOMAXPROCS. When the profile denies the read, the runtime sees one CPU, sets GOMAXPROCS to 1, and wb-netd throughput drops by about 40 percent. An explicit runtime.GOMAXPROCS(runtime.NumCPU()) before the call turns that update off, and GOMAXPROCS stays at 8 under a bare (deny default). The security review on PR65PR65 (merged): docs(spike): X23-sandboxed-daemons result, yes with conditionsResult of spike X23-sandboxed-daemons, approach steps 1 and 2 (the scope set by the 2026-10-04 decision on #34). found this, and the spike repeated it. Allowing sysctl-read of hw.ncpu works too. The explicit call is recommended because it keeps the wb-netd profile empty and doesn’t depend on which value the runtime reads.

  3. wb-hostd starts its children through a launcher (option A). A confined process can’t apply a second profile: the kernel refuses it (forbidden-sandbox-reinit), and children inherit their parent’s profile. So wb-hostd starts a launcher, wb-launcher, before it confines itself, and each program the launcher starts confines itself. The spike’s launcher showed that this works, but it was looser than this (it passed arguments and the environment, and read requests from a stream socket). A launcher that doesn’t widen what a compromised wb-hostd can do needs all of these:

    • It is a separate, small program that uses only the Go standard library. It isn’t wb-hostd started again in another mode, which would run the init code of every wb-hostd dependency unconfined.
    • Its request channel is a SOCK_SEQPACKET or SOCK_DGRAM socketpair inherited at start, never a path. It takes one fixed-format request per message. A request with unexpected descriptors has them closed and is refused.
    • It starts each program with no arguments and a fixed environment. The one bounded exception is the repository for wb-git (condition 4).
    • Each program’s profile and its parameters are compiled into the program, or come from configuration that wb-hostd read before it confined itself. They never come over the request channel.
    • Its program table holds absolute paths in the installed bundle, never under <config>, <data> or <logs>, and it checks that when it starts.
    • Each program has an instance cap (SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.).
  4. git gets its own profile (proposal), or inherits wb-hostd’s (measured). In the spike, git ran as a child of the confined wb-hostd and inherited its profile. That works, but a bug in git receive-pack, which parses packs the guest builds, would then have every right of wb-hostd. It could read every project’s policy, change approvals in state.db, write other projects’ landing repositories, and alter the audit log. The proposal: a wb-git shim that wb-launcher starts, which applies a profile for one repository and then runs git. That profile allows reading the git installation and writing that one repository. The spike didn’t build it.

    The repository and the git subcommand differ per request, so wb-git is the one bounded exception to the launcher’s “no arguments” rule:

    If the maintainer chooses the fallback instead, git under the wb-hostd profile is recorded in T00-indexT00-indexboundary 6 is the host terminal stream. as an accepted residual risk. Either way:

    • The profile allows only the git installation: bin/git, libexec/git-core/, share/git-core/ and the libraries git links. Homebrew git links pcre2 and gettext through /opt/homebrew/opt/<lib>, a symbolic link into /opt/homebrew/Cellar/<lib>/<version>. Seatbelt matches resolved paths. Each library needs two rules: file-read-metadata on the /opt/homebrew/opt/<lib> literal, and file-read* on the resolved Cellar subpath, with the real path resolved before confining (the security review on PR65PR65 (merged): docs(spike): X23-sandboxed-daemons result, yes with conditionsResult of spike X23-sandboxed-daemons, approach steps 1 and 2 (the scope set by the 2026-10-04 decision on #34). reproduced this). process-exec can be limited to git, git-receive-pack and git-upload-pack. The spike allowed all of /opt/homebrew or the whole Xcode developer directory, which is wider than git needs.
    • wb-hostd resolves the /usr/bin/git shim to the real binary before it confines itself.
    • git runs without the user’s or the system’s git configuration, in a working directory inside <data>, with the repository directories created before it runs.
  5. Profiles take paths as parameters. Generated rules, such as the ones for each parent directory of <data> (below), name parameters ((param "PARENT1")), and the paths go in as parameter values. The spike pasted the paths into the profile text instead. The security review on PR65PR65 (merged): docs(spike): X23-sandboxed-daemons result, yes with conditionsResult of spike X23-sandboxed-daemons, approach steps 1 and 2 (the scope set by the 2026-10-04 decision on #34). showed that a crafted path then turns the profile off, so the daemon runs unconfined.

  6. What wb-hostd does before it confines itself. It reads its own configuration, sets GOMAXPROCS, loads the local time zone, starts the launcher, resolves the git binary, and works out the paths and parameters for its profile. None of that reads anything the guest sent.

  7. Each daemon fails closed. A profile that doesn’t compile, or a missing parameter, makes the call fail and the daemon exit.

Host: macOS 27.0.1 (26A434), Apple Silicon, Go 1.27.1. The spike code and its recorded output are on the spike branch: spikes/x23-sandboxed-daemons at 6602ecb, and the GOMAXPROCS check after review at 00c2119 (results/ holds the output of each run).

A probe program applied each profile to itself and then tried each operation. Under deny-all.sb ((deny default) and nothing else), applied in process:

Works Denied
goroutines, garbage collection, returning memory to the OS, async preemption, timers opening any file, /etc/passwd, the home directory, /tmp
crypto/rand, ECDSA signing stat of any path, os.Getwd, os.Hostname
inherited descriptors: stderr, sockets TCP and UDP connect, also to loopback
socketpair and passing descriptors with SCM_RIGHTS connecting to a Unix socket by path, listen
DNS lookups, running a program, signals to other processes
Mach service lookups the system libraries try: com.apple.logd, com.apple.system.notification_center, com.apple.system.opendirectoryd.libinfo
sysctl reads such as kern.hostname and kern.ipc.somaxconn

The profile applies to every thread of the process, including the ones the Go runtime started before the call. A file open from 32 goroutines, each locked to its own OS thread, was denied on all 32.

time.Local becomes UTC, because the time zone file can’t be read. A daemon that needs local time loads it before it confines itself.

wb-netd: gVisor over inherited descriptors

Section titled “wb-netd: gVisor over inherited descriptors”

A stand-in for wb-netd confined itself, then ran a gVisor stack on an inherited datagram socket with one Ethernet frame per datagram (as the file-handle network attachment uses). For each TCP connection from a guest stack on the other end, it made a socketpair, passed one end to a proxy over an inherited Unix socket with SCM_RIGHTS, and copied the stream to the other end. The proxy echoed. Each run sent 64 MiB each way on each of 4 streams:

Mechanism Profile Echo throughput
not confined none 420 MiB/s, median of 5
in process, no cgo netd.sb (hw.ncpu allowed) 438 MiB/s, median of 5
in process, cgo netd.sb 418 MiB/s, median of 5
sandbox-exec netd-exec.sb 439 MiB/s, median of 5
in process, no cgo (allow default) 404 MiB/s, median of 5
in process, no cgo deny-all.sb 258 MiB/s, median of 3
in process, no cgo, explicit GOMAXPROCS deny-all.sb 437 MiB/s, median of 3 (runs: 437, 314, 458)
in process, no cgo, same session netd.sb 472 MiB/s, median of 3

All streams arrived complete. The differences between the rows other than plain deny-all.sb are within the noise of a shared machine. The call took 5.36 to 9.26 ms in the recorded runs.

The recommended wb-netd profile is the bare one, with GOMAXPROCS set before the call:

(version 1)
(deny default)

Under it, the stand-in couldn’t open, write or stat a file, connect over TCP, UDP or a Unix socket path (also to a listener in the same test), listen, resolve a name, or run a program. Its log goes to an inherited descriptor: a pipe or socket to wb-hostd, never a descriptor on a file in <logs> or <data>. A profile is checked when a file is opened, not on each write, so an inherited file descriptor would keep working under any profile.

In process sandbox-exec
Profile the rules the daemon needs those, plus loading the binary: running it, reading it, /usr/lib, the dyld cache, and the sysctl values the Go runtime reads at start
cgo not needed not needed
Who chooses the profile the daemon, from a profile compiled into it its parent, on the command line
Apple’s status sandbox.h marks sandbox_init “No longer supported” since 10.8, and doesn’t declare sandbox_init_with_parameters the man page says “DEPRECATED”

sandbox-exec with (deny default) alone can’t start the program at all (execvp() ... Operation not permitted). The extra rules let any code in the process read /usr/lib and the system libraries until it exits. In process, the profile only has to allow what the daemon does after start.

The variant with parameters takes paths such as <data> as values that the profile reads with (param "DATA"), so paths stay out of the profile text (condition 5).

Both interfaces are deprecated and both still work. Apple points developers at App Sandbox, which is set by entitlements at signing time. Its entitlements switch capabilities on or off (network client, for example) and give the program a container directory. This spike didn’t try it.

A stand-in for wb-hostd confined itself to its directories (parameters CONFIG, DATA, LOGS), then:

Check Result
read <config>/config.toml allowed
write in <config> denied
create, lock (flock) and write <data>/state.db allowed
append to <logs>/audit.jsonl allowed
listen on a Unix socket in <data>/run, serve a client outside the sandbox allowed
read or write outside its directories, TCP or UDP out, DNS, listen on TCP denied
git round trip with Homebrew git: init --bare, commit, push (receive-pack), clone (upload-pack) works
the same with the Xcode git binary, found with xcrun --find git before confining works
the same through the /usr/bin/git shim fails: the shim runs xcode-select, which reads /var/select/developer_dir
start a wb-netd child that confines itself fails: forbidden-sandbox-reinit
the same through a launcher started before confining works, and the child’s profile holds
ask the launcher for a program not in its table (sh) refused

git needed these from the profile and from wb-hostd:

  • Running and reading the git installation, and /dev/null.
  • No user or system git configuration: GIT_CONFIG_NOSYSTEM=1, GIT_CONFIG_GLOBAL=/dev/null and HOME set to a state directory. git treats a denied ~/.config/git/config as an error and stops. The git gateway must not use the user’s git configuration in any case.
  • Metadata reads (stat) of each parent directory of <data>, because git resolves real paths from the root. A profile has no rule for “the parents of a path”, so the profile needs one rule for each parent, with the path as a parameter (condition 5).
  • A working directory inside <data>, and the repository directories created by wb-hostd before git runs.

The local push and clone in the test start git-receive-pack and git-upload-pack through /bin/sh, which the test profile allowed. The git gateway runs them directly (S08-workspace-and-gitS08-workspace-and-git: Workspace and Git Round TripHow code gets into the guest and how the agent's work gets back out, without sharing the host filesystem.), so the real profile doesn’t need a shell.

The profile that ran, without the generated parent rules and without the NETD rules that let the spike start wb-netd directly:

(version 1)
(deny default)
(allow sysctl-read (sysctl-name "hw.ncpu"))
(allow file-read* (subpath (param "CONFIG")))
(allow file-read* file-write* (subpath (param "DATA")) (subpath (param "LOGS")))
(allow network-bind network-inbound
(local unix-socket (subpath (string-append (param "DATA") "/run"))))
(allow process-fork)
(allow process-exec (literal (param "GIT")))
(allow process-exec file-read* (subpath (param "GITROOT")))
(allow file-read* file-write-data (literal "/dev/null"))
; git starts under this profile, so dyld must load it.
(allow file-read* (literal (param "GIT")))
(allow file-read* (literal "/") (subpath "/usr/lib")
(subpath "/System/Library/dyld") (subpath "/System/Cryptexes/OS"))
(allow file-read-metadata (subpath "/System/Volumes/Preboot/Cryptexes"))
(allow sysctl-read (sysctl-name "hw.pagesize" "hw.pagesize_compat"
"hw.logicalcpu_max" "hw.physicalcpu_max" "kern.osrelease" "kern.osversion"))

GITROOT was /opt/homebrew or /Applications/Xcode.app/Contents/Developer. Condition 4 narrows it to the git installation. That narrower rule set was not run.

SQLite itself was not run. state.db stands for it with a file lock and a write.

This is the part of wb-proxyd that doesn’t use the Keychain. I61I61 (closed): X23-sandboxed-daemons: wb-proxyd profile with Keychain and Secure EnclaveSplit from #34 (X23-sandboxed-daemons) during triage on 2026-10-04. added the rest, in “wb-proxyd with the Keychain and the Secure Enclave (I61I61 (closed): X23-sandboxed-daemons: wb-proxyd profile with Keychain and Secure EnclaveSplit from #34 (X23-sandboxed-daemons) during triage on 2026-10-04.)”.

  • Outbound TCP and DNS work under a short profile: network-outbound to TCP, UDP to port 53, reading /private/etc/resolv.conf and /private/etc/hosts, and connecting to /private/var/run/mDNSResponder, which Go’s resolver uses through libSystem on macOS (profiles/proxyd-net.sb).
  • Checking a server certificate against the system roots fails under that profile (SecPolicyCreateSSL error: 0). It works once the profile also allows the trustd, SecurityServer, cfprefsd and ocspd services, reading the Security framework and the system keychains, and every stat and sysctl read (profiles/proxyd-net-tls.sb). That profile is too wide, and I61I61 (closed): X23-sandboxed-daemons: wb-proxyd profile with Keychain and Secure EnclaveSplit from #34 (X23-sandboxed-daemons) during triage on 2026-10-04. must not start from it as it is.

wb-proxyd with the Keychain and the Secure Enclave (I61)

Section titled “wb-proxyd with the Keychain and the Secure Enclave (I61)”

From I61I61 (closed): X23-sandboxed-daemons: wb-proxyd profile with Keychain and Secure EnclaveSplit from #34 (X23-sandboxed-daemons) during triage on 2026-10-04.: can wb-proxyd run under a profile that allows outbound network, its Keychain items and Secure Enclave signing, and denies the rest?

I61I61 (closed): X23-sandboxed-daemons: wb-proxyd profile with Keychain and Secure EnclaveSplit from #34 (X23-sandboxed-daemons) during triage on 2026-10-04. was filed before B23-keychain-unsignedB23-keychain-unsigned: How do development builds without a signing identity keep their Keychain items and their CA key?Between updates the access-control list works, but after each update every item asks for a password nobody knows. and B248-dev-signingB248-dev-signing: Can development builds signed by the developer's own team share Keychain items across an update?Yes, with conditions. were decided, and asked for a throwaway keychain file. Since those decisions, wb-proxyd keeps its items in the data protection keychain behind access groups of the team that signed the build (S15-least-privilegeS15-least-privilege: Least Privilege on the HostThe security design for SEC12-least-privilege: which rights Wraith Box takes on the host, where credentials are held, and how each host process gets only the credentials it needs, for only as long as it needs them.). The spike measured that setup.

Yes. The profile:

(version 1)
(deny default)
(allow network-outbound (remote tcp))
(allow file-read-metadata (literal "/etc") (literal "/var"))
(allow file-read* (literal "/private/etc/resolv.conf")
(literal "/private/var/run/resolv.conf") (literal "/private/etc/hosts"))
(allow network-outbound (remote udp "*:53"))
(allow network-outbound (literal "/private/var/run/mDNSResponder"))
(allow mach-lookup (global-name "com.apple.trustd.agent"))
(allow file-read-metadata (literal (param "BUNDLE")))
(allow mach-lookup (global-name "com.apple.securityd.xpc"
"com.apple.ctkd.token-client"))

BUNDLE is the real path of the helper’s bundle directory, .../Contents/Helpers/wb-proxyd.app, worked out before the daemon confines itself (condition 5).

Host: macOS 27.0.1 (26A434), Apple M2, Go 1.27.1, Xcode 27.0. The helper was built as in X29-dev-signingX29-dev-signing: Keychain access group for development buildsCan a developer's free personal team, an Apple ID signed in to Xcode without a paid membership, sign the helpers in Wraith Box.app (wb-proxyd, wb-hostd, wb-vmd) with a keychain-access-groups entitlement and a provisio…: a cgo binary as the main executable of Contents/Helpers/i61.app, with the profile embedded, signed with the hardened runtime by the team G7BF23LV79 and holding the groups G7BF23LV79.nl.wraithbox.binding and G7BF23LV79.nl.wraithbox.ca. It confined itself with the no-cgo call from condition 1, which also works inside a cgo binary, then checked that /etc/passwd couldn’t be opened, then ran each probe. No dialog appeared at any step.

Probe Unconfined Network part only Final profile
write, read, delete binding/ item works fails: -25291 works, 0.4 to 5 ms
new Secure Enclave key, token object ID into a ca/ item works fails: -26276 works, 13 ms
read the ca/ item, restore the key, sign, verify works fails: -25291 works, 5 ms
delete the ca/ item works fails works
read an item in the group nl.wraithbox.store -34018 -25291 -34018
list the file-based keychains, attributes only 166 items -50 -50
DNS lookup works works works
TLS GET of api.anthropic.com, system roots works fails: SecPolicyCreateSSL error: 0 works
open /etc/shells, the home directory, login.keychain-db works denied denied
write in /tmp works denied denied
listen on loopback TCP, or on a Unix socket in /tmp works denied denied
UDP to port 123 works denied denied
run /bin/echo works denied denied

The final profile ran four times with the same result. Applying it took 5 to 8 ms in the recorded runs.

-34018 is errSecMissingEntitlement. The code signature refuses the other group, under a profile and without one. The profile, not the signature, keeps the login keychain out. Unconfined, the helper saw the attributes of its 166 items.

sandboxd reported only three violations for the network-part run, the two Mach services above and com.apple.analyticsd, and none for the failed certificate check. On macOS 27 the reports come from sandboxd, not from the kernel’s Sandbox sender that I34I34 (closed): X23-sandboxed-daemons: Self-sandboxed Go daemons on macOSX23-sandboxed-daemons (added to S11-verification-and-spikes in #14) read. With the two services added, the store worked. For the certificate check a script took the wide I34I34 (closed): X23-sandboxed-daemons: Self-sandboxed Go daemons on macOSX23-sandboxed-daemons (added to S11-verification-and-spikes in #14) TLS rules, one rule per name or path, and dropped each one whose removal still let the TLS probe pass twice in a row. Then it did the same for the paths under /Users that the remaining file-read-metadata rule needed.

com.apple.analyticsd stays denied, and nothing failed for it.

Throwaway code on branch spike/x23-sandboxed-daemons, commit 546489c, tag spike-x23-sandboxed-daemons-i61: the helper (i61/helper), its build and run scripts, the minimizing script, the profiles, and the recorded output (i61/results).

Status: Answered: yes with conditions. wb-proxyd Keychain part answered 2026-10-15 (I61I61 (closed): X23-sandboxed-daemons: wb-proxyd profile with Keychain and Secure EnclaveSplit from #34 (X23-sandboxed-daemons) during triage on 2026-10-04.): yes