> ## Documentation Index
> Fetch the complete documentation index at: https://www.agent37.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Host an Android phone

> Run an Android 14 emulator with hardware acceleration, ADB, screenshots, persistent phone storage, and a live screen in the browser.

The `agent37-android` [template](https://www.agent37.com/docs/agents-api/templates.md) gives your code an Android 14 emulator with the SDK, ADB, and a live screen in the browser. The image starts the emulator automatically; wait for Android to finish booting before sending it work. This template has no chat API.

It only runs as a [VM instance](https://www.agent37.com/docs/agents-api/vm-instances.md). The emulator needs hardware virtualization (`/dev/kvm`), which a VM has and a sandbox does not, so a create without `"type": "vm"` or `"type": "performance"` is a `400`.

```text title="Paste this into your coding agent" wrap theme={null}
Read https://www.agent37.com/docs/llms-full.txt.
I want an Android phone I can drive with adb.
Create it with POST /v1/instances using the agent37-android template, with "type": "vm" and 4 vCPU / 8 GB / 20 GB disk.
Then run `android-wait` through POST /v1/instances/{id}/exec until it reports the boot completed, and show me `adb shell getprop ro.build.version.release`.
Run `android-shot` through exec and decode its stdout as a base64 WebP screenshot; check exit_code and truncated on every exec response.
Finish by minting a signed URL for port 6901 so I can watch the screen.
My key is in AGENT37_API_KEY.
```

## Create one

```bash curl theme={null}
curl -X POST https://api.agent37.com/v1/instances \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "template": "agent37-android",
    "type": "vm",
    "resources": { "cpu": 4, "memory": 8, "disk": 20 }
  }'
```

Omitting `resources` selects 4 vCPU / 8 GB RAM / 12 GB disk, and 8 GB RAM is the smallest size: a phone reloads its saved state on every start, which a smaller one cannot fit. The example requests 20 GB disk for more storage. Size CPU and RAM against your actual apps and sustained automation workload; a successful boot does not establish that a shape is large enough for every app.

The create returns as soon as the machine has started. Android is still booting at that point. The AVD is created on first boot; later boots reuse it and can use an emulator quick-boot snapshot when one is available. Wait after every start with the image's own helper, which blocks until Android reports `sys.boot_completed`:

```bash curl theme={null}
curl -X POST https://sandbox.agent37.app/v1/instances/ab12cd34ef/exec \
  -H "X-Agent37-Key: sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "command": "android-wait 600" }'
```

`android-wait` checks Android boot, not the readiness of a particular app or its first frame.
Launch your target app before capturing it, for example with
`adb shell am start -W -a android.settings.SETTINGS`. If the display is asleep, send
`adb shell input keyevent KEYCODE_WAKEUP` and `adb shell wm dismiss-keyguard` first.

## Drive it with ADB

ADB is already connected to the phone, so [exec](https://www.agent37.com/docs/agents-api/exec.md) is all you need. Nothing has to be exposed to the internet for your code to drive the device.

```bash curl theme={null}
curl -X POST https://sandbox.agent37.app/v1/instances/ab12cd34ef/exec \
  -H "X-Agent37-Key: sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "command": "adb shell am start -a android.intent.action.VIEW -d https://example.com" }'
```

The commands a device-driving agent leans on:

| | |
| - | - |
| `android-shot` | A base64 WebP screenshot, scaled to 540 pixels wide for the JSON exec response |
| `adb exec-out screencap -p` | A full-resolution PNG; transfer binary output over SSH |
| `adb emu screenrecord screenshot /tmp/shots` | A full-resolution PNG written into that folder (create it first) in about 0.1 s, several times faster than `screencap` |
| `adb shell input tap 540 1200` | A touch; `input text`, `input swipe` and `input keyevent` are the rest of the loop |
| `adb shell uiautomator dump` | The view tree, when you would rather act on element bounds than on pixels |
| `adb install app.apk` | Sideload an app; `adb shell pm list packages` lists what is installed |
| `adb logcat -d -t 200` | The last 200 log lines |
| `adb shell dumpsys window \| grep mCurrentFocus` | Which app and activity is in front |

[SSH](https://www.agent37.com/docs/agents-api/ssh.md) works too, and is the better way in when you want `adb pull` of something big or an interactive shell: `ssh root@ab12cd34ef.agent37.app`.

### Screenshots through the API

```bash curl theme={null}
curl -X POST https://sandbox.agent37.app/v1/instances/ab12cd34ef/exec \
  -H "X-Agent37-Key: sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "command": "android-shot" }'
```

Decode `stdout` from base64 into a WebP image. Check `exit_code: 0` and `truncated: false`
before decoding. Exec returns text and caps each output stream at 512 KB, so raw PNG bytes
cannot be returned directly in its JSON response. `android-shot 360` requests a smaller frame.

## Watch the screen

The screen is served on port `6901` by [noVNC](https://novnc.com), so any browser can open it with no plugin and no client. Mint a [signed URL](https://www.agent37.com/docs/agents-api/urls.md) and point it at noVNC's own page:

```bash curl theme={null}
curl -X POST https://api.agent37.com/v1/instances/ab12cd34ef/signed-url \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "port": 6901, "ttl_seconds": 300 }'
# -> { "url": "https://ab12cd34ef-6901.agent37.app/?a37_token=...", ... }
```

Keep the token and change the path to `/vnc.html`:

```
https://ab12cd34ef-6901.agent37.app/vnc.html?a37_token=...&autoconnect=1&resize=scale
```

Add `&view_only=1` to watch without touching. The URL is a credential: anyone holding it can tap and type on the phone, so mint a short one and hand it only to the device's owner. To embed the screen in your own app rather than open a tab, mount the noVNC client in your page and connect its WebSocket straight to the instance; [Hermes with a desktop](https://www.agent37.com/docs/agents-api/hermes-desktop.md) has the code, and it applies here unchanged.

noVNC is what the template ships because it needs nothing installed and rides the same authenticated edge as every other port. For a smoother picture, run [ws-scrcpy](https://github.com/NetrisTV/ws-scrcpy) on the instance and serve it on its own port: it streams H.264 over a WebSocket and the browser decodes it with WebCodecs. The native [scrcpy](https://github.com/Genymobile/scrcpy) client is better still, over an SSH tunnel to ADB (`agent37 ssh ab12cd34ef -- -L 5037:localhost:5037`). The emulator's own WebRTC stream needs UDP, which the Agent37 edge does not carry.

## What is on the image

| | |
| - | - |
| Android | 14 (API 34), `google_apis` x86\_64, as an AVD named `agent37` on a Pixel 6 profile |
| SDK | `platform-tools` (ADB), `emulator`, `cmdline-tools` at `/opt/android-sdk` |
| Screen | Xvfb, x11vnc, and noVNC on `6901` |

`google_apis` includes Google Play services and supports `adb root`. It does not include the Play Store app. Sideload with `adb install` and test the apps and login flows your product needs. For the Play Store or another Android version, build [your own image](https://www.agent37.com/docs/agents-api/custom-image.md) from the [Android Dockerfile](https://github.com/agent37-platform/templates/tree/main/images/vm/android), selecting the SDK package with its `SYSTEM_IMAGE` build argument. Changing versions also needs a matching AVD; installing an SDK package alone does not change the existing phone.

What the phone stores (apps, logins, files, the quick-boot snapshot) lives in the AVD on the instance's persistent disk, so it survives stop, start, restart, resize and [image updates](https://www.agent37.com/docs/agents-api/instances/update.md). The SDK itself is in the image and costs nothing against your disk.

Environment knobs, as [instance env](https://www.agent37.com/docs/agents-api/instance-environment.md): `ANDROID_AVD_RAM_MB` (default `2048`), `ANDROID_AVD_DATA_MB` (phone storage, automatically sized from free disk with a 1536 MB floor and 6144 MB cap), `ANDROID_AVD_DEVICE` (default `pixel_6`), `ANDROID_SCREEN_GEOMETRY` (default `560x1000x24`, sized to the window the emulator draws) and `ANDROID_EMULATOR_ARGS` for additional emulator flags. RAM, phone storage, and device profile are set when the AVD is first created; changing these env values does not resize or replace an existing phone.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.