Agent Sandboxes, part three: Xcode builds for an agent that can't touch the Mac

claude-code sandboxing xcode ios security agents

Last week’s part two ended with Agent Sandboxes being built by Claude from inside one of its own microVMs. That’s still how it gets built, and the last two days of it have gone on one feature, because one of my projects has grown an iOS app and I ran straight into a wall.

Every one of my agents lives in a Linux sandbox. Xcode lives on a Mac. There is no amount of clever that makes xcodebuild run on Ubuntu.

So what’s the problem?

The quick answers are all a bit grim:

  1. Run the agent on the Mac. That throws away the whole sandbox story, on the machine with the most of my stuff on it.
  2. Give the sandbox SSH to the Mac. Now the agent has a shell on a Mac, which is option one with extra steps.
  3. Hosted CI. Renting someone else’s Macs works, but I’ve got Macs right here, and I’d rather not hand an agent a token for a third party just to compile something.

And an Xcode build is about as far from “just compile this” as you can get. Build phases are shell scripts, Swift packages run their own code at build time, the test target is literally arbitrary code. Whatever builds the project is running whatever the agent wrote, so wherever that happens needs to be disposable.

I want the agent to be able to say “build this commit and show me the screenshot”, and have no way at all to reach the machine that does it.

Git is the queue

Everything here runs on my own kit: the Linux host, the build host and the Macs. Nothing is hosted, and the only outside party that ever gets a credential presented to it is Apple, for signing and TestFlight (more on that below).

There are three parts, and the bit in the middle is my favourite thing in the project right now.

The build host is a plain git user (aiogit) on a Linux box, reached over SSH. There’s no daemon. sshd runs one script, aio-buildd, as the forced command of whichever key connected, and git runs the same script as the repos’ hooks. That’s the whole service.

Git is the record of everything:

  • a job is an annotated tag, build/<id>, and the tag’s message is the job as JSON (action, scheme, project, destination, configuration), checked against a fixed format when it’s pushed
  • a worker claims it by creating refs/claims/<id>, which is create-only, so two workers can’t both win
  • the result is refs/results/<id>, holding the summary, the build log, test results and screenshots

A whole job queue in three refs. No database, no broker, nothing to keep running.

Refs are write-once. No deletes, no force-pushes. Each key gets a role and nothing else; the UI’s key can create job tags and read state, a worker’s key can fetch, claim, send logs and push the result of a job it claimed. A queue with an audit log, built out of things sshd and git already do. I do enjoy it when the boring tools turn out to be enough.

The Mac only dials out

The Mac worker is a LaunchAgent that connects out to the build host and never listens for anything. Per job it:

  1. fetches the commit
  2. clones a fresh macOS VM with Tart (the Cirrus Labs Xcode images work nicely) and shares the checkout in read-only
  3. runs a fixed set of xcodebuild steps for the action: build, test, run (install and launch in the Simulator, then take a screenshot) or archive
  4. pushes the result
  5. deletes the VM

One job, one VM, then it’s gone. Whatever the build scripts got up to goes with it.

So the agent’s build scripts get a VM that exists for one job and then doesn’t. One fun constraint, Apple’s licence allows two macOS VMs per Mac, so max_vms goes all the way up to… 2.

What the agent actually gets

Tick Apple builds on a workspace’s Access tab and the agent gets an MCP server, aio-builds, with apple_build, build_status, build_log, build_result, get_artifact and cancel_build. build_result hands screenshots back as images, so Claude can look at what the Simulator rendered and decide the button’s in the wrong place without me being involved.

It gets there the same way API tokens work everywhere else in Agent Sandboxes; nono’s proxy adds a per-workspace key to the request, and the web UI does the real work on the outside. It copies the commit out of the project into a clean mirror (using git’s upload-pack, never the repo’s own hooks or config, because that repo belongs to the agent), tags it and pushes the tag.

The agent never holds a git credential, or any connection to the build host or the Mac. It also only builds commits, so uncommitted changes don’t go anywhere (worth knowing before you wonder why your fix isn’t in the build).

There’s a Builds tab too, with the same jobs, live logs, screenshots and a form to queue one by hand.

Signing, or “the key that can’t be proxied”

Building is the easy half. Shipping to TestFlight needs two secrets, and they behave very differently.

The App Store Connect API key fits the existing pattern. The .p8 stays in secrets/, and for each request the proxy runs a little script outside the sandbox which signs a short-lived JWT (19 minutes, Apple’s limit is 20) and injects it. The agent sees $ASC_TOKEN, a placeholder. There’s a default-deny list of endpoints on top, so a workspace can be given “TestFlight” without being given the whole API.

The signing identity (the certificate, its private key and the provisioning profiles) doesn’t fit at all. A proxy can swap a token into a header, but it can’t sign a binary on your behalf. So nothing goes into the sandbox, and the agent asks the MCP server to do the signing, one of two ways:

  • export_build, on the Mac. xcodebuild -exportArchive in a fresh VM where no project code runs, optionally uploading straight to TestFlight. The keys travel sealed: each worker has its own RSA key, vouched for by the SSH key I added for it, and the identity is encrypted so only the worker that claimed the job can open it. The build host in the middle carries the blob and can’t read it or swap in a key of its own.
  • sign_ipa, on the Linux host. Re-signs an .ipa with rcodesign, no Mac involved. Quick, and handy for ad-hoc and development builds.

How export_build gets the keys to the Mac. The build host is just the postman.

Being honest about that second one, it means running a signing tool with the real key against an app the agent supplied. The input gets unpacked with checks first (no paths or links out of its folder, caps on size and file count), but for anything heading to the App Store I’d take Apple’s own tools on the Mac every time.

What went wrong on the way

A couple of things worth owning up to.

The UI keeps one long-lived SSH “watch” open to the build host. After I updated the build host, that watch carried on happily running the old aio-buildd, which didn’t know about seal keys, listed <worker>.seal.json as if it were a worker, and never passed any keys on. Signing just quietly didn’t happen. The watch now ends itself when aio-buildd is replaced.

The installers got a guard rail too: install-buildhost now refuses to run on a Mac and points you at install-worker instead.

What it doesn’t do

The Agent Sandboxes allowlist stops at the Linux host. What a build can reach from inside the Tart VM is the Mac’s and Tart’s to decide (there’s a --net-softnet option to keep the VMs off your LAN, and you should use it). It’s Apple silicon only, because Tart is. And it’s two days old, so treat it accordingly!

In other updates

One more commit landed while I was writing this, and it’s nothing to do with Apple. It’s for the problem you get when this stuff works, which is having far too many workspaces open at once.

The sidebar now tells you who needs you. Each workspace gets a spinner while Claude is working, an accent dot when it’s finished or is waiting on you, and a grey dot for output you haven’t looked at yet. The browser tab’s title counts the ones waiting, so you can see it from another window. Under the hood it’s the humble terminal bell; Claude gets Stop and Notification hooks that ring it, and tmux notes when it rang.

Finding things. Hit / to filter by name, folder or #tag, Enter opens the first match. Sort A–Z or by most recent activity, and there’s a compact mode for when the list gets silly.

Tags and groups. Tag a workspace from its header and the sidebar groups by the first tag. Groups collapse, a collapsed group still shows how many inside it are waiting, and you can pin favourites to the top.

A light theme, for those who want one (Auto, Light or Dark, at the foot of the sidebar). The terminals stay dark either way, as is right and proper.

TL;DR

Eleven commits, a bit under five thousand lines, written by Claude in a microVM and applied by me from the Host page as before.

  • Agents in Linux sandboxes can build, test, run, archive, sign and upload Xcode projects.
  • Git over SSH is the queue: jobs are tags, claims and results are write-once refs, no daemon.
  • The Mac connects out only, and every job gets a Tart VM that’s deleted afterwards.
  • The App Store Connect key is signed into a JWT by the proxy. The signing identity is sealed per worker and never enters a sandbox.

The code’s at metahertz/agent-sandboxes, and the README has the set-up steps. Let me know if you get it going on your own Mac, I’d love to hear what breaks.

Happy hacking!

-Matt

← All posts