r/iOSProgramming • u/Adventurous_Clock881 • 2m ago
Discussion I run a full aarch64 Linux VM inside an iOS app, without JIT, so an AI agent gets a real shell
I've been building Pallas Agent, an iOS assistant where the agent loop runs on the phone itself. The models are still in the cloud (ChatGPT sign-in or any OpenAI-compatible endpoint); what runs on the phone is the harness, the tools, and your files.

Models are way better at bash and Python than at any custom tool API I could design, so I wanted the agent to have a real Linux shell on-device.


The stack
Swift/SwiftUI app. The agent harness (a mobile build of the open-source DeepSeek Harness) runs in-process on nodejs-mobile without JIT, behind a loopback port.
The first time the model calls
bash, the appdlopens QEMU 10.0.12-utm (from UTM SE) and boots an aarch64virtmachine in the same process. TCG targets UTM's TCTI (aarch64-tcti) threaded-code backend, turning guest code into chains of addresses of precompiled gadgets. Since the app only ever writes data and never executable memory, it works without a JIT entitlement or a jailbreak.Guest is unmodified Linux 6.12 with an Ubuntu 24.04 arm64 userland, a read-only root, and bubblewrap dropping privileged capabilities (no
SYS_ADMIN,SYS_MODULE,SYS_PTRACE, etc., keeping only basic file/uid caps). The app's workspace is mounted over virtio-9p so files stay in the app's Documents directory.Preinstalled: bash, Python 3.12, Node 24, npm, git, curl, ripgrep, pandas, NumPy, Matplotlib, DuckDB, and Polars.
Numbers (on iPhone, interpreter only)
Cold boot to first command dropped from 28s to 11s by switching to a custom uncompressed initramfs (just the 15 required modules plus 3 optional ones) and precompiling the V8 code cache and
.pycfiles onto a read-only tools disk.After that, launches restore a whole-machine snapshot over QMP in ~1.6s.
Translation is under 5% of the runtime; interpretation is most of it, and for file-heavy workloads 9p round trips take over. Rough ballpark: guest work runs about 4-8x slower than TCG on a Mac.
Things that bit me
Random Rust crashes. This one took a while to track down: ripgrep died in ~45 out of 120 runs. Turned out TCTI's
cmp_vechad the LT/LE and LTU/LEU gadgets swapped, socmlt #0evaluated true for zero lanes and Rust's SwissTableHashMapsilently lost entries. Instead of rebuilding QEMU from scratch, I patched 8 bytes in the prebuilt binary's branch table. Upstream had actually fixed the same bug too (utmapp/qemued597a6).Node 24's
fetchtaking down the whole engine. undici callssocket.setTypeOfService(0)on every new connection. On iOS that returnsEINVALif QEMU's port forward has already reset the connection, and it escaped as an uncaught exception. Switched health checks tonode:http.Passing V8 flags broke the code cache. Even a single non-default flag changes V8's flag hash, which makes Node silently ignore its built-in code cache and noticeably slows down startup.
4 vCPUs ran slower than 2 because the extra two landed on efficiency cores.
iOS reclaims listening sockets when an app is suspended, which silently kills slirp's
hostfwd. Rather than rebooting the guest on resume, the host just re-adds the forward over QMP.
Why not iSH? iSH pioneered this on iOS with user-mode i386 and a reimplemented syscall layer, which is much lighter and has no boot time. I went with full-system aarch64 and a real kernel mainly so official arm64 glibc binaries, namespaces, and bubblewrap work out of the box. Snapshot restore hides most of the boot cost.
The QEMU patch, guest corresponding source, and a longer write-up (including a side-by-side with iSH) are here: https://github.com/deemo0666/pallas-vm
The app: https://github.com/deemo0666/pallas-agent
If you're curious about any part of the QEMU-on-iOS setup, ask away.
