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

# Virtualization: KVM, Firecracker, Android

> Nested virtualization in a sandbox: every sandbox has /dev/kvm, so QEMU/KVM, Firecracker and the Android emulator run at full speed.

Every sandbox has nested virtualization. `/dev/kvm` is there, so QEMU/KVM, Firecracker and the Android emulator run at full speed. You do not need a flag or a permission.

```bash theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
boat exec <id> 'test -e /dev/kvm && echo "KVM available"'
```

## Where your sandbox runs

Every sandbox runs as a full virtual machine on a physical host dedicated to boat. The fleet includes AMD Ryzen 7 9700X and Ryzen 9 9950X hosts. Sandboxes on the same host share CPU time. A sandbox's vCPUs are not dedicated physical cores. CPU virtualization extensions are passed through, and each sandbox has its own kernel.

## Run the Android emulator

This script runs a headless Android emulator. Use `default` or bigger: the emulator needs about 3 GB of RAM. We tested it on a `large` sandbox.

* The install takes about one minute.
* Android 14 then boots in 20 to 30 seconds.

```bash theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
sudo apt-get install -y openjdk-17-jre-headless
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 ANDROID_HOME=$HOME/android
mkdir -p $ANDROID_HOME/cmdline-tools && cd /tmp
curl -fsSLo clt.zip https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip
unzip -q clt.zip -d $ANDROID_HOME/cmdline-tools && mv $ANDROID_HOME/cmdline-tools/cmdline-tools $ANDROID_HOME/cmdline-tools/latest
SDK=$ANDROID_HOME/cmdline-tools/latest/bin
yes | $SDK/sdkmanager --licenses >/dev/null
$SDK/sdkmanager "platform-tools" "emulator" "system-images;android-34;google_apis;x86_64"
echo no | $SDK/avdmanager create avd -n phone -k "system-images;android-34;google_apis;x86_64" -d pixel_6
if [ ! -e /dev/kvm ]; then
  echo "No KVM on this sandbox: the Android emulator cannot start here." >&2
else
  $ANDROID_HOME/emulator/emulator -avd phone -no-window -no-audio -gpu swiftshader_indirect &
  $ANDROID_HOME/platform-tools/adb wait-for-device
fi
```

To take a screenshot, run `adb exec-out screencap -p > screen.png`.


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