Corral — Exclusive Android Device Leases for Coding Agents
Corral pools the Android devices attached to a host — USB, WiFi and emulators — and leases each
one to exactly one agent session at a time. The failure it prevents is concrete: one session runs
./gradlew connectedAndroidTest while another installs an APK to the same serial, and the run
fails in a way that reads as a flaky test. ANDROID_SERIAL only binds callers that cooperate,
and agents do not. Corral decides at exec time instead.
Use it before any device work: adb shell, adb install, a screenshot, am instrument, a
./gradlew connectedAndroidTest or install* task. Claim or lease first; do not start with
adb devices and grab a serial.
The core loop
The form to prefer queues and holds: the command waits in the FIFO queue, then runs with the
served device leased until it exits.
corral lease --timeout 120 -- ./gradlew connectedAndroidTest
corral lease --timeout 180 --type emulator -- adb install app.apk
--timeout caps the queue wait (max 600 s, clamped with a warning). Omit it and a busy pool
prints a self-teaching line naming the holders and this exact form, then exits 1. Everything
after -- is the command; nothing before it is run as a program. The CLI renews the lease while
the command runs, so the TTL bounds only a CLI that stopped renewing. Selectors compose:
--serial, --model, --os (minimum), --type usb|wifi|emulator, --avd.
For work spanning several commands, claim, use, free:
serial=$(corral claim) # serial alone on stdout
ANDROID_SERIAL=$serial adb shell ...
corral free "$serial"
A claim's TTL is the hold (30 minutes from the CLI) and survives the process that made it; renew
a long session with corral renew <serial>, and run corral free --all in a trap so an
abandoned claim does not block the pool. corral wait is the poll-then-decide form: it prints a
serial and hands the lease back when the wait process exits, so use it only when you must know
which device you would get before deciding.
Read-only commands need no lease: corral devices, corral status, corral queue,
corral owner, corral check, corral doctor.
The gate
Three independent layers enforce the lease on POSIX: an adb wrapper earlier on PATH, an SDK
platform-tools/adb shim for absolute-path calls, and a Gradle init.d gate, because AGP never
runs the adb binary and only a build-level gate can stop its install* and
connected*AndroidTest tasks. A Windows install has two layers — the .bat wrapper and the
Gradle gate — with no SDK adb.exe shim.
A refusal is the gate working, and it prints the way through (corral lease -- <cmd> or
corral claim plus ANDROID_SERIAL). The read-only allowlist is the readonly= line of
~/.config/corral/rules; a missing rules file fails closed and refuses every call. The gate
checks -s <serial> and ANDROID_SERIAL whatever that file says. Identity is self-declared —
this is a rail against accidental collision, not authentication.
Emulators and demo devices
corral avd list|start|stop <avd> manages AVDs. A freshly started AVD joins the pool unbooted
and is not claimable until Android reports boot complete, so pair corral avd start with a
corral lease --timeout … --type emulator -- … ticket that is served at the boot flip.
corral demo starts a second, isolated daemon whose pool is simulated; GET /api/config
returns "demo":true and every demo model ends in (demo). Those leases exercise the plumbing,
not hardware — never run a real build, test or install against a demo serial.
Limits worth knowing
The threat model is cooperating agents. ddmlib clients that talk to the adb server on :5037
directly (Android Studio's Run/deploy, Logcat, Device Explorer) and any adb reached outside the
SDK path by absolute name (adb.real) are documented bypasses. macOS has no installer; Windows
is host-verified on one box. The daemon binds 127.0.0.1 only.
Installation
No source-backed install or usage instructions could be extracted automatically. Review the upstream project before running this skill in a sensitive workflow.
Source