# How to Run Appium Tests Against the Android Emulator in a Cloud VM

> On a large Sandboxer sandbox, boot the Android emulator headless with KVM, install Appium 2 with the UiAutomator2 driver pinned to 4.2.9, and point a Python Appium client at 127.0.0.1:4723. In our run, setup took 72 seconds, the emulator booted in 26, and a Settings test passed in 19.

Source: https://sandboxer.com/guides/run-appium-tests-against-the-android-emulator. Updated 2026-11-25.

**Short answer:** On a large Sandboxer sandbox, boot the Android emulator headless with KVM, install Appium 2 with the UiAutomator2 driver pinned to 4.2.9, and point a Python Appium client at 127.0.0.1:4723. In our run, setup took 72 seconds, the emulator booted in 26, and a Settings test passed in 19.

Part of [Docker, Kubernetes and Nested VMs in a Cloud Sandbox](/guides/docker-and-virtualization-in-a-cloud-sandbox).

**Where Sandboxer fits:** each sandbox is an Ubuntu 24.04 microVM with its own kernel and `/dev/kvm`, so the emulator runs as an accelerated nested VM, and Appium, adb and your test client sit next to it in the same machine ([Machines](/docs/machines)). Plans start at $20/mo ([pricing](/pricing)).

The emulator itself (SDK install, `-accel on`, adb, the streamed desktop, stop and resume) is covered in [Run the Android emulator in a cloud VM](/guides/run-the-android-emulator-in-a-cloud-vm). This page starts where that one stops: Appium on top, one real UI test, and the version trap you hit with Appium 2 today.

## What we measured

One `large` sandbox (8 vCPU, 16 GB RAM) in us-east, 2026-11-25, running the copy-paste block at the end of this page. We used `large` because the emulator's RAM comes out of the sandbox's, as in the emulator guide.

| Step | Time |
| - | - |
| Java, Android command-line tools, emulator, Android 15 `google_apis` x86_64 image, AVD | 56 s |
| Appium 2.19.0, UiAutomator2 driver 4.2.9, Appium Python client 6.1.8 | 16 s |
| Emulator cold boot to `sys.boot_completed=1` | 26 s (emulator log: `Boot completed in 25170 ms`) |
| Test run, first session on a fresh device | 19 s (session start 12.2 s) |
| Test run, later sessions on the same device | 8 s (session start 4.5–4.9 s, in an earlier sandbox the same day) |
| Whole block, `sbx new` to `sbx delete` | 2 min 2 s |

The first session is slower because Appium installs its UiAutomator2 server APKs on the device. Later sessions reuse them.

## The version trap: Appium 2 and the newest UiAutomator2 driver

On 2026-11-25, `npm view` reported Appium `latest` as 4.0.1 and the UiAutomator2 driver `latest` as 10.4.0. With Appium 2 installed, `appium driver install uiautomator2` failed:

```text
Error: ✖ 'uiautomator2' cannot be installed because the server version it requires (^4.0.0-beta.8) does not meet the currently installed one (2.19.0). Please install a compatible server version first.
```

The driver's peer dependency tells you which line still works. Driver 4.x is the last one that accepts Appium 2:

```bash
npm view appium-uiautomator2-driver@4 peerDependencies.appium | tail -1
npm view appium-uiautomator2-driver@5 peerDependencies.appium | tail -1
```

```text
appium-uiautomator2-driver@4.2.9 '^2.4.1 || ^3.0.0-beta.0'
appium-uiautomator2-driver@5.0.7 '^3.0.0-rc.2'
```

So on Appium 2, install `uiautomator2@4.2.9`. If you can move to a newer Appium, follow the [Appium docs](https://appium.io/docs/en/latest/quickstart/) and install the driver without a version.

## Three other things that failed first

- **`npm install -g` as `user`.** Node's global prefix in the sandbox is `/usr`, so a global install without `sudo` doesn't put `appium` on the `PATH` (`appium: command not found`). `npm config set prefix ~/.local` fixes it, since `~/.local/bin` is already on `user`'s `PATH`.
- **`adb: device offline` on the first session.** Our first test, started right after boot, failed during session setup with `Error executing adbExec … adb: device offline`. `adb devices` showed `device` a moment later, and the next run passed. In the clean run below it didn't happen.
- **No wait after a tap.** Looking up the next screen's `Internet` item right after `click()` raised `NoSuchElementException`. `driver.implicitly_wait(10)` fixed it.

## The test

A Python Appium client opens Settings, finds **Network & internet** by its text through a UiAutomator selector, taps it, waits for the next screen, reads its labels and saves a screenshot:

```python
driver = webdriver.Remote("http://127.0.0.1:4723", options=opts)  # appPackage com.android.settings
driver.implicitly_wait(10)
item = driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Network & internet")')
item.click()
driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Internet")')
texts = [e.text for e in driver.find_elements(AppiumBy.CLASS_NAME, "android.widget.TextView")]
driver.save_screenshot("network.png")
```

Appium listens on `127.0.0.1` only, so nothing outside the sandbox can reach it. The full file is in the copy-paste block.

The saved screenshot was a 148,293-byte PNG, 1080 x 2400. It shows the **Network & internet** screen: Internet (AndroidWifi), SIMs, Airplane mode switched off, Hotspot & tethering, Data Saver, VPN and Private DNS.

## Copy-paste: run an Appium test on a fresh emulator

Install the CLI with `curl -fsSL https://sandboxer.com/install | sh` and sign in with `sbx login`. Then paste this. It writes the test file, creates a `large` sandbox with none of your secrets, installs the Android SDK, Appium 2 and the client, boots the emulator, runs the test, copies the screenshot back and deletes the sandbox. It uses `jq` on your machine.

```bash
cat > test_settings.py <<'EOF'
import time
from appium import webdriver
from appium.options.android import UiAutomator2Options
from appium.webdriver.common.appiumby import AppiumBy

opts = UiAutomator2Options()
opts.platform_name = "Android"
opts.device_name = "emulator-5554"
opts.app_package = "com.android.settings"
opts.app_activity = ".Settings"

t0 = time.time()
driver = webdriver.Remote("http://127.0.0.1:4723", options=opts)
print(f"session started in {time.time() - t0:.1f}s")
driver.implicitly_wait(10)
try:
    item = driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Network & internet")')
    print("found:", item.text)
    item.click()
    driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Internet")')
    texts = [e.text for e in driver.find_elements(AppiumBy.CLASS_NAME, "android.widget.TextView")]
    print("next screen shows:", texts[:6])
    print("current activity:", driver.current_activity)
    driver.save_screenshot("network.png")
finally:
    driver.quit()
print(f"test finished in {time.time() - t0:.1f}s")
EOF

id=$(sbx new --name appium-test --type large --no-env --ttl 3600 --json | jq -r 'select(.event=="ready") | .id')
sbx scp test_settings.py "$id":/home/user/test_settings.py

sbx exec "$id" --timeout 600 'set -e; S=$(date +%s)
sudo apt-get update -qq && sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -qq openjdk-17-jre-headless >/dev/null 2>&1
mkdir -p ~/android/cmdline-tools && cd /tmp
curl -fsSLo tools.zip https://dl.google.com/android/repository/commandlinetools-linux-16111833_latest.zip
unzip -q tools.zip && mv cmdline-tools ~/android/cmdline-tools/latest
cat >> ~/.profile <<"EOF"
export ANDROID_HOME=$HOME/android
export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH
EOF
. ~/.profile
yes | sdkmanager --licenses >/dev/null 2>&1 || true
sdkmanager "platform-tools" "emulator" "system-images;android-35;google_apis;x86_64" >/dev/null 2>&1
echo no | avdmanager create avd -n pixel -k "system-images;android-35;google_apis;x86_64" -d pixel_7 >/dev/null
echo "android sdk + image: $(( $(date +%s) - S ))s"; S=$(date +%s)
npm config set prefix ~/.local
npm install -g --silent appium@2 >/dev/null 2>&1
appium driver install uiautomator2@4.2.9 >/dev/null 2>&1
python3 -m venv ~/venv && ~/venv/bin/pip install -q Appium-Python-Client
echo "appium $(appium --version) + uiautomator2 $(appium driver list --installed 2>&1 | grep -o "uiautomator2@[0-9.]*" | cut -d@ -f2) + python client: $(( $(date +%s) - S ))s"'

sbx exec "$id" "adb start-server" >/dev/null 2>&1
sbx exec "$id" --detach "emulator -avd pixel -no-window -no-audio -no-boot-anim -accel on -gpu swiftshader_indirect > ~/emulator.log 2>&1" >/dev/null
sbx exec "$id" --detach "appium --address 127.0.0.1 --port 4723 > ~/appium.log 2>&1" >/dev/null

sbx exec "$id" --timeout 300 'S=$(date +%s); adb wait-for-device
until [ "$(adb shell getprop sys.boot_completed 2>/dev/null | tr -d "\r")" = 1 ]; do sleep 2; done
echo "emulator boot: $(( $(date +%s) - S ))s ($(grep -o "Boot completed in [0-9]* ms" ~/emulator.log))"
until curl -s 127.0.0.1:4723/status >/dev/null; do sleep 1; done
S=$(date +%s); ~/venv/bin/python test_settings.py 2>&1 | grep -v "^ "
echo "test run: $(( $(date +%s) - S ))s"; file network.png'

sbx scp "$id":/home/user/network.png . && ls -l network.png
sbx delete "$id" --yes
sbx info "$id"
```

Our run on 2026-11-25 (trimmed with `…`):

```text
android sdk + image: 56s
appium 2.19.0 + uiautomator2  + python client: 16s
emulator boot: 26s (Boot completed in 25170 ms)
session started in 12.2s
found: Network & internet
next screen shows: ['Internet', 'AndroidWifi', 'SIMs', 'CARD 1', 'Airplane mode', 'Hotspot & tethering']
current activity: .SubSettings
test finished in 18.7s
test run: 19s
network.png: PNG image data, 1080 x 2400, 8-bit/color RGBA, non-interlaced
-rw-r--r-- 1 … 148293 Nov 25 11:11 network.png
{"ok":true,"type":"deletion.operation","operation":{…,"status":"completed","targetId":"sb_a332jllodl"}}
{"event":"error","error":"Sandbox not found","code":"not_found","status":404,…}
```

The driver version after `uiautomator2` came out empty because `appium driver list` colors its output, so the `grep` didn't match. The install itself worked: in an earlier sandbox the same day, `appium driver list --installed` showed `uiautomator2@4.2.9 [installed (npm)]`, and the test above ran through it. The last line confirms the sandbox is gone.

To skip the 72 seconds of setup on every run, save a prepared sandbox as a named snapshot and start each test sandbox from it ([snapshots](/docs/snapshots)). Quit the emulator with `adb emu kill` before you save or stop, as the emulator guide explains.

## FAQ

### Which UiAutomator2 driver version works with Appium 2?

Driver 4.x, whose peer range is `^2.4.1 || ^3.0.0-beta.0`; we used 4.2.9. Drivers 5.0.7, 6.9.3 and 7.6.2 need Appium 3, and on 2026-11-25 the newest, 10.4.0, needed Appium 4.

### Does Appium need a GPU or a display in the sandbox?

No. The emulator ran with `-no-window` and `-gpu swiftshader_indirect`, which renders in software. Sandboxer has no GPUs. Appium drives the device through adb and the UiAutomator2 server.

### Can I run the Appium server outside the sandbox?

Our run kept Appium on `127.0.0.1` inside the sandbox, next to adb and the emulator, and the test ran there too. We didn't test a remote Appium client against a hosted port.

### Can I use JavaScript instead of Python?

Appium has clients for several languages, including WebdriverIO for JavaScript ([Appium docs](https://appium.io/docs/en/latest/ecosystem/clients/)). We ran the Python client only, so the timings above are for Python.

### Why does the first test take longer than the rest?

On a fresh device, Appium installs the UiAutomator2 server APKs before the session starts. Our first session started in 12.2 s; later sessions on the same device started in under 5 s.

## Related

- [Docker, Kubernetes and Nested VMs in a Cloud Sandbox](/guides/docker-and-virtualization-in-a-cloud-sandbox)
- [Run the Android emulator in a cloud VM](/guides/run-the-android-emulator-in-a-cloud-vm)
- [Sandboxes for QA and test automation](/guides/sandboxes-for-qa-and-test-automation)
- [Docker and nested KVM inside an agent sandbox](/guides/docker-and-kvm-inside-an-agent-sandbox)
