Android emulator (preview)
The kosa8-android image runs the Android emulator in a sandbox, for
mobile agents and mobile reinforcement learning. A person can watch or take over the phone through
noVNC in a browser. An agent can drive it with adb from outside the sandbox, or with one-line
commands from an ordinary exec: screenshot, tap, swipe, type, install an APK and dump the UI.
This is a preview, and it has not yet run on a live kosa8 Cloud host.
The emulator needs /dev/kvm inside the sandbox, which is KVM running inside the
sandbox's own microVM (nested virtualization). Only hosts that have it switched on take these
sandboxes. No kosa8 Cloud host has it today, so a create answers 501 not_available
(checked 2026-11-22), and the kosa8-android image has not been published to the registry yet. Expect rough edges
until the live test is done: boot time, sleep, snapshots and forks are all untested.
| Port | What |
|---|---|
| 6080 | noVNC: the phone's screen in a web page (through scrcpy). Open it as a preview URL. |
| 5555 | adb, carried as a WebSocket, for an agent outside the sandbox (kosa8-adb-bridge). |
Inside the image: Debian 13, the Android emulator 37.3.10 with an Android 15 (API 35) Google
APIs x86_64 system image (no Play Store), adb 37.0.3, scrcpy 5.0.1, Xvfb, x11vnc and noVNC with
websockify. Every version and checksum is pinned in images/android/versions.env. The
image is large, about 7 GB unpacked, so the first create on a host takes a while to pull it.
1. Create the sandbox#
Give it at least 4 vCPU and 8 GiB, since the emulator is a whole second machine. The API turns
on kvm for this image by itself, which makes the sandbox persistent and keeps it
from sleeping.
curl -s -X POST https://api.kosa8.com/v1/sandboxes \ -H "Authorization: Bearer $KOSA8_API_KEY" -H 'Content-Type: application/json' \ -d '{"size":"4x8","image":"ghcr.io/azmxai/kosa8-android:35"}' # 202 {"sandbox":{"id":"sbx_…","state":"creating","persistent":true,…}} then running once the image is pulled # 501 {"error":"not_available",…} while no host offers nested KVM
In production, name a dated tag such as 35-20261121.1 instead of the moving
35. "kvm": true asks for /dev/kvm with any other image too,
for another emulator or a nested VM of your own.
2. Start Android#
Booting can take longer than an ordinary exec may run (90 seconds), so start it in the background and ask until it is done:
curl -s -X POST https://api.kosa8.com/v1/sandboxes/sbx_…/exec \ -H "Authorization: Bearer $KOSA8_API_KEY" -H 'Content-Type: application/json' \ -d '{"cmd":["kosa8-android","start"],"background":true}' # 202 {"exec":{"id":"…","state":"running",…}} curl -s https://api.kosa8.com/v1/sandboxes/sbx_…/exec/EXEC_ID -H "Authorization: Bearer $KOSA8_API_KEY" # once it has exited 0, its output ends: android ready: noVNC on :6080, adb (WebSocket) on :5555, device emulator-5556, screen 720x1280
start waits until Android reports it has booted. The first boot is a cold one and
the slowest. A clean kosa8-android stop saves a quick-boot snapshot, so the next start
is faster. Set KOSA8_ANDROID_SCREEN (default 720x1280),
KOSA8_ANDROID_DPI (320) and KOSA8_ANDROID_RAM_MB (3072) in the exec's env to
change the device. kosa8-android status --json reports each part. Running
start again restarts only the parts that have stopped.
Where the sandbox has no usable /dev/kvm, start fails and says why. The
emulator will not run an x86_64 system image without hardware acceleration.
3. Watch it, or take over#
curl -s -X POST https://api.kosa8.com/v1/sandboxes/sbx_…/previews \ -H "Authorization: Bearer $KOSA8_API_KEY" -H 'Content-Type: application/json' \ -d '{"port":6080}' # {"preview":{"url":"https://6080-….<preview domain>/?kosa8_preview=eyJz…",…}}
Open url and press Connect. Clicks and drags become taps and swipes, and typing
goes to the phone. Anyone with the link can use the phone until the link expires. Use
…/previews/6080/rotate to end every link at once.
4. adb from outside the sandbox#
A preview URL carries HTTP and WebSockets, not raw TCP, so port 5555 serves the emulator's adb
as a WebSocket. kosa8-adb-bridge turns it back into a local TCP port for the ordinary
adb client. It is a single Python file using only the standard library: copy it out of the image,
or from images/android/kosa8-adb-bridge in the repository. The device trusts one adb
key, so fetch that key too.
# the key the device trusts, and the bridge script curl -s -X POST https://api.kosa8.com/v1/sandboxes/sbx_…/exec -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d '{"cmd":["kosa8-android","adb-key"]}' | jq -r .stdout > kosa8-adbkey curl -s -X POST https://api.kosa8.com/v1/sandboxes/sbx_…/exec -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d '{"cmd":["cat","/usr/local/bin/kosa8-adb-bridge"]}' | jq -r .stdout > kosa8-adb-bridge # a private preview of port 5555; its host and token curl -s -X POST https://api.kosa8.com/v1/sandboxes/sbx_…/previews -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d '{"port":5555}' # {"preview":{"host":"5555-….<preview domain>","token":"eyJz…",…}} export KOSA8_PREVIEW_TOKEN=eyJz… ADB_VENDOR_KEYS=$PWD/kosa8-adbkey python3 kosa8-adb-bridge https://5555-….<preview domain> & adb connect 127.0.0.1:5555 adb -s 127.0.0.1:5555 shell getprop ro.build.version.release # 15
Tools that speak adb then work as they do on a local emulator: Appium's UiAutomator2 driver,
AndroidWorld-style harnesses, adb install, adb logcat.
Never open port 5555 with "public": true. adb has no login of its
own beyond the key, and on this image it gives a root shell on the phone.
5. Screenshots and input from an exec#
curl -s -X POST https://api.kosa8.com/v1/sandboxes/sbx_…/exec \ -H "Authorization: Bearer $KOSA8_API_KEY" -H 'Content-Type: application/json' \ -d '{"cmd":["kosa8-android","screenshot","--base64"]}' | jq -r .stdout | base64 -d > screen.png
| Command | Does |
|---|---|
kosa8-android screenshot [FILE] [--base64] | A PNG of the phone's screen, saved to FILE (default /tmp/kosa8-android/screen.png), or printed as base64 |
kosa8-android tap X Y | Tap at X,Y in device pixels |
kosa8-android swipe X1 Y1 X2 Y2 [MS] | Swipe from one point to another over MS milliseconds (default 300) |
kosa8-android long-press X Y [MS] | Press and hold (default 800 ms) |
kosa8-android type TEXT | Type into the focused field. Printable ASCII only |
kosa8-android key KEY… | Press keys by name: HOME, BACK, ENTER, APP_SWITCH, or any KEYCODE_ name or number |
kosa8-android install-apk FILE | Install or replace an APK, with its runtime permissions granted. Upload it with the files API first |
kosa8-android open PACKAGE | Launch an app, such as com.android.settings |
kosa8-android ui-dump [FILE] | The screen's view hierarchy from uiautomator, as XML: each element's text, resource id, class and bounds |
kosa8-android size | The screen size, such as 720x1280 |
kosa8-android adb ARGS… | Any adb command against the emulator, such as adb shell am start -a android.intent.action.VIEW -d https://example.com |
A mobile-agent loop maps each action it takes to one exec: a screenshot and a UI dump as the observation, then a tap, swipe, type or key as the action. The UI dump gives element bounds, so an agent can tap an element's centre rather than guess pixels from the screenshot.
How it works, and why it needs a special host#
A kosa8 sandbox is a microVM. The Android emulator is itself a virtual machine, so it needs KVM inside the sandbox's VM. That takes three things:
- The host's KVM must offer nested virtualization (
kvm_amdorkvm_intelwithnested=1). Cloud Hypervisor, kosa8's VMM, then passes the CPU's virtualization feature to the sandbox by default. - The sandbox's guest kernel must include KVM. The standard guest kernel does not, so a host that offers this boots a KVM-enabled build of the same kernel.
- The sandbox's container must reach
/dev/kvm. In this preview, a kvm sandbox gets the same container privileges as a"docker": truesandbox, sokosa8-android startcan make the device node. The microVM stays the isolation boundary, as it does for Docker sandboxes.
A host reports nested_kvm only when an operator has switched it on and its KVM has
nested virtualization. The API places kvm sandboxes only on such hosts.
Limits#
- Preview: not yet run end to end on a kosa8 Cloud host. Boot time under nested virtualization is unmeasured. On bare metal with KVM, a cold boot of this system image usually takes under a minute.
- A kvm sandbox never sleeps (
sleep_after_sis 0), and it is billed while it runs. Saving a VM's memory while a nested guest runs inside it has not been tested. Delete the sandbox when you are done, or stop the emulator and keep it. - Snapshots and forks of a running emulator are untested. Stop the emulator first
(
kosa8-android stop) if you take one. - x86_64 only, with software rendering (SwiftShader). There is no GPU, so 3D-heavy apps and games are slow. Google APIs image: no Play Store, so install apps as APKs.
- The emulator and adb run as the user
android. Commands sent to the sandbox run as root, andkosa8-androidruns adb asandroidfor them. - Egress controls apply to the phone's traffic like any other program's. An allow list that leaves out the sites the apps use will stop them.
Something wrong or missing? Edit this page, or write to contact@kosa8.com.