Automation API
Control a running VM from scripts over HTTP and WebSocket. Use this page to turn the API on, authenticate, and make your first calls; the full API reference lists every route and method.
Turn it on
Add --api-listen when you launch the VM:
After the VM starts, vphone-vm prints the address and a token:
- Without
--api-listenthere is no host listener. - Port
0asks macOS for a free port; the actual address is printed after the VM starts. --api-listenis unavailable with--dfu.
vphoned runs as root, and the API can read and write any guest file, list the keychain and load launch daemons. For local-only use, listen on 127.0.0.1 or [::1]. Any other address prints a warning: every machine that can reach it needs only the token, which travels in clear text over plain HTTP, so use it only on a trusted network.
The token
The token is new for each launch: 32 random bytes, in hex. To use a fixed token, set VPHONE_API_TOKEN before launching; vphone-cli vm launch passes its environment through to vphone-vm. The value must be 16 to 256 characters of A-Z a-z 0-9 - . _ ~; any other non-empty value stops the launch.
Send the token in any of these forms:
A missing or wrong token gets 401 Unauthorized, and the connection closes before anything reaches the guest.
Example calls
Rules that trip up hand-written clients:
- Every
POSTmust sendContent-Type: application/json, or it gets415. - A request with an
Originheader, or with aHostother thanvphoned,localhost,127.0.0.1or::1, gets403. This blocks browser pages from reaching the API. GETroutes only read. To change a setting, usePUTorPOST, for examplePUT /v1/low-power-modewith{"enabled": true}.
Swift apps can use the VPhoneAPIClient in the VPhoneExternalAccessKit library, which sends the token for you; see the reference for an example.
Without a network listener
The VM's control socket accepts the same methods without the API listener: send {"t":"rpc","method":"<method>","params":{}} as one JSON line. See Control socket.