iOS sandbox: a worker setting boots every leased simulator sandboxed and checked

Abierto
#2,043 0 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@V3RON ya está trabajando en esto.

Desde el 2/12/2026.

  • #2058 de @V3RON — abierto

Evaluación

Este issue todavía no se ha evaluado.

Descripción

task:ready

Part of #1648.

Scope

An operator turns on ios.sandbox.enabled on a worker: from then on every simulator that worker leases boots sandboxed and is checked before it is granted; one that fails is never leased. agent-device's boots on that worker are sandboxed too. A worker on an unchecked Mac, Xcode or device set refuses iOS and says why. A leased simulator found without the sandbox loses its lease. Without the setting nothing changes.

If it goes wrong, a sandboxed worker grants an unsandboxed simulator, or a worker without the setting boots or refuses differently than today.

Technical spec

Commit b037ae2a0.

Rows
  • Behaviours: B3, B4, B5, B6, B7, B15, B18
  • Stored state: S1, S2, S3
  • Interfaces: I15, I17, I2, I3, I4, I5, I6, I7, I14
  • Existing code: X1, X2, X3, X4, X5, X6, X7, X8, X9, X14, X17, X18, X23, X24, X25
Facts

none

Modules touched

drivers/ios (definition.ts, driver-options.ts, simulator-boot.ts, command-run.ts, index.ts, seeds.ts lookup, new jail-profile.ts, jail-platform.ts, jail-xcrun.ts, jail/profile.sb, jail/main.swift for I15, jail/Jail.swift for I3: SIMLOCK_JAIL_DIR, the profile and token found by SIMULATOR_UDID, in place of the prototype's SIMLOCK_JAIL_PROFILE and SIMLOCK_JAIL_TOKEN), core (driver.ts, startup-converger.ts, create-core.ts:423 where the converger's ports are built, managed-device-lifecycle.ts tests), leasing (lease-health-monitor.ts), daemon (driver-discovery.ts, worker-composition.ts), bus (src/bus/index.ts EventMap and EVENT_NAMES, index.test.ts) for driver.sandbox-rejected, agent-device (host/agent-device-supervisor.ts, worker.ts), e2e/slow-ios-sandbox.test.ts (new), website (reference/configuration.mdx, reference/events.mdx, troubleshooting/worker.mdx), docs/internal/EVENTS.md, src/drivers/ios/AGENTS.md, docs/internal/agent-rules/toolchain.md "The simulator jail" (its check steps use the new variables). Searches: rg "bootAndWait|virtualLeaseEnvironment|driverEnvironment|DriverRejection|IdleDeviceDeletion|launchd_sim" src.

Rules in play
  • ADR 0103 (Accepted — not yet implemented): the sections named on each line below; the feature's rows hold the shapes.
  • ADR 0103 §1–§4: per worker, off by default; every lease boot sandboxed and checked, fail closed; the kill block; checked platforms only.
  • ADR 0001 and 0048 as 0103 narrows them: the default set is refused with the sandbox on.
  • src/drivers/AGENTS.md: the driver imports only core, ports and shared; facts reach the bus through callbacks (the new event through driver-discovery.ts).
  • src/agent-device/AGENTS.md: the edge imports nothing from the drivers; the xcrun folder reaches it as driverEnvironment only.
  • src/core/AGENTS.md: the new deletion port commits through Registry; startup never installs.
  • Documentation rule 9: configuration, events and troubleshooting pages in this PR.
Tests

Seams: createDriver with a ScriptedProcessRunner (src/drivers/ios/test-index.ts:217, model src/drivers/ios/index-device-set.test.ts), src/drivers/ios/definition.test.ts, src/leasing/lease-health-monitor.test.ts, src/core/startup-converger.test.ts, src/agent-device/host/agent-device-supervisor.test.ts, src/core/create-core.test.ts (the deletion adapter), src/daemon/main-agent-device.test.ts (the agentDeviceEnvironment to PATH wiring) and src/daemon/driver-discovery.test.ts (the driver.sandbox-rejected payload) (seams added in delivery, pending the maintainer).

  • 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>: absent; enabled: true; enabled: "yes"; reversePorts: []; [8081, 8081]; [0]; [70000]; [80.5]; ["8081"]; 201 ports
  • B3a: a refused ios.sandbox value throws the message every other config key throws, Invalid config value for "ios.sandbox.<key>": expected …, and reversePorts: [8081, 8081] loads as [8081] (I4: duplicates kept once); the B3 test pins both (decided in delivery, pending the maintainer)
  • 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: prepare boot; recovery boot; reboot before a grant (default set); clipboard refresh reboot; listManaged
  • 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 drivers.ios.deviceSet is default (which ios.simulator.headless: false needs, so it is refused too); driver.sandbox-rejected is emitted with the reason and doctor lists its summary; Android starts: 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; deviceSet: default with headless: false or true: device-set; headless: false on the simlock set: invalid-device-set, as today (Simulator.app, which agent-device opens after each boot it makes, v0.21.43:packages/platform-apple/src/core/simulator.ts:187, sees Xcode's set and can boot a simulator without the sandbox)
  • 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: prepare; recover; reboot before a grant; seed throwaway; settle copy; empty reversePorts (no pair)
  • 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: 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)
  • 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 deletes an unleased ready one that its startup listing marked sandboxed: false, through a port of its own (UnsandboxedDeviceDeletion.deleteUnsandboxed, beside IdleDeviceDeletion in src/core/startup-converger.ts:27; record deleted, the events a delete commits today), and no other device; when a sandboxed simulator is deleted the driver first lists the processes whose program lies in its device folder and, after the delete, kills those still running, because a copy of launchd_sim run from there keeps Apple's signature and cannot be killed from inside: leased, sandboxed: nothing; leased, not sandboxed: lease lost, device reclaimed (deleted); ready, not sandboxed at startup: deleted (record deleted); ready and shutdown devices marked sandboxed, or not marked: kept; a process running a copy of launchd_sim from the device folder after the delete: killed; check fails to run: not marked (no evidence); without the sandbox: no check
  • 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; xcodebuild (through PATH or xcrun xcodebuild) boots a shut-down destination with the keys first; other calls pass on unchanged; without the sandbox the daemon's PATH is as today: 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 … -destination id=<udid> -DVTSimulatorSetLocation=<set> with the simulator Shutdown in that set: simctl --set <set> boot <udid> with the keys, then the real xcodebuild with the same arguments; that boot fails: its exit code, the real xcodebuild not run; same with it Booted: no boot; xcrun xcodebuild …: the same; xcodebuild with no simulator destination: unchanged; PATH of the simulator daemon: the wrapper folder then the old PATH; phone daemon: unchanged; without the sandbox: no wrapper on PATH
  • B6a: the clipboard-refresh second boot runs only on the default set, which a sandboxed worker refuses (B5), so it is not a sandboxed boot: it passes no jail key and B6 has no case for it (decided in delivery, pending the maintainer)
  • B15a: unsandboxedDeletion in src/core/create-core.ts shuts the device down, then destroys it with initiator unsandboxed; a failed delete is logged, not thrown; create-core.test.ts pins both (decided in delivery, pending the maintainer)
  • B19: src/drivers/ios/AGENTS.md is at its 8000-character cap, so it gains one short line pointing to ADR 0103 for the sandbox rules (the kill after a delete, the xcrun folder), with existing lines reworded, not dropped, to make room; src/docs-manuals.repo.test.ts stays green (decided in delivery, pending the maintainer)

Done when

  • Every unit case of B3–B7, B15, B18 passes; a worker without ios.sandbox keeps today's argv for every boot (B4).
  • website/src/content/docs/docs/reference/configuration.mdx documents ios.sandbox, events.mdx documents driver.sandbox-rejected and the unsandboxed reason, troubleshooting/worker.mdx each refusal.
  • Slow lane (real simulator): e2e/slow-ios-sandbox.test.ts (new) leases a simulator on a sandboxed worker, simlock-jail check passes for its root launchd_sim, and an app in it is refused the worker's home folder; the same test confirms agent-device's simulator daemon finds simlock's xcrun on PATH (I17).

Out of scope

The simctl allow-list (T3), port grants and the peer check (T4), the lease-folder grant (T5), the docs page on what the sandbox covers (T6).

Depends on

  • #2048 because: dist/jail/ and src/drivers/ios/jail/

Written by an agent.

Lenguaje dominante
TypeScript
Estrellas
730
Forks
44
Merge medio
15 h 28 min
PR fusionados (30 d)
387

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de callstackincubator/simlock

Todos los issues de callstackincubator/simlock

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.