Mobilebox
Menu

OpenHands on Android: let the agent fix the crash.

OpenHands can test and fix Android apps on a Mobilebox cloud phone. The phones cost $0.01 a minute and were ready for a first screenshot in 1.35 s in our 22 November 2026 benchmark. Add the hosted Mobilebox MCP server to the agent’s mcp_config and it has what that loop needs: it can build your app in its terminal, install the build, open it, read the screen and the crash log with its stack trace, fix the code, check the fix on the phone and push it.

Python, 40 lines, the hosted MCP server and its 19 tools. Android and iPhone over one API.

Run it in three steps.

Your code owns the phone; the agent only drives it.

Read the quickstart
  1. 1

    Get a key

    Sign up with GitHub and create an API key in the dashboard. New workspaces get free credit.

  2. 2

    Install OpenHands

    pip install openhands-sdk openhands-tools

  3. 3

    Run the example

    python agent.py with MOBILESANDBOX_API_KEY and LLM_API_KEY set. It creates a phone, gives the agent one task and deletes the phone, also when the run fails.

The whole example

timeout in mcp_config is in milliseconds: 120 would give each tool call 0.12 s. The key reaches the agent’s terminal as an OpenHands secret, masked in everything the model reads.

python · agent.py
# OpenHands + Mobilebox: an OpenHands agent builds your Android app, runs it on a cloud phone, reads the crash, fixes
# the code, checks the fix on the phone and pushes it. BUILD and APK describe your build; LLM_MODEL picks the model.
#   pip install openhands-sdk openhands-tools
#   cd your-app-repo && MOBILESANDBOX_API_KEY=... LLM_API_KEY=... python agent.py
import json, os, time, urllib.request
from pydantic import SecretStr
from openhands.sdk import LLM, Agent, Conversation, Tool
from openhands.tools.file_editor import FileEditorTool
from openhands.tools.terminal import TerminalTool

API, KEY = 'https://mobilebox.dev', os.environ['MOBILESANDBOX_API_KEY']
BUILD = os.environ.get('BUILD', './gradlew assembleDebug')
APK = os.environ.get('APK', 'app/build/outputs/apk/debug/app-debug.apk')


def phones(method, path=''):  # your code owns the phone: create it, and always delete it
    req = urllib.request.Request(f'{API}/v1/phones{path}', method=method, headers={'Authorization': f'Bearer {KEY}'})
    with urllib.request.urlopen(req, timeout=120) as res:
        return json.loads(res.read() or 'null')


llm = LLM(usage_id='agent', model=os.environ.get('LLM_MODEL', 'anthropic/claude-sonnet-4-5-20250929'),
          api_key=SecretStr(os.environ['LLM_API_KEY']), base_url=os.environ.get('LLM_BASE_URL'))
agent = Agent(llm=llm, tools=[Tool(name=TerminalTool.name), Tool(name=FileEditorTool.name)],
              mcp_config={'mobilebox': {'url': f'{API}/mcp', 'headers': {'Authorization': f'Bearer {KEY}'},
                                        'timeout': 120_000}})  # milliseconds, not seconds

t0 = time.time()
phone = phones('POST', '?wait=ready')['id']
try:
    conversation = Conversation(agent=agent, workspace=os.getcwd())
    # The terminal gets the key as $MOBILESANDBOX_API_KEY for uploads; OpenHands masks it in all output. It types the
    # export into its shell, so keep that shell's history off disk.
    os.environ['HISTFILE'] = '/dev/null'
    conversation.update_secrets({'MOBILESANDBOX_API_KEY': KEY})
    conversation.send_message(
        f'The app in this repo crashes. Fix it and prove the fix on the Android cloud phone {phone}. '
        f'Build with `{BUILD}`. Install the build with: curl -fsS -H "Authorization: Bearer $MOBILESANDBOX_API_KEY" '
        f'--data-binary @{APK} {API}/v1/phones/{phone}/apps . Then use the Mobilebox tools: act with open_app '
        'to start it and read the screen, app_logs for the crash and its stack trace. Fix the code, rebuild, '
        'reinstall and check on the phone that the crash is gone, then commit and git push. Report the crash, '
        "the fix and what the screen shows now. Don't create or delete phones.")
    conversation.run()
finally:
    phones('DELETE', f'/{phone}')
    print(f'phone {phone} deleted after {time.time() - t0:.0f} s')

What we checked on production on 23 November 2026: OpenHands’ own MCP client listed the 19 tools and ran create_phone, act and delete_phone, and this example ran its whole loop with a scripted stand-in choosing each call, ending on “Build 2 works” in 17 s. The agent loop has not been run with a real model yet, and the phone was deleted.

Questions

Before you wire OpenHands to a phone.

What did the run on production do, step by step?

A scripted stand-in chose each call, so this shows the tools and timings, not a model’s judgement. On a test app that crashed on start: build and install 2.9 s, open it 3.2 s (2.5 s of that a wait), read the crash log 0.2 s (NumberFormatException at Main.java:13), fix the line, rebuild and reinstall 2.5 s, open it again 3.6 s (“Build 2 works”), commit and push 0.2 s. 17 s from the first step to the report, 15 s of phone time.

How do I add Mobilebox in the OpenHands app?

In Agent Canvas open Customize > MCP Servers, then Add custom server: type SHTTP, URL https://mobilebox.dev/mcp, Authentication Bearer token with your Mobilebox key, timeout 120 seconds. Test connection should report 19 tools.

Why does the agent upload with curl instead of install_app?

install_app takes a link the phone can download. A build the agent just made has no link yet, so it uploads the APK over REST: POST /v1/phones/{id}/apps with the file as the body. When CI publishes the build, pass its URL to install_app instead.

Which models can drive it?

Any model OpenHands reaches through LiteLLM. LLM_MODEL takes a provider/model id; LLM_BASE_URL points it at an OpenAI-compatible endpoint. We have not run the loop with a real model yet; our run used a scripted stand-in, and OpenHands, its terminal and editor, the build and the phone were real.

Can the agent install my app?

Yes. install_app takes a public APK or split-bundle URL, or your code uploads the file over REST; then the agent opens it with {"type":"open_app","package":…}. See installing APKs and split bundles, and app automation for the whole run.

Does the agent stay signed in between runs?

Yes, if you park the phone instead of deleting it: its apps, data and logins wait for the next run, and a parked phone is free. The app’s own session can still expire. See park and resume.

Does it work on iPhone?

Yes. Create the phone with platform: "ios" and the agent uses the same tools. See iPhone and iPad.

What does a run like this cost?

A ready phone costs $0.01 a minute, billed per second with a one-minute minimum; boot time and parked phones are free, so a run like the one above costs about a cent. See pricing.

Read more

Using another framework? OpenAI Agents SDK, LangGraph, CrewAI, browser-use, Mastra, Vercel AI SDK, Claude Agent SDK, or all integrations.

Next questions