Repository navigation
Description
Request: none
Problem
A leased iOS simulator is not isolated from the Mac it runs on, or from the other simulators on it. Every process of a simulator runs as the worker's user with no sandbox. Measured on macOS 26.6 with Xcode 27.2 and the iOS 27.2 runtime, an app installed in one simulator could:
- read and change another simulator's app data;
- read and write the worker user's home folder,
~/.sshand the keychain folder included; - connect to any service on the worker's loopback, and to the other simulator's
testmanagerdsocket; - start programs of the Mac itself;
- look up the Mac's own services (pasteboard, WindowServer, the keychain server,
CoreSimulatorService), because CoreSimulator hands every simulator the host's bootstrap port.
A lease holder also runs simctl on the worker itself (device.exec, simlock simctl): it can shut its simulator down and boot it again (boot, or bootstatus -b), start a program outside the simulator (spawn -s), and write any file of the worker with simctl io <udid> screenshot <path>.
The docs say as much today: a device root is an accident boundary, and an agent token is shell access to the worker. So one worker cannot serve two clients who do not trust each other. No vendor documents isolation at the simulator level; the usual answer is one macOS VM per job, capped at two per Mac, or a dedicated Mac.
Draft PR #1649 holds a prototype that boxes a simulator in: a small library, loaded into the simulator's first process at boot, puts it and every process it starts under a macOS sandbox profile that refuses everything not listed. With it, all the attempts above were refused, while Safari, Settings, an XCTest run and an agent-device session still worked. Nothing in the driver uses it yet.
Who it is for
An operator who runs a worker behind a gateway for clients who do not trust each other: a device farm. An agent that runs on the worker itself already has its own shell there and gains nothing.
Outcome
- The operator turns the sandbox on for a worker. A worker without it behaves as today.
- From then on every simulator that worker leases runs sandboxed: it reaches its own folders, the iOS runtime, the internet, the loopback ports its lease opened with
reverse, and its lease's folder, and nothing else of the worker or of another lease. - A simulator whose sandbox did not take is never leased, and a leased one found running without it loses its lease.
- An app in a sandboxed simulator cannot kill the simulator. A simulator that shuts itself down comes back sandboxed when agent-device boots it, and any boot without the sandbox ends its lease.
- A client keeps installing an app from its lease's folder, launching it, running XCTest and using an agent-device session on a sandboxed simulator.
- On a Mac, macOS or Xcode the sandbox was not checked on, the worker serves no iOS and says why.
How it works for the user
flowchart TD
O[Operator sets ios.sandbox.enabled: true, restarts] --> C{Apple silicon, checked macOS and Xcode majors, jail files built, headless?}
C -- no --> R[iOS not started: driver.sandbox-rejected, doctor names the reason]
C -- yes --> B[Each lease boot: compile profile, boot with the jail, check]
B -- check fails --> D[Simulator destroyed, never leased]
B -- check passes --> L[Lease granted]
L --> P[simlock simctl: allow-listed verbs only]
L --> T[reverse on a listed port: granted while open]
L --> I[install from the lease folder: read granted]
Before, on any worker:
$ simlock simctl shutdown <udid> && simlock simctl boot <udid>
$ simlock simctl io <udid> screenshot /Users/worker/.ssh/authorized_keys
$ simlock reverse 9999
reverse 9999 -> worker loopback 9999
After, on a worker with ios.sandbox.enabled: true:
$ simlock simctl shutdown <udid>
simlock: Refusing `simctl shutdown` on a sandboxed worker: it would let the simulator come back without its sandbox. Release the lease for a fresh device instead.
$ simlock simctl io <udid> screenshot shot.png
simlock: Refusing `simctl io` on a sandboxed worker: it writes a file of the worker. Use the console's Screen tab or agent-device's screenshot instead.
$ simlock reverse 9999
simlock: TUNNEL_PORT_NOT_ALLOWED: reverse 9999: this worker's sandbox opens only the ports in ios.sandbox.reversePorts (3000, 4200, 5173, 8080, 8081, 8097, 19000, 19001, 19002, 19006)
$ simlock reverse 8081
reverse 8081 -> worker loopback 8081
$ simlock files put App.ipa && simlock simctl install App.ipa # a single file in the lease folder: works
Startup on an unchecked Xcode major, in simlock doctor:
ios: not started (driver.sandbox-rejected: unchecked-xcode): the iOS sandbox was checked on Xcode 27 only, and this worker runs Xcode 28. Driver discovery runs once, at daemon startup: restart the daemon (…) once this is fixed, or the platform stays unavailable.
Examples
simctl passthrough on a lease (device.exec or simlock simctl):
| Command | Today | Sandboxed worker |
|---|---|---|
simctl install <udid> App.ipa (lease folder) |
runs | runs (read inside the simulator; lease folder granted) |
simctl install <udid> /Users/worker/x.ipa |
runs | sandbox refuses the read |
simctl addmedia <udid> photo.jpg (lease folder) |
runs | runs (read inside the simulator, per the prototype's run) |
simctl launch <udid> com.x |
runs | runs |
simctl launch --stdout=/tmp/x <udid> com.x |
runs | refused (names a worker path) |
simctl spawn <udid> /bin/ls |
runs | runs (inside the sandbox) |
simctl spawn -s <udid> /bin/sh |
runs | refused (runs outside the simulator) |
simctl bootstatus <udid> |
runs | runs |
simctl bootstatus <udid> -b |
runs | refused (boots without the sandbox) |
simctl boot <udid> / shutdown <udid> |
runs | refused |
simctl io <udid> screenshot x.png |
runs | refused |
simctl push <udid> com.x payload.json |
runs | refused; push <udid> com.x - (stdin) runs |
simctl keychain <udid> add-root-cert x.pem |
runs | refused |
simctl diagnose |
runs | refused |
simctl erase <udid> |
refused | refused |
simctl list |
runs | runs |
reverse (default ios.sandbox.reversePorts):
| Port | Today | Sandboxed worker |
|---|---|---|
| 8081 | opens | opens, granted while open |
| 9999 | opens | TUNNEL_PORT_NOT_ALLOWED |
| 8081, already used by another lease | TUNNEL_PORT_IN_USE |
TUNNEL_PORT_IN_USE |
ios.sandbox.reversePorts:
| Value | Result |
|---|---|
| absent | the default list |
[8081] |
only 8081 |
[] |
no reverse on this worker |
[0], [70000], [80.5], ["8081"] |
config refused: a port is a whole number from 1 to 65535 |
| 201 ports | config refused: at most 200 |
[8081, 8081] |
accepted, one port |
What could go wrong
- A macOS or Xcode update is installed on a sandboxed worker: it serves no iOS until a Simlock release lists the new major. Likely about once a year per major.
- A client's command that names a file outside its lease's folder, or a
simctlverb off the list, fails where it worked before. - An agent-device install from an upload fails on a sandboxed worker.
- An app shuts its own simulator down (
launchctl reboot): agent-device or simlock boots it again sandboxed, and itsreverseports work again at the next health check. - An operator turns the sandbox on while leases are live: those leases end at the first health check after the restart, as lost.
- An operator reads "sandbox" as a guarantee. Some services of the Mac stay shared between simulators, and Android's
adbstill reaches the worker's files, so this is weaker than a VM. The docs say so.
Words used
- sandbox profile: the text file of rules macOS enforces on a process, here "refuse everything, then allow this list", e.g.
src/drivers/ios/jail/profile.sb. - jail library: the library loaded into a simulator's first process (
launchd_sim) that applies the profile before anything else runs, e.g.dist/jail/libsimlock-jail.dylib. - sandboxed worker: a worker with
ios.sandbox.enabled: true. - grant: a sandbox extension the worker issues so a running simulator may reach one more thing, e.g. loopback port 8081 while
reverse 8081is open. - checked majors: the macOS and Xcode major versions a Simlock release lists as tested with the sandbox, e.g. macOS 26 with Xcode 27.
- host bootstrap port: the handle CoreSimulator gives each simulator, through which a process can ask the Mac's
launchdfor any service of the logged-in user. - peer check: the worker finding which process opened a connection to a
reverselistener (or listens for a forward tunnel), and accepting it only when that process descends from the lease's rootlaunchd_sim. - root
launchd_sim: the simulator's first process: a process whose command names the device folder and whose program is the runtime's own<RUNTIME>/sbin/launchd_sim, read withlsof. A tenant can name a programlaunchd_simand orphan it, but cannot run that file: the profile forbids it.
Non-goals
- Android. An emulator is a virtual machine already; its
adbpassthrough stays as it is, and the docs say so. - A guarantee as strong as a VM or a dedicated Mac.
- Limits on CPU, memory or disk per simulator.
- Network rules by domain or address: the profile language only tells loopback from everything else, by port.
- Sandboxing per lease: the sandbox is the worker's.
- Installs through agent-device uploads on a sandboxed worker.
- Intel Macs, until the library's x86_64 build has run in a simulator.
Completion conditions
- On a worker without
ios.sandbox, every boot, passthrough andreverseruns as before (unit tests of each). - On a sandboxed worker on a Mac with Xcode, a leased simulator's app is refused the worker's home folder, another lease's simulator data, a loopback port its lease did not open, the Mac's programs and the Mac's services, and reaches its own data, a port its lease opened with
reverse, and a file in its lease's folder (slow lane). - A simulator whose sandbox check fails is shut down, never granted, and destroyed on a lease boot (unit test).
- A leased simulator found running without its sandbox (after the operator turned it on) loses its lease as
unsandboxed, and an unleased one is shut down at startup (unit test). - An app in a sandboxed simulator cannot kill its
launchd_sim, and after it shuts the simulator down withlaunchctl reboot, agent-device's next command boots it sandboxed (slow lane). - On a sandboxed worker an app installed from the lease's folder launches, an XCTest run passes and an agent-device session opens and taps (slow lane).
- A sandboxed worker on an unchecked macOS or Xcode major, on an Intel Mac, without the jail files, or with
headless: falsedoes not start iOS, emitsdriver.sandbox-rejectedand doctor names the reason (unit test). - The release fails when
dist/jail/lacks any of its three files. - The docs say what the sandbox covers, what it does not, and that it is weaker than a VM.
Open questions
None.
Decisions
- ADR 0101 — A worker may sandbox each iOS simulator it leases (PR docs(adr): 0101 a worker may sandbox each iOS simulator it leases (#1648) #2036): per worker and off by default; every lease boot sandboxed and checked, fail closed; the simulator cannot kill its own
launchd_sim; a leased simulator found without the sandbox loses its lease; checked majors on Apple silicon only;simctlpassthrough an allow-list; loopback ports and the lease folder by grant; the gaps said in the docs. - Android keeps working on a sandboxed worker; the docs say
adbpassthrough still reaches the worker's files. - Decided in the session: seed throwaways and settle copies boot without the sandbox, because no client code runs in them and every clone boots under its own profile at its own lease boot.
- Decided in the session: a sandbox that did not take is a failed boot (
DriverCrashError), and the driver shuts the simulator down before it throws, because a failed lease boot already destroys the device and a failed recovery boot is retried and then ends the lease, and neither may leave a booted simulator without its sandbox. - Decided in the session (maintainer): the profile blocks a process of the simulator from signalling its root
launchd_simand from starting another one (I2), and passthrough refusesbootstatus -bandspawn -s. A spike on the iOS 27.2 runtime ran these rules: SIGKILL, SIGTERM and SIGSTOP tolaunchd_simrefused, app launch, terminate,openurland background-relaunch unbroken, no othersignaldenial (hand-run, no bound). - Decided in the session (maintainer, "every boot carries it"): an app can still shut its simulator down with
launchctl rebootorreboot3(), which no profile rule stops, so every boot of a sandboxed simulator carries the jail: the library finds the simulator's profile by its UDID in the worker's jail folder (I3), and agent-device's simulator daemon gets anxcrunthat boots throughsimctl bootwith the jail's keys (I17), becausebootstatus -bdrops them (run). A boot simlock did not make is noticed at the next health check and re-granted (B17); one without the sandbox loses its lease (B15). - Decided in the session: the signal rule matches
launchd_simby launchd's signing identifier and Apple's signature together, because the identifier alone can be forged by an ad-hoc signed tenant program, which then could not be killed by a host shutdown either (spike);(target self)with(target children)was rejected because runningboardd could no longer stop apps (spike). - Decided in the session (maintainer): with the sandbox on, a leased simulator found running without it loses its lease as lost (
unsandboxed) and is destroyed; decided in the session: the driver checks every running simulator on eachlistManaged, so the health monitor finds it at its first tick after the restart, and startup shuts down an unleasedreadyone, because a ready simulator is granted without a boot on thesimlockset. - Decided in the session: the startup refusals are a new event,
driver.sandbox-rejected, besidedriver.root-rejected, because they are not about the device root, asdriver.adb-server-rejectedis its own event. - Decided in the session: the Apple-silicon test is
sysctl -n hw.optional.arm64, because Node under Rosetta reportsx64on Apple silicon. - Decided in the session: the default
reversePortsis 3000, 4200, 5173, 8080, 8081, 8097, 19000, 19001, 19002, 19006 (Metro, React DevTools, Expo, Vite, Angular, common web servers), because the spike compiled 100 ports in 0.13 s and these cover the dev servers a mobile client reverses. - Decided in the session: grants reach the simulator through a file the simulator can read but not write, consumed by the jail library in the root
launchd_sim, with port grants bound to its pid, because a tenant who reads a pid-bound token cannot consume it (spike), and one who cannot write the file cannot replay one. The lease-folder grant is a file token not bound to a pid, because a tenant who consumes it gains only its own lease's folder. - Decided in the session: tokens are issued by a new
simlock-jail issueverb, because the daemon is Node and the issuing calls are private C functions. - Decided in the session: the driver writes each simulator's profile as the shipped
profile.sbwith one allow and deny-unless-granted pair per listed port appended, because the loopback rules must come last and a port list cannot pass as oneNAME=VALUE; ports are whole numbers checked by the config, so nothing else reaches the text. - Decided in the session: T2 makes every change to
profile.sb(port pairs, grants file, acknowledgement file, lease-folder read class, the two self-issue denials, the signal rule), because T4 and T5 then build on a profile that is already final. - Decided in the session: the acknowledgement file is the one file the simulator may write in its jail folder, and the worker reads it no-follow, as a regular file, at most 32 bytes, because the simulator can replace it with a pipe or a link.
- Decided in the session: after a recovery boot the driver issues the grants of the lease's open
reversetunnels again, and the lease-folder grant once per boot, because the boot empties the grants file and starts a newlaunchd_sim. - Decided in the session: at startup the daemon releases every port grant left in a leased simulator's grants file, because no
reverselistener outlives the daemon. - Decided in the session: on a sandboxed worker forward tunnels use the same parent-chain check as the reverse peer check, because a tenant can start a listener with another lease's
SIMULATOR_UDID. - Decided in the session: the iOS driver reads the macOS version with
sw_vers -productVersionitself, becauseNodeHostInfofalls back to the kernel version, where Darwin 26 is macOS 27, and the driver gets noHostInfotoday. - Decided in the session: the peer check walks the parent chain to the lease's
launchd_simand never trustsSIMULATOR_UDID, because a tenant can start a program with any environment. - Decided in the session: the lease-folder grant is not released before the lease ends, because the simulator is destroyed when its lease ends.
- Decided in the session (maintainer's answer "leave it as a gap", read as): an agent-device install from an upload is a known gap on a sandboxed worker, and
simlock simctl installfrom the lease's folder is the supported install. - Decided in the session (maintainer): every terminal of the worker's user stays open to a sandboxed simulator, because XCTest needs a terminal whose name is not known before boot. The docs require a sandboxed worker to run as its own macOS user with nobody logged in on a terminal, and list as a gap that an app can read and write another lease's test-runner console; a follow-up issue will try per-terminal grants.
- Decided in the session: agent-device's fast accessibility snapshot stays off under the sandbox and is a known gap, because agent-device falls back to its XCTest path, which works.
- Decided in the session: the shared Mac services, POSIX shared-memory names, terminals, outbound connections to any non-loopback address (a cloud Mac's metadata service at 169.254.169.254 included) and Android guests reaching listeners inside a simulator through the worker's loopback are known gaps in the docs, and T6 probes the pasteboard, input and rendering services before the docs make any claim about them.
- Decided in the session: a new major is checked with the steps
docs/internal/agent-rules/toolchain.md"The simulator jail" lists (T1), then added to the checked list by a release.
Behaviours
| Id | Behaviour (invoker, action, what it sees) | Seam | Cases | Task |
|---|---|---|---|---|
| B1 | A maintainer builds on a Mac and gets dist/jail/libsimlock-jail.dylib (iOS Simulator, arm64 and x86_64), dist/jail/simlock-jail (macOS, both) and dist/jail/profile.sb; a build that loses either binary or a slice leaves it out with a warning, and the profile ships only beside both; not on a Mac, nothing is built; the build's slice logic is covered on Linux too, so Fallow's coverage gate passes |
src/build-capture.test.ts:28 scratchRepo with a fake xcrun |
all build; library fails; one macOS slice fails; no xcrun; not macOS; slice joining run with a fake xcrun on Linux |
T1 |
| B2 | The release job fails when the built dist/jail/ lacks one of its three files, and the packed tarball must hold all three |
.github/workflows/release.yml:176 step "Both iOS capture programs built", run as its shell script over a scratch dist/ |
all three present; library missing; profile missing; tarball without dist/jail/simlock-jail |
T1 |
| B3 | An operator sets ios.sandbox; the config loads enabled (default false) and reversePorts (default list), and refuses a bad value with invalid value for ios.sandbox.<key> |
src/drivers/ios/definition.test.ts:31 |
absent; enabled: true; enabled: "yes"; reversePorts: []; [8081, 8081]; [0]; [70000]; [80.5]; ["8081"]; 201 ports |
T2 |
| B4 | On a worker without the sandbox, every boot runs simctl boot with no SIMCTL_CHILD_ key, compiles nothing, checks nothing, and listManaged runs no check |
src/drivers/ios/test-index.ts:217 createDriver with a ScriptedProcessRunner |
prepare boot; recovery boot; reboot before a grant (default set); clipboard refresh reboot; listManaged |
T2 |
| B5 | A sandboxed worker's iOS driver does not start when the Mac is not Apple silicon, the macOS or Xcode major is not checked or not readable, the jail files are missing or ios.simulator.headless is false; driver.sandbox-rejected is emitted with the reason and doctor lists its summary; Android starts |
src/drivers/ios/index-device-set.test.ts:41 pattern, createDriver with extra options; src/daemon/driver-discovery.test.ts:97 for the event |
arm64 + checked majors: starts; hw.optional.arm64 prints 0: not-apple-silicon; sysctl exits non-zero (no such key): not-apple-silicon; sw_vers -productVersion 27.0: unchecked-macos; sw_vers fails: unchecked-macos (unreadable); Xcode 28: unchecked-xcode; xcodebuild -version fails: unchecked-xcode (unreadable); no dist/jail/simlock-jail: missing-files; headless: false on the default set: window |
T2 |
| B6 | On a sandboxed worker each lease boot writes the simulator's profile (shipped profile.sb plus one port pair per listed port), compiles it into its jail folder, empties its grants file, deletes its acknowledgement file, writes its token file, then runs simctl boot with the jail's two SIMCTL_CHILD_ keys (I3); seed throwaway and settle boots carry none |
createDriver (src/drivers/ios/test-index.ts:217), src/drivers/ios/boot-deadline.test.ts:48 bootBudgetDriver |
prepare; recover; reboot before a grant; clipboard refresh reboot (the second boot carries the keys too); seed throwaway; settle copy; empty reversePorts (no pair) |
T2 |
| B7 | After a sandboxed boot the driver finds the simulator's root launchd_sim (X14), records its pid as the boot's identity (X4), and runs simlock-jail check on it and every live process under it; a process that has exited by the check is skipped; on exit 0 the device is ready, otherwise the driver shuts the simulator down and the boot fails with I7; a failed lease boot destroys the device, a failed recovery boot is retried and in the end loses the lease |
createDriver; src/core/managed-device-lifecycle.ts:107 and :234 tests for the failed-boot paths |
check exits 0; check exits 1; a child gone between ps and the check (skipped, exit 0); root gone (exit 1); no root launchd_sim; a process named launchd_sim whose command names the device folder but whose program is another file, under the root or orphaned to pid 1 with a lower pid (not taken as root); lsof fails for a candidate (not taken); simlock-jail past 10 s; compile exits 65 (boot fails before simctl boot); recover boot fails the check (simulator shut down, error rethrown) |
T2 |
| B8 | On a sandboxed worker a lease holder's simctl passthrough passes only allow-listed verbs and options and refuses the rest with PASSTHROUGH_REFUSED and a reason; without the sandbox today's rules hold |
src/drivers/ios/test-index.ts:213 simctlPassthrough, src/drivers/ios/index-passthrough.test.ts:42 |
each row of the passthrough table in Examples; bootstatus -b and -b before the udid; bootstatus -cb and -bd (cluster holding b); spawn -s, spawn --standalone and spawn -ws (cluster holding s); an option off a verb's list (launch --foo, install -z); bootstatus -c and spawn -w (allowed); same commands without the sandbox; hasTerminal true (local CLI) and false (device.exec) |
T3 |
| B9 | On a sandboxed worker reverse <port> on a listed port has simlock-jail issue generic (I16) make a token bound to the root launchd_sim, appends a grant line, waits for the acknowledgement, then opens; close appends the release; an unlisted port is refused TUNNEL_PORT_NOT_ALLOWED before anything listens; no acknowledgement within 2 s, or an acknowledgement file that is not a small regular file, closes the listeners and answers TUNNEL_FAILED |
src/drivers/ios/device-tcp.test.ts:100 setup |
listed port; unlisted port; empty list; acknowledgement late; acknowledgement file a pipe or a link (read refused, TUNNEL_FAILED, no hang); port in use (TUNNEL_PORT_IN_USE first); close; issue fails; without the sandbox: no grant |
T4 |
| B10 | On a sandboxed worker a connection to a reverse listener is handed on only when the process that opened it (found by its local port) descends from the lease's root launchd_sim; a forward tunnel connects only to a listener whose process descends from it; otherwise the connection is closed |
src/drivers/ios/device-tcp.test.ts:100 setup with scripted lsof and ps, a fake TcpStream with a peer |
app of the lease; app of another simulator; worker process; peer exited before lsof; lsof fails; process with a forged SIMULATOR_UDID; a decoy launchd_sim of another simulator naming this lease's folder (not the root, refused); forward listener of another simulator with the lease's SIMULATOR_UDID; without the sandbox: as today |
T4 |
| B11 | Inside a sandboxed simulator the jail library in the root launchd_sim consumes each new grant line of its grants file and releases on each release line, writing the last line's number to the acknowledgement file; a process of the simulator cannot issue a com.simlock. grant itself, cannot use a token it read from the grants file, cannot signal the root launchd_sim or start another one, and consumes every line whatever its result, so an old line's failed consume stops nothing |
slow lane e2e/slow-ios-sandbox.test.ts (new) |
grant opens the port for a running app; release closes it; generic self-issue refused; file self-issue refused; a token read from the grants file and consumed by an app does nothing; an app's SIGKILL, SIGTERM and SIGSTOP of the root launchd_sim refused; an app's kill(-1, SIGKILL) leaves the root launchd_sim running; an app's exec of launchd_sim refused; an ad-hoc signed program named com.apple.xpc.launchd stays killable; an app's launchctl reboot shuts the simulator down and agent-device's next command boots it sandboxed (B18, B17); a token line bound to an older launchd_sim is skipped |
T4 |
| B12 | On a sandboxed worker a device.exec of simctl install or addmedia gives the simulator read access to the lease's folder before the command, once per boot of the simulator, a boot known by the root launchd_sim pid X4 records (T2), so a boot simlock did not make (B17) counts as new; the install then reads the file |
src/daemon/dispatcher-exec.test.ts:50; createDriver for the driver side; slow lane for the read |
first install; second install (no second grant); install after a recovery boot (granted again); install after a boot simlock did not make, root pid changed (granted again); addmedia; other verbs (no grant); grant not acknowledged in 2 s (refused, next install tries again); file self-issue of the lease class refused; without the sandbox (no grant) |
T5 |
| B13 | On a sandboxed worker a probe app in a leased simulator is refused the worker's home, another lease's simulator data, an unopened loopback port, a Mac program and a Mac service, and reaches its own data, an opened reverse port and its lease folder; an .ipa and a photo uploaded to the lease folder install and add; a worker path outside it does not; an XCTest run passes, an agent-device session opens and taps |
slow lane e2e/slow-ios-sandbox.test.ts |
each attempt in the case list, two leases on one worker | T6 |
| B14 | The probe also tries the shared Mac services (pasteboard between leases, input to another simulator, rendering of another simulator) and records each result; the docs page states the measured results and the gaps and nothing more | slow lane e2e/slow-ios-sandbox.test.ts |
pasteboard written by lease A read by lease B; input sent at B from A; B's screen read from A | T6 |
| B15 | On a sandboxed worker the iOS listManaged checks each running simulator and marks one whose root launchd_sim is not sandboxed; the health monitor ends a leased one's lease as lost (device.recovery-failed, reason unsandboxed) without a recovery attempt, and startup converge shuts down an unleased ready one |
createDriver for listManaged; src/leasing/lease-health-monitor.test.ts with a fake driver; src/core/startup-converger.test.ts |
leased, sandboxed: nothing; leased, not sandboxed: lease lost, device reclaimed (deleted); ready, not sandboxed at startup: shut down; check fails to run: not marked (no evidence); without the sandbox: no check | T2 |
| B16 | At startup on a sandboxed worker, the iOS driver appends a release line for every port grant left in a leased simulator's grants file, and numbers new lines after the file's last one; after a recovery boot it issues the grant of each reverse tunnel of that lease still open |
createDriver with a scripted grants file; src/drivers/ios/device-tcp.test.ts:100 |
two port grants left: two releases; none left; recovery with one open reverse: one new grant |
T4 |
| B17 | On a sandboxed worker, when listManaged finds a leased simulator's root launchd_sim with another pid than the one its last driver boot recorded and the check passes, the driver issues again the grants of that lease's open reverse tunnels, as after a recovery boot (B16); the lease-folder grant follows the new pid by itself (B12); found at the health monitor's next tick (src/leasing/lease-health-monitor.ts:113, every health.probeIntervalMs) |
createDriver with a scripted process table and grants file |
same pid: nothing; new pid, check passes, one open reverse: one grant bound to the new pid; new pid, check fails: B15; new pid, no open tunnel: no line |
T4 |
| B18 | On a sandboxed worker agent-device's simulator daemon runs xcrun through simlock's xcrun (I17): every simctl call carries the jail's two keys, so a plain simctl boot <udid> (agent-device's ensureBootedSimulator, v0.21.43 packages/platform-apple/src/core/simulator.ts:64-115) boots sandboxed, and simctl bootstatus <udid> -b becomes simctl boot with the keys, then bootstatus <udid> without -b; calls other than simctl pass on unchanged; without the sandbox the daemon's PATH is as today |
src/agent-device/host/agent-device-supervisor.test.ts for the environment; a unit test of the script written by jail-xcrun.ts with its real-xcrun path pointed at a recording fake (as src/build-capture.test.ts fakes one) |
simctl boot <udid>: the keys present; simctl --set <set> boot <udid>: --set kept, keys present; bootstatus <udid> -b: boot with the keys then bootstatus <udid>; boot exits non-zero "already booted": goes on to bootstatus; boot fails otherwise: its exit code, no bootstatus; simctl --set <set> bootstatus <udid> -b: the --set kept on both; simctl launch …, simctl list: keys present, arguments unchanged; xcodebuild …: no keys, unchanged; PATH of the simulator daemon: the wrapper folder then the old PATH; phone daemon: unchanged; without the sandbox: no wrapper on PATH |
T2 |
Stored state
| Id | What and where | Created, changed, deleted by | Listed or swept by | A restart mid-step leaves | Schema step | Task | Used by |
|---|---|---|---|---|---|---|---|
| S1 | A jail folder per sandboxed simulator, <simlockHome>/jail/<UDID>/, mode 0700, holding profile.sb (written), profile (compiled bytes) and token (the 6 characters of I2's TOKEN) |
Created and its files rewritten by each sandboxed lease boot (B6), before simctl boot; read by the jail library at every boot of that simulator, whoever makes it (I3), so they are kept between boots; deleted by destroy after simctl delete, as launchdOverridesRoot is (src/drivers/ios/index.ts:464) |
none: it lives and dies with its simulator | A boot cut after the compile leaves the folder; the simulator's next boot rewrites it or its destroy removes it | none | T2 | T4, T5 |
| S2 | grants in the S1 folder: lines <n> grant <class> <token> and <n> release <class>, n from 1 after each boot; readable, not writable, by the simulator |
Emptied by each sandboxed boot (B6); appended by reverse open and close (B9), the lease-folder grant (B12), startup releases and recovery grants (B16); deleted with S1 |
read by the jail library in the root launchd_sim (B11) |
A restart keeps the lines; startup releases the port grants left (B16); a recovery boot empties the file; a boot simlock did not make keeps it, and the library consumes its old lines again, the pid-bound ones failing harmlessly (B11, B17) | none | T2 | T4, T5 |
| S3 | ack in the S1 folder: the number of the last line the library applied; the one file of S1 the simulator may write |
Deleted by each sandboxed boot (B6); written by the jail library (B11); deleted with S1 | read by the driver no-follow, as a regular file of at most 32 bytes (I12), after each line it appends | nothing to clean: a forged number only hurts its own lease | none | T2 | T4, T5 |
Interfaces
| Id | What | Shape and bounds | Errors and limits | Where | Task | Used by |
|---|---|---|---|---|---|---|
| I1 | dist/jail/simlock-jail compile <profile.sb> <output> NAME=VALUE… and check <pid>…, as PR #1649 builds them |
compile: absolute profile path, output path, values as NAME=VALUE (name non-empty); check: one or more positive pids |
compile: 64 bad argument, 65 profile error (message from libsandbox), 66 unreadable profile, 70 libsandbox failure, 73 unwritable output; check: 1 simlock-jail: not sandboxed: <pids>; 10 s limit per call, from spawn |
src/drivers/ios/jail/main.swift (PR #1649) |
T1 | T2 |
| I15 | simlock-jail check skips a gone process |
a pid with no process (kill(pid, 0) answers ESRCH) is skipped; the first pid (the root) must exist |
1 simlock-jail: no process <pid> for the first pid |
src/drivers/ios/jail/main.swift |
T2 | — |
| I16 | simlock-jail issue generic <class> <pid> and issue file <class> <path> |
generic: class com.simlock.loopback.<UDID>.<port>, the pid it is bound to (sandbox_extension_issue_generic_to_process_by_pid); file: class com.simlock.read.<UDID>, an absolute real path (sandbox_extension_issue_file); each prints the token on stdout |
64 bad argument; 70 simlock-jail: cannot issue <class>: <errno>; 10 s limit, from spawn |
src/drivers/ios/jail/main.swift |
T4 | T5 |
| I17 | simlock's xcrun for agent-device |
a #!/bin/sh script <simlockHome>/jail/bin/xcrun, written by jail-xcrun.ts at each start of a sandboxed worker, mode 0755, with the real xcrun path (/usr/bin/xcrun) written into its text; for simctl … it runs the real xcrun with I3's two keys added to its environment, and turns simctl [--set <s>] bootstatus <udid> [opts] -b into simctl [--set <s>] boot <udid> then simctl [--set <s>] bootstatus <udid> [opts]; anything else is exec <real xcrun> "$@". The keys are harmless on a call that boots nothing: SIMCTL_CHILD_ keys reach only a process simctl starts in the simulator (launch, spawn), and that process is already sandboxed, so the library's constructor returns at once (the constructor in src/drivers/ios/jail/Jail.swift, PR #1649, returns when sandbox_check(getpid()) answers 1). How the edge finds the folder without importing a driver: the iOS driver's virtualLeaseEnvironment() (src/drivers/ios/index.ts:606) adds SIMLOCK_IOS_XCRUN_DIR=<simlockHome>/jail/bin on a sandboxed worker; it reaches the supervisor as driverEnvironment (src/daemon/worker-composition.ts:301, src/agent-device/worker.ts:129), and the simulator daemon's #environment (src/agent-device/host/agent-device-supervisor.ts:565) prepends it to PATH, as it already reads SIMLOCK_IOS_DEVICE_SET (:599); the phone daemon gets neither |
boot's stderr and exit code when it fails other than "already booted"; no limit of its own (agent-device's timeout holds). agent-device v0.21.43 runs plain xcrun (v0.21.43:packages/platform-apple/src/core/tool-provider.ts:57), so it is found through PATH; T2's slow-lane run confirms it; if not, B15 still ends the lease |
src/agent-device/host/agent-device-supervisor.ts, src/drivers/ios/index.ts, src/drivers/ios/jail-xcrun.ts (new) |
T2 | — |
| I2 | profile.sb parameters and rules |
Parameters UDID, TOKEN (6 characters), DEVICE, RUNTIME, LIBRARY, HOME, XCODE, JAIL (the S1 folder), LEASE_FILES (<dataDir>/lease-files), all real paths (/private/var never /var); a missing one stops the compile. Rules T2 adds: read of JAIL/grants, write of JAIL/ack, path ancestors of JAIL and LEASE_FILES; (allow file-read* (extension "com.simlock.read.<UDID>")); (deny generic-issue-extension (extension-class-regex #"^com\.simlock\.")) and the same for file-issue-extension; after (allow signal (target same-sandbox)), (deny signal (require-all (target-signing-identifier "com.apple.xpc.launchd") (target-attribute is-apple-signed-executable))) and (deny process-exec* (literal "<RUNTIME>/sbin/launchd_sim")) (spike, iOS 27.2 runtime: these hold; (target self) with (target children) hangs simctl launch); the single PORT parameter goes. Appended per listed port, last: (allow network-outbound (remote tcp "localhost:<p>")) then (deny network-outbound (require-all (remote tcp "localhost:<p>") (require-not (extension "com.simlock.loopback.<UDID>.<p>")))) (spike: the other orders do not hold) |
as I1 compile 65 |
src/drivers/ios/jail/profile.sb (PR #1649), src/drivers/ios/jail-profile.ts (new, writes the per-simulator text) |
T2 | T4, T5 |
| I3 | Boot environment of a sandboxed simctl boot, and how the library finds its files |
two keys, the same for every simulator: SIMCTL_CHILD_DYLD_INSERT_LIBRARIES=<dist/jail/libsimlock-jail.dylib> and SIMCTL_CHILD_SIMLOCK_JAIL_DIR=<simlockHome>/jail, passed through runCommand's new env, added to the daemon's own. The library in launchd_sim reads SIMULATOR_UDID from its environment and uses <JAIL_DIR>/<UDID>/profile, token, grants and ack (S1–S3). Run on this Mac (iOS 27.2 runtime, scratch set): SIMCTL_CHILD_SIMLOCK_PROBE=viaboot xcrun simctl boot <udid> then simctl getenv <udid> SIMLOCK_PROBE printed viaboot; the same through bootstatus <udid> -b printed 'SIMLOCK_PROBE' not found; ps -E of that launchd_sim showed SIMULATOR_UDID=<udid> and argv <device>/data/var/run/launchd_bootstrap.plist, the fallback when the key is missing |
SIMLOCK_JAIL_DIR set and no profile or token for the UDID, or neither the key nor the argv names one: the library ends launchd_sim (exit 78), so the boot fails; the boot's existing deadline |
src/drivers/ios/command-run.ts:29, src/drivers/ios/simulator-boot.ts:57 |
T2 | T4 |
| I4 | Config ios.sandbox |
enabled: boolean, default false; reversePorts: array of whole numbers 1 to 65535, at most 200, duplicates kept once, default [3000, 4200, 5173, 8080, 8081, 8097, 19000, 19001, 19002, 19006]; a driver key under ios, so no contract shape change |
invalid value for ios.sandbox.enabled: expected a boolean; invalid value for ios.sandbox.reversePorts: expected at most 200 whole numbers from 1 to 65535 |
src/drivers/ios/definition.ts:51 |
T2 | T3, T4, T5 |
| I5 | Checked platforms | a list of { macos: <major>, xcode: <major> }, first entry { macos: 26, xcode: 27 }; macOS major from sw_vers -productVersion run by the driver, Xcode major from xcodebuild -version (src/drivers/ios/components.ts:314), CPU from sysctl -n hw.optional.arm64 (Apple silicon only when it prints 1) |
each call 10 s; a failed call is the matching rejection | src/drivers/ios/jail-platform.ts (new) |
T2 | — |
| I6 | Event driver.sandbox-rejected |
{ platform: "ios", reason: "not-apple-silicon" | "unchecked-macos" | "unchecked-xcode" | "missing-files" | "window", detail: string ≤ 200 }; a DriverRejection like driver.root-rejected; doctor prints the summary and its usual restart remedy (src/core/doctor-findings.ts:137); new EVENTS.md entry |
summaries: the iOS sandbox runs on Apple silicon only; the iOS sandbox was checked on macOS <list> only, and this worker runs macOS <n>; the iOS sandbox could not read this worker's macOS version; the iOS sandbox was checked on Xcode <list> only, and this worker runs Xcode <n>; the iOS sandbox could not read this worker's Xcode version; the iOS sandbox's files are not built (dist/jail/); build on a Mac with Xcode; ios.simulator.headless: false opens DeviceHub, which can boot a simulator without the sandbox |
src/core/driver.ts:464, src/daemon/driver-discovery.ts:358 |
T2 | — |
| I7 | Failed sandboxed boot | DriverCrashError the sandbox did not take on <udid>: <check's stderr, first line>, the sandbox did not take on <udid>: no launchd_sim found, the sandbox did not take on <udid>: simlock-jail did not answer in 10 s, or could not compile the sandbox for <udid>: <compile's stderr, first line> |
as any failed boot | src/drivers/ios/index.ts:412 |
T2 | — |
| I8 | Sandboxed simctl allow-list |
verbs: addmedia, appinfo, bootstatus (never -b), get_app_container, getenv, help, icloud_sync, install, launch, list, listapps, location, openurl, pbcopy, pbpaste, privacy, push (only with - as its file), spawn (never -s / --standalone), status_bar, terminate, ui, uninstall; options are an allow-list per verb (the verb's simctl help options minus the refused ones); an option not on its verb's list is refused; a short-flag cluster (-cb) is read letter by letter and refused when any letter is refused or unknown; refused: bootstatus -b, spawn -s/--standalone, launch --stdout, --stderr (both forms); install and addmedia keep their path, because the simulator reads it inside its sandbox (prototype record, PR #1649 toolchain.md:208) |
PASSTHROUGH_REFUSED Refusing \simctl ` on a sandboxed worker: ; reasons: it would let the simulator come back without its sandbox. Release the lease for a fresh device instead. (boot, shutdown, bootstatus -b), it runs a program outside the simulator's sandbox. (spawn -s), it writes a file of the worker. Use the console's Screen tab or agent-device's screenshot instead. (io), it reads or writes a file of the worker.` (every other verb or option off the list) |
src/drivers/ios/passthrough-rules.ts:26 |
T3 | — |
| I9 | Error TUNNEL_PORT_NOT_ALLOWED |
details {}; message reverse <port>: this worker's sandbox opens only the ports in ios.sandbox.reversePorts (<list>); a new error code, bumps the protocol by one; errors.mdx |
refused before any listener opens | src/contract/errors.ts:444 (beside TUNNEL_PORT_IN_USE) |
T4 | — |
| I10 | Grant line and acknowledgement | S2 lines; the token from I16; the driver appends a line, then reads S3 (I12) every 100 ms until it holds that line's number or more, for at most 2 s | TUNNEL_FAILED reverse <port>: the sandbox did not open the port within 2 s |
src/drivers/ios/jail-grants.ts (new), jail library |
T4 | T5 |
| I11 | Lease folder on a passthrough | PassthroughContext.leaseFolder?: string, filled by device.exec from LeaseFiles.folderOf, resolved before the driver builds the command; the iOS driver issues I16 issue file com.simlock.read.<UDID> <folder> and writes its line through I10, once per boot |
a grant not acknowledged in 2 s: PASSTHROUGH_REFUSED Refusing \simctl `: the sandbox did not open the lease's folder within 2 s`; not counted as granted |
src/core/driver.ts:443, src/daemon/dispatcher-exec.ts:101 |
T5 | — |
| I12 | Small-file read of the file port | readSmallRegularFile(path, maxBytes): opens with no-follow and non-blocking, refuses anything not a regular file, reads at most maxBytes; Node adapter and fake |
undefined for a missing, non-regular or larger file |
src/ports/filesystem.ts:84 |
T4 | T5 |
| I13 | Peer of a loopback connection | TcpStream.peer?: { address: string; port: number } from the socket's remote address and port; Node adapter sets it, the fake takes it |
absent when the socket has none | src/ports/tcp-stream.ts:12, src/ports/tcp-listener.ts:27 |
T4 | — |
| I14 | Sandbox mark on an observed device | ObservedDevice.sandboxed?: boolean, set by the iOS driver on a sandboxed worker for a running simulator (false only when check ran and failed); new device.recovery-failed reason unsandboxed |
none | src/core/driver.ts:146, src/leasing/lease-health-monitor.ts:45 |
T2 | — |
Existing code
Commit cb48e18.
Searches: rg -n bootAndWait src (4 outside tests), rg -n SIMCTL_CHILD src (0), rg -n launchd_sim src (4), rg -n REFUSED_SIMCTL_VERBS src (3), rg -n driver.root-rejected src (7), rg -n folderOf src (17), rg -n "reverse(" src/drivers/ios (1), rg -n GiveUpReason src (2), rg -n "interface TcpStream" src (1).
| Id | Code (path:line) | Today | With this feature | Handled by |
|---|---|---|---|---|
| X1 | src/drivers/ios/simulator-boot.ts:26 bootAndWait |
the one boot routine: simctl boot, bootstatus -b, listapps on one deadline; shuts down only on a timeout (:51) |
takes the jail's environment for lease boots; its callers check after, and shut down on a failed check | B6, B7 |
| X2 | src/drivers/ios/simulator-boot.ts:57 #boot |
the clipboard refresh shuts a booted default-set simulator down and boots it again | the second simctl boot carries the same environment |
B6 |
| X3 | src/drivers/ios/command-run.ts:29 |
spawn gets { timeoutMs } only: no environment on the iOS command path |
takes an optional env, added to the daemon's own; the ProcessRunner port already accepts env (src/ports/process-runner-types.ts:3) |
I3 |
| X4 | src/drivers/ios/index.ts:412 makeReady |
boots, then runAfterBoot |
writes and compiles before, checks after on a sandboxed worker; after a recover boot issues the open tunnels' grants again; records the root launchd_sim pid of each driver boot (B7), read by B12 and B17 |
B6, B7, B16, B17 |
| X5 | src/drivers/ios/seeds.ts:318, src/drivers/ios/seeds.ts:548 |
settle copies and throwaways boot through bootAndWait |
unchanged: no jail environment | B6 |
| X6 | src/core/managed-device-lifecycle.ts:107 rebootForLease, src/core/managed-device-lifecycle.ts:234 recoverLeased |
both reach makeReady; a failed boot commits or rethrows; the health monitor retries a failed recovery (src/leasing/lease-health-monitor.ts:328) and gives up after maxRecoveryAttempts |
unchanged: the simulator is already shut down when the check fails, so the retries boot it under the sandbox again | B7 |
| X7 | src/drivers/ios/driver-options.ts:101 |
headless: false under the simlock set refuses iOS invalid-device-set |
with the sandbox on, headless: false on any set refuses iOS driver.sandbox-rejected (window) |
B5 |
| X8 | src/core/driver.ts:464 DriverRejectionEvent |
root and adb-server rejections | adds driver.sandbox-rejected |
I6 |
| X9 | src/daemon/driver-discovery.ts:358 |
publishes driver.root-rejected from a driver's refusal |
publishes the new event the same way | I6 |
| X10 | src/drivers/ios/passthrough-rules.ts:26, src/drivers/ios/passthrough-rules.ts:100 |
refuses create, erase, delete, shutdown all, runtime delete; boot, bootstatus -b, spawn -s and a single shutdown pass |
on a sandboxed worker, only I8's list passes | B8 |
| X11 | src/drivers/ios/passthrough-rules.ts:65 |
runs xcrun with an empty environment |
unchanged: a holder cannot pass SIMCTL_CHILD_ keys; execBaseEnvironment (src/daemon/exec-env.ts:28) keeps none either |
B8 |
| X12 | src/drivers/ios/device-tcp.ts:191 reverse |
listens on both loopbacks and hands every connection on (:211) |
on a sandboxed worker: listed ports only, grant before open, release on close, peer check per connection | B9, B10 |
| X13 | src/drivers/ios/device-tcp.ts:134 holdsUdid |
trusts SIMULATOR_UDID= in a listener's environment (forward tunnels) |
on a sandboxed worker, the parent-chain check replaces it | B10 |
| X14 | src/drivers/ios/seeds.ts:366 |
takes the first process whose command has launchd_sim and the device folder as the root |
a shared lookup (T2) takes as root only a candidate whose program, the first n line after ftxt of lsof -a -p <pid> -d txt -Fn, equals the real path of <RUNTIME>/sbin/launchd_sim (run here: lsof -p <pid> -Fn -d txt printed p429, ftxt, n<program path>); never by argv name or parent, since a tenant can orphan a process named launchd_sim to pid 1; tenants cannot run that file (I2 exec deny), and a hard link to it from the device folder fails because the runtime is another volume; one lsof per candidate, 10 s limit; it feeds check, listManaged, issue and the peer check |
B7, B10, B12, B15, B17 |
| X15 | src/daemon/dispatcher-exec.ts:101, src/daemon/dispatcher-exec.ts:135 |
asks the driver for the command (:101), then resolves the lease folder as its cwd (:135) |
resolves the folder first and passes it to the passthrough as leaseFolder |
B12 |
| X16 | src/lease-files/store.ts:82 folderOf |
creates the lease folder (0700) on first use | unchanged; the grant names it | B12 |
| X17 | src/agent-device/host/agent-device-supervisor.ts:565 #environment |
merges the base environment, driverEnvironment and agent-device's keys; agent-device's policy denies boot and shutdown, but its commands still run simctl boot and bootstatus -b on a simulator that is not booted |
on a sandboxed worker the simulator daemon's PATH starts with SIMLOCK_IOS_XCRUN_DIR from driverEnvironment (I17), prepended, never replacing; the phone daemon's is unchanged |
B18 |
| X18 | src/drivers/ios/boot-courtesies.ts:96 |
opens DeviceHub when headless is false |
never reached on a sandboxed worker (B5) | B5 |
| X19 | .github/workflows/release.yml:176 |
requires the two capture programs | also requires dist/jail/ |
B2 |
| X20 | src/contract/errors.ts:444 |
TUNNEL_PORT_IN_USE entry |
TUNNEL_PORT_NOT_ALLOWED beside it |
I9 |
| X21 | src/ports/tcp-stream.ts:12, src/ports/tcp-listener.ts:27 |
a TcpStream carries no peer address or port |
carries peer (I13) |
B10 |
| X22 | src/ports/filesystem.ts:84 |
readFile follows links and reads whole files |
adds readSmallRegularFile (I12) |
B9 |
| X23 | src/leasing/lease-health-monitor.ts:210, src/leasing/lease-health-monitor.ts:362 #giveUp |
a running observed device is healthy; give-up reasons attempts-exhausted, device-missing, provenance-drift |
a leased device marked sandboxed: false gives up at once with unsandboxed |
B15 |
| X24 | src/core/startup-converger.ts:57 converge |
acts on unleased devices: interrupted reclaims, spent deletes, off platforms | also shuts down an unleased ready device marked sandboxed: false |
B15 |
| X25 | src/ports/host-info.ts:33 NodeHostInfo.read |
a failed sw_vers falls back to the kernel version |
not used by the sandbox: the driver runs sw_vers -productVersion (I5) |
B5 |
Tasks
Written by an agent.
Activity
V3RON commentedon Dec 2, 2026
Design posted: business sections rewritten for the decided scope (sandboxed worker, allow-listed simctl, granted reverse ports and lease folder, checked majors); Decisions, Behaviours B1-B14, Stored state S1-S3, Interfaces I1-I11 and Existing code X1-X20 added; ADR 0101 in PR #2036.
Written by an agent.
docs(adr): 0101 closes the boot and spawn escapes and states the gran…
docs(adr): 0101 blocks the kill and sandboxes every boot of a sandbox…
V3RON commentedon Dec 2, 2026
Design updated: the checker fixes are in, the profile blocks killing
launchd_sim, and every boot of a sandboxed simulator carries the sandbox (agent-device boots through a Simlockxcrun; a boot Simlock did not make is re-granted or ends the lease). Open questions: none.Written by an agent.
docs(adr): 0101 finds the root launchd_sim by its program, sandboxes …
V3RON commentedon Dec 2, 2026
Design updated: the xcrun script sandboxes every simctl call of agent-device; passthrough options are an allow-list read flag by flag; the root launchd_sim is found by its program file, not its name or parent; the lease-folder re-grant after an outside boot moves to T5 (B12).
Written by an agent.