feat: add daemon policy to confine devices, commands, and device shutdown
Summary
Operators can now confine a daemon, for example a remote agent-device proxy host, to one simulator and stop agents from shutting it down. The config is one JSON file:
{
"version": 1,
"devices": { "allow": [{ "udid": "<simulator-udid>" }] },
"commands": { "deny": ["boot", "shutdown"] },
"capabilities": { "deny": ["device-shutdown"] }
}
AGENT_DEVICE_DAEMON_POLICY=./policy.json agent-device proxy
Before: the only hook was AGENT_DEVICE_HTTP_AUTH_HOOK. It sees top-level RPCs only, so batch steps (where shutdown is allowed), replay actions, device names resolved inside the daemon, and close --shutdown all got past it.
After: the daemon itself checks the policy at three points (ADR 0029):
- Request gate in
createRequestExecutionScope. Denied commands, abatchthat names a denied step,close --shutdown, and an explicit foreign--udid/--serialare refused before any lock or device resolution.batchsteps andreplayactions call this function again, so they are checked too. - Device scope. Runtime bindings refuse a resolved device outside the scope before the gateway binds it. Device inventory, and so
devicesand automatic selection, lists only allowed devices. - Capability gate. The device-shutdown host capability refuses every shutdown, whichever command asks.
The daemon loads the policy once and refuses to start if the file is not valid. A denial returns UNAUTHORIZED with details.reason: "DAEMON_POLICY_DENIED", the rule, and a do-not-retry hint. It never includes the policy path. The daemon writes the policy digest to daemon.json. A client that names a policy refuses to reuse a daemon that enforces a different policy or none. Without AGENT_DEVICE_DAEMON_POLICY, behavior does not change.
Docs: ADR 0029, the ADR index, remote help text, and website/docs/docs/remote-proxy.md. There is no CONTEXT.md entry: the glossary is at its 12,000-byte budget, so ADR 0029 names the term.
Validation
- Live check on an iOS 26 simulator (iPhone 17), with an isolated state dir and the policy above:
devices --platform ioslisted only the pinned simulator. The host has 8 available.open --udid <other simulator>was denied withrule: device.open com.apple.Preferenceswith no device selected opened on the pinned simulator.snapshotworked.shutdown,batch [snapshot, shutdown](no step ran), andclose --shutdownwere all denied, both over the socket and over the HTTP transport indualmode. The simulator stayedBootedthroughout.- A caller that named a different policy file got
DAEMON_POLICY_MISMATCHwith adaemon stop --state-dirhint.
- Live check on an Android 37.2 emulator (
emulator-5554, policy pinningserial):deviceslisted only the emulator; the booted iOS simulators were hidden.open --serial emulator-5556was denied withrule: device.open com.android.settingswith no device selected opened on the emulator, andsnapshotworked.shutdown,batch [snapshot, close --shutdown], andclose --shutdownwere all denied. The emulator stayed booted.
- New tests cover the router, parsing, the shutdown host guard, and the reuse check. I disabled each layer in turn (request gate, bind gate, inventory filter, reuse check), and each time its test failed.
- Checks: the
layering,depgraph,agent-guidance,production-exports,fallow, andbundle-owner-filesgates pass locally.pnpm check:unitpassed (11666 unit tests; smoke 71/71 afterpnpm build).pnpm test:integration:providerpassed (217).pnpm typecheck,pnpm lint, andpnpm check:fallow --base origin/mainare clean.
Tradeoffs / follow-ups
- The policy applies to every transport, not only remote requests. Origin markers such as
publicNetworkOnlymust be copied to child requests by hand, so a rule based on origin could leak. A host operator can usesimctl/adbdirectly or a separate--state-dir. - Command rules come from the command registry: public commands by name, internal device commands by the public command they serve (new
catalog.servesPublicCommandtrait) or by their own name, and protocol-only internal commands are never decided. An allow list must nameruntimeforreact-devtoolsand Maestro flows. A name the registry does not know is denied under an allow list. bootis allowed unless the policy denies it. There is no admin route that skips the policy.- The policy is not yet readable over RPC or
/health. Agents learn it from denial errors, and a client connected to a remote daemon cannot verify which policy that daemon enforces. lease_allocatefor a device outside the scope is not refused when it is allocated. The first bind refuses it.- A local takeover (for example, asking for a transport that the daemon does not serve) starts a replacement daemon with the caller's environment. Remote clients cannot trigger takeover. This is documented in the ADR.
- I did not check
test(Maestro) steps directly. They dispatch through the replay port.
25 files touched (6 new). Scope: daemon request admission, runtime binding, the shutdown host capability, daemon client reuse, one command-registry catalog trait (servesPublicCommand), shared daemon-client test helpers, and docs.
Diff size: 25 files changed, 1216 insertions(+), 43 deletions(-), which is over the 1,000-line gross budget in docs/agents/pull-requests.md. Production code is 459+/15- lines (excluding tests); the rest is tests, ADR 0029, and docs.
š¤ Generated with Claude Code