Skip to content
karagöz docs
Star4npm0.5.1

Let an AI agent drive a real iPhone

What an iPhone needs before an AI agent can read its screen and tap on it through Karagöz, and how to install Karagöz's runner.

Karagöz reads an iPhone’s screen and sends it input through its runner. The runner is a small XCUITest bundle that karagoz install-runner builds with your Apple team and installs on the phone. Karagöz reaches it over the USB cable. An agent then uses the same commands, output and error codes on the iPhone as on an emulator.

  • A Mac with Xcode 15 or newer, and Xcode 27 or newer for screenshot.
  • The iPhone paired with the Mac, with Developer Mode on: Settings > Privacy & Security > Developer Mode. devices does not list iPhones on iOS 16 and older.
  • For reading the screen and input: a USB cable, and Settings > Developer > Enable UI Automation on. Karagöz does not support an iPhone on Wi-Fi only.
  • To build the runner: an Apple ID signed in to Xcode > Settings > Accounts. Xcode saves the account’s team once you open a project’s Signing & Capabilities tab.
  • Karagöz on the Mac: Install.
~/app
karagoz install-runner

install-runner picks the team from --team, else the teams Xcode saved: the only one, else the only paid one. It builds the runner with xcodebuild and automatic signing, then installs it with devicectl. When your keychain has no development certificate, Xcode creates one. It also registers the iPhone on your developer account. Both stay on your Mac and account.

  • The first build needs the network: Xcode talks to Apple’s developer service.
  • With more than one device listed, name the iPhone with --device <UDID or model>.
  • Run it again after updating Karagöz or Xcode, and for another iPhone.
  • A free Apple ID (Personal Team) also signs the runner; this is untested. Its profile lasts 7 days, so you run install-runner again every week. The phone asks once to trust the developer: Settings > General > VPN & Device Management, which needs internet.

The MCP tool is install_runner.

For more information, see install-runner.

karagoz mcp serves the same commands to an AI agent as tools. MCP server has the setup for each client.

When nothing answers, ui-tree, tap or another input command starts the runner with xcodebuild test-without-building. It stays up between calls and stops itself after 10 minutes without a read or an input.

With a passcode set, the phone shows “Enter iPhone Passcode for XCTest” when the runner starts. It asks the first time after a restart, about once a day, and the first time after the phone was locked. xcodebuild does not report it, so the call waits up to 60 s and returns DEVICE_NOT_READY, whose message says to look at the iPhone. Enter the passcode on the phone and run the command again.

For more information, see ui-tree.

How Karagöz reaches and secures the runner
  • The runner listens on 127.0.0.1 port 27753 on the phone. Karagöz reaches it over the USB cable through macOS’s usbmuxd, so nothing on the phone’s network can.
  • Other apps on the phone can reach that port, so each start gives the runner a new secret, kept in ~/Library/Caches/karagoz/runner/<UDID>.token (mode 0600).
  • Every request and every answer carries an HMAC-SHA256 under that secret, so the secret never crosses the connection, and the runner refuses anything unsigned.
  • Karagöz leaves no daemon behind: the only process is the xcodebuild that started the runner, and it exits with the runner.
  • RUNNER_NOT_INSTALLED: no runner Karagöz can use. Run install-runner again. Any of these causes it:
    • None is installed.
    • The installed one was built by another Karagöz or Xcode, or its build on this Mac was deleted.
    • Its profile does not include this iPhone, or has expired.
    • A runner from an older Karagöz is still answering.
  • DEVICE_NOT_READY: the message says what to do.
    • For install-runner: the iPhone is not paired, has Developer Mode off, or is locked.
    • For a read or an input: the iPhone is not connected by USB cable, is locked, or does not trust the runner’s developer yet.
    • The runner did not start within 60 s: look at the phone for the passcode prompt, and check Settings > Developer > Enable UI Automation.
    • Something else answers on the runner’s port without this Mac’s key, or another app holds that port.
  • HELPER_FAILED: the message says which and what to do.
    • For install-runner: no Xcode, no Apple account or team in Xcode, or a failed build, with xcodebuild’s error lines and the log path.
    • For a read or an input: the selected Xcode has no xcodebuild, xcodebuild could not start the runner for a reason Karagöz does not know, or this iOS changed an interface the runner uses (update Karagöz).
    • For an input: an event the runner could not play, no answer within 30 s plus the gesture or typing time, or a runner that closed the connection. A call that waits more than 8 s behind another fails the same way.
  • NOT_SUPPORTED: install-runner picked a simulator or an Android device, device <id> is not an iPhone; karagoz's runner runs only on iPhones. Its --device takes an iPhone’s UDID or model.