Mobilebox
Menu
Embed a phoneDocs pages and contents

On this page

Embed a live phone in your app

Show your own users a live Android phone inside your web app, for example a preview of the app your product just built. They watch it, or tap, swipe and type on it, without a Mobilebox account. You get a short-lived iframe URL, signed by us and bound to one phone and one page origin.

A working app with all of this, a preview per end user in one call, Expo and APK builds, signed webhooks and usage per user, is examples/app-builder-preview: two files, no dependencies, about 10 minutes to run.

1. Allow your origins once

Tell Mobilebox which pages may hold the iframe. Up to 20 origins: https://host[:port], https://*.example.com for any subdomain, or http://localhost:port while you develop.

bash
curl -X PUT https://mobilebox.dev/v1/embed/origins \
  -H "Authorization: Bearer $MOBILESANDBOX_API_KEY" -H "Content-Type: application/json" \
  -d '{"origins": ["https://app.example.com", "https://*.preview.example.com"]}'

2. Preview an app in one call

POST /v1/previews does a whole preview: it gets the end user’s phone, puts the app on it, waits until the app is on screen and returns the link.

bash
curl -X POST https://mobilebox.dev/v1/previews \
  -H "Authorization: Bearer $MOBILESANDBOX_API_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"apk_url": "https://builds.example.com/preview.apk", "end_user": "user_42", "origin": "https://app.example.com", "interactive": true}'
json
{
  "phone_id": "ph_…",
  "embed_url": "https://mobilebox.dev/embed?t=e1.ph_…",
  "expires_at": "2026-11-25T10:15:00.000Z",
  "package": "com.example.preview",
  "reused": false,
  "origin": "https://app.example.com",
  "interactive": true
}
  • The app: one of apk_url (an APK or split bundle; from EAS, GitHub Actions or Gradle: Bring your build), expo_url (the exp:// link npx expo start --tunnel prints; the phone gets the Expo Go of the project’s SDK) or ios_app_url (a .zip of the simulator build’s .app, with "platform": "ios").
  • The phone: end_user is your id for the person. Their newest phone of that platform is used again, started if it was parked ("reused": true), else a new one is made with that label. An Android phone gets the 30 Hz display. Without end_user, every call makes a phone.
  • The link: origin, interactive and ttl as for a link to a running phone. iPhones and iPads are view-only.
  • Done means on screen: the call returns once the app is in front on two reads in a row. On production on 25 November, with F-Droid’s Editor APK: 27 s on a new phone, 15 s on a parked one, 5 s on a running one; a big APK adds its download. An Expo SDK 58 project took 41 s on a new phone, Expo Go’s install included. For an Expo link, on screen means Expo Go is in front: a big project’s JavaScript can still be loading for a few seconds.
  • Retries: an Idempotency-Key header returns the same preview for 24 h, even for a retry that arrives while the first call still runs. The same key with other options is a 409 idempotency_conflict. A failed preview keeps no key, so the same key tries again.
  • Webhooks: the phone’s phone.ready, phone.parked, phone.deleted and phone.failed events arrive as for any phone, with its end_user.

Everything that can be refused is refused before a phone is made: the request’s shape, an origin that isn’t on your list (403 origin_not_allowed), interactive on iOS (409 embed_ios_view_only). After that, each stage fails with its own code, plus stage, cause (the underlying error’s code) and phone_id:

CodeStageWhat happened
boot_failed, phone_not_readyphoneNo phone could be started; retry (a booting one is reused)
install_failedinstallThe download, the APK or Expo Go: cause says which, e.g. download_failed, invalid_apk, unsupported_abi, expo_unreachable
open_failedopenThe app didn’t come to the screen within 30 s, usually a crash at start. GET /v1/phones/{id}/apps/{package}/logs has its crash

The phone stays after an install or open failure, so fixing the build and calling again (same end_user) uses it. Park it, or let it park when idle, when your user leaves.

MCP: preview_app takes the same fields (ttl_seconds, idempotency_key) and returns the link and snippet.

3. Put it in your page

html
<iframe src="https://mobilebox.dev/embed?t=e1.ph_…" width="360" height="800" style="border:0" title="Phone preview"></iframe>

The phone’s screen fills the frame at its own aspect ratio. Size the iframe as you like; 360×800 fits a 1080×2400 phone.

Step by step, on a phone you already have

The call above is these steps in one. On a phone your agent already uses, make the link yourself.

A phone with a smooth screen

Create the phone with display_hz: 30: its display runs at 30 Hz instead of 15, so scrolling and animations look smooth in the preview. It gets a preview screen too: 720×1600 at 280 dpi, the same layout as a phone’s 1080×2400 at 420 dpi (apps look the same), which costs the server less to draw; the stream is 360×800.

bash
curl -X POST https://mobilebox.dev/v1/phones \
  -H "Authorization: Bearer $MOBILESANDBOX_API_KEY" -H "Content-Type: application/json" \
  -d '{"display_hz": 30}'

30 Hz costs more of the server while the screen moves, so a server runs a few such phones at once. Past that the phone runs at 15 Hz and the answer has a notice; it is never refused, and its next start gets 30 Hz when there is room. The phone JSON’s display_hz says what it runs at now.

bash
curl -X POST https://mobilebox.dev/v1/phones/$PHONE_ID/embed \
  -H "Authorization: Bearer $MOBILESANDBOX_API_KEY" -H "Content-Type: application/json" \
  -d '{"origin": "https://app.example.com", "interactive": true, "ttl": 900}'

The answer has url, expires_at, origin, interactive and snippet:

json
{
  "url": "https://mobilebox.dev/embed?t=e1.ph_…",
  "expires_at": "2026-11-25T10:15:00.000Z",
  "origin": "https://app.example.com",
  "interactive": true,
  "snippet": "<iframe src=\"https://mobilebox.dev/embed?t=e1.ph_…\" width=\"360\" height=\"800\" style=\"border:0\" title=\"Phone preview\"></iframe>"
}
  • origin is the page that holds the iframe, and must be on your list.
  • interactive defaults to false (view-only). With true, your user’s taps, swipes and typing reach the phone, plus the back, home, enter, delete, recents and tab keys. Never power.
  • ttl is how long the link opens: 60 to 3600 seconds, 900 by default.

Make the link on your server, where your API key lives, and hand only the URL to the browser.

When it ends

The link opens until expires_at. Make a new one before then and swap the iframe’s src. An open embed ends:

  • at expires_at;
  • when the phone parks, stops or is deleted;
  • on DELETE /v1/phones/{id}/embed, which ends every embed link of that phone at once, open ones included. Do this when your user leaves the preview.

The embed tells its parent page, and only the origin it was made for:

js
window.addEventListener('message', (e) => {
  if (e.origin !== 'https://mobilebox.dev') return // with several embeds, e.source says which iframe
  const m = e.data
  if (m?.type === 'mobilebox:live') { /* on screen: m.width × m.height (the phone's pixels), m.interactive */ }
  if (m?.type === 'mobilebox:state') { /* m.state: connecting, reconnecting, paused (your own user is typing on it) */ }
  if (m?.type === 'mobilebox:end') { /* m.reason: make a new link, or show your own fallback */ }
})

End reasons:

ReasonMeaning
expiredPast expires_at
revokedDELETE /v1/phones/{id}/embed
parked, failed, deletedThe phone parked, stopped or was deleted
invalidNot a link we made, or cut short
not_framedOpened as a page of its own
unreachableNo stream for about a minute; the embed offers Try again
unsupportedThe browser has no WebCodecs (e.g. Safari before 16.4)

When the embed isn’t live it keeps the last frame, dimmed, under a short line your user can read. If you see the browser’s own "blocked" page icon inside the iframe, the page’s origin is not the link’s origin.

Keyboard and pointer. On an interactive link, your user taps or clicks; a tap shows a ring at once. A click (or Tab to the preview) lets them type. Enter, Backspace and Escape (Back) go to the phone, and the wheel or a trackpad scrolls it. On a touch screen the phone’s own keyboard comes up. A view-only link never blocks the page from scrolling.

What your users get, and what they don’t

  • One phone’s screen. No other phone, no account, no API key, no billing, no agent captions, no way into Mobilebox.
  • Only your pages can frame it. The browser refuses any other parent: CSP frame-ancestors is exactly the link’s origin. The link opened as a page of its own shows nothing.
  • Short-lived and revocable. A link stops at expires_at, or on DELETE /v1/phones/{id}/embed.
  • Your own user wins. While someone signed in to your workspace has taken control of the phone in the live view (to type a password or a code), embeds pause, and their input is refused with human_in_control.

Treat an embed URL like a short-lived password to that one phone. Whoever holds it can do what the iframe can, until it expires or you revoke it. Keep ttl short for interactive links, and revoke when the session ends.

Billing

An embedded phone is billed as normal phone minutes while it runs. Taps and typing count as activity, so a phone someone plays with doesn’t park while idle; watching alone doesn’t.

MCP

preview_app {apk_url | expo_url | ios_app_url, end_user?, origin, interactive?, ttl_seconds?, platform?, idempotency_key?} does the whole preview; embed_phone {phone_id, origin, interactive?, ttl_seconds?} makes a link for a phone you have. Both return the URL and the snippet. Set the allowed origins with PUT /v1/embed/origins.

iPhone and iPad

An iOS simulator embeds the same way, with the same link, iframe and messages, view-only: your users watch the app live while your agent drives it. "interactive": true on an iOS phone answers 409 embed_ios_view_only; taps and typing in an embed are for Android phones for now. The picture inside the frame is live video on most phones, and still pictures, about one a second, on the rest. A live picture opens only for as long as the embed link, and DELETE /v1/phones/{id}/embed ends it within about 20 s. That also closes your own live views of the phone; they reconnect by themselves. When an iOS preview with live video ends or reconnects, the frame shows the reason on a blank screen rather than over the last picture.

Errors: errors and recovery (origin_not_allowed, embed_link_expired, embed_view_only, embed_ios_view_only, …).

Source: docs/EMBED.md in the repo, rendered at build time.