# Move a Hosted Mac Agent Without Losing Its State

Canonical: https://figment.so/blog/mac-agent-exit-migration

Drain the old Mac, export configuration without secrets, rotate every secret, re-register the runner on the new Mac, and hold the old one for 24 to 48 hours. A like-for-like Intel agent moves to a Figment Intel Mac VM ($25 a month).

Move a hosted Mac agent with five phases: drain the old machine, export configuration without secrets, stand up the new machine blocked, re-register the CI runner, then smoke test, cut over and hold the old machine for rollback. The risk sits in the seam between "old machine drained" and "new machine accepting work", and the explicit drain, the secret-free export and the hold window close that seam. A like-for-like Intel agent (CI runner, API poller or launchd job) moves to Figment's Intel Mac VM at $25 a month.

## Which Figment plan should the agent move to?

Pick the plan that matches the old machine's workload, not the cheapest one by default.

| Scenario | Plan | Month | Day | Hour |
|---|---|---:|---:|---:|
| Like-for-like Intel toolchain, launchd agents, scripts | [Intel Mac VM](/mac-hosting#intel-vm) (4 shared vCPUs, 4GB, 80GB, macOS Sequoia) | $25 | $2 | $0.15 |
| arm64-only binaries, Xcode 26.4 or later | [Apple Silicon Mac VM](/mac-hosting#apple-silicon-vm) (4 shared vCPUs, 4GB, 65GB) | $39 | $6 | $0.40 |
| Heavy builds, or an agent that should own the whole Mac | [Dedicated M4 Pro 48 GB](/mac-hosting#dedicated-m4-pro) (M4 Pro, 48GB, 512GB) | $349 | Monthly only | Monthly only |

The Intel VM runs compatible Intel Mac toolchains, including [Xcode 26.0 to 26.3 on macOS Sequoia](https://developer.apple.com/documentation/apple-silicon/porting-your-macos-apps-to-apple-silicon), and can cross-compile and sign supported arm64 device apps and universal macOS binaries. It cannot execute arm64-only binaries, Xcode 26.4 or later, or visionOS tooling. VM vCPUs are shared, not reserved cores. Every plan gives you administrator access to your own Mac or VM. The Intel Mac VM and the Dedicated M4 Pro include SSH, encrypted remote desktop and browser access; the Apple Silicon Mac VM has the browser desktop and SSH.

## What does Apple silicon cost compared with CloudMac?

If your job genuinely needs Apple silicon, compare like with like. [CloudMac](https://cloudmac.org/pricing) lists M4/16 GB/256 GB at $99.99 a month, and [cloudmac.org](https://cloudmac.org/) advertises a $999 a year option, which is $83.25 effective monthly. Figment's Apple Silicon Mac VM costs 12 × $39 = $468 a year, but it is a VM with shared vCPUs and has 4GB of memory, while CloudMac's listing is a whole M4 with 16GB. Figment's Dedicated M4 Pro 48 GB costs $3,228 for a year paid up front and is a bigger whole Mac (M4 Pro, 48GB, 512GB). CloudMac's 512 GB and 1 TB rows are currently marked "Fully reserved, Next allocation not scheduled". If Apple silicon is a nice-to-have and the Intel toolchain is fine, the $25 Intel VM is the cheapest valid target by a wide margin.

## What should I separate before I move?

Treat the agent as three things and move each differently:

| Category | Contents | Transfer method |
|---|---|---|
| Configuration | launchd plists, scripts, cron entries, environment variable **names** | Source control or secure file transfer |
| Secrets | API keys, tokens, signing identity, Developer ID private keys | Retrieve fresh from your secret manager on the new host; rotate at source |
| State | Job state files, checkpoints, artifact cache | Copy explicitly and validate against a known-good reference |

Never dump the live environment to a plaintext file, because `printenv` output contains anything your shell has loaded. Export the list of variable names your agent requires, then re-inject values from your CI or password manager on the new host. Signing identities belong in an encrypted p12 (private key included) handled by your secrets system, not copied out of Keychain as bare files. Provisioning profiles are regular files on disk and should be re-downloaded from Apple Developer, not "exported" from Keychain.

You need admin on your CI service to issue a new runner registration token and remove the old runner, access to your secret manager to retrieve and rotate credentials, and permission to update your own firewall, artifact store or CI allowlists if any of them pin the old machine's egress IP.

## How do I drain the old machine?

Set a drain flag, let in-flight work finish, and take the runner offline.

```bash
touch ~/agent/.drain                 # your wrapper refuses new jobs if present
tail -F /tmp/agentjob.log            # watch in-flight work finish
launchctl list | grep com.yourteam.agentjob   # PID column shows "-" when idle
```

Mark the runner offline in your CI UI and tell upstream schedulers (cron orchestrators, webhook dispatchers) that this host is going away.

## How do I export configuration without secrets?

Copy scripts, plists, named state and a Brewfile, and record only the names of the variables the agent needs.

```bash
#!/usr/bin/env bash
set -euo pipefail
umask 077
OUT="$HOME/agent-export-$(date -u +%Y%m%dT%H%M%SZ)"
mkdir -p "$OUT"/{launchd,scripts,state,env-names}

cp ~/Library/LaunchAgents/com.yourteam.agentjob.plist "$OUT/launchd/"
cp /usr/local/bin/run-agent-job.sh /usr/local/bin/reconcile-job.sh "$OUT/scripts/"

# State you intentionally carry across
[ -f ~/agent/job.state ] && cp ~/agent/job.state "$OUT/state/"
[ -d ~/agent/checkpoint-latest ] && cp -R ~/agent/checkpoint-latest "$OUT/state/"

# NAMES ONLY: values stay in your secret manager
grep -oE '\$\{?[A-Z_][A-Z0-9_]*' /usr/local/bin/run-agent-job.sh \
  | tr -d '${' | sort -u > "$OUT/env-names/required.txt"

brew bundle dump --file="$OUT/Brewfile" --describe --force
echo "Wrote $OUT. Transfer over an encrypted channel."
```

This script is an illustrative example, not a benchmark. Adapt variable discovery to how your scripts actually reference secrets. Do this before you delete the old Mac: when you stop a Figment Mac, access stops. A stopped Mac is kept free for 24 hours. After that, storage costs a quarter of the plan's daily price for each day, until you delete the Mac.

## How do I set up the new machine without letting it take work?

Create the drain flag first, so the new machine starts blocked, then install tools, scripts and plists.

```bash
mkdir -p ~/agent && touch ~/agent/.drain   # start blocked

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew bundle install --file=/path/to/agent-export/Brewfile

install -m 0755 /path/to/agent-export/scripts/*.sh /usr/local/bin/
cp /path/to/agent-export/launchd/*.plist ~/Library/LaunchAgents/

# Inject secrets from your manager, one per required.txt line
# e.g. export API_KEY="$(op read 'op://CI/agent/api-key')"

cp /path/to/agent-export/state/job.state ~/agent/
```

## How do I re-register the CI runner?

Remove the old runner and register the new one with a fresh token. For a GitHub Actions self-hosted runner, follow the current docs on [removing runners](https://docs.github.com/en/actions/how-tos/manage-runners/self-hosted-runners/remove-runners) and [hardening self-hosted runners](https://docs.github.com/en/actions/reference/security/secure-use#hardening-for-self-hosted-runners).

On the old machine (or in the repository or organization Settings → Actions → Runners UI):

```bash
./config.sh remove --token OLD_REMOVAL_TOKEN
```

On the new machine, with a fresh registration token:

```bash
./config.sh --url https://github.com/YOUR_ORG/YOUR_REPO \
            --token NEW_REGISTRATION_TOKEN \
            --name figment-mac-agent-v2 \
            --labels mac,automation
./svc.sh install && ./svc.sh start
```

GitHub automatically removes a persistent self-hosted runner that has not connected for more than 14 days, and an ephemeral runner after 1 day. The explicit removal step is a cleanup courtesy inside those windows, and required outside them.

## How do I cut over and keep a way back?

Smoke test, remove the drain flag, redirect triggers, and keep the old machine drained but reachable.

```bash
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.yourteam.agentjob.plist
shortcuts run "AgentSmokeTest"       # see support.apple.com shortcuts CLI guide
# Confirm runner shows Online in the CI UI, then:
rm -f ~/agent/.drain
```

Redirect upstream triggers (cron, webhooks, dispatcher config) to the new host. Keep the old machine drained but reachable for 24 to 48 hours for rollback, then decommission.

## What must be true before I call the move done?

Tick every item:

```
EXPORT
  [ ] Drain flag set; in-flight job finished; log quiet
  [ ] CI runner shows Offline in service UI
  [ ] Upstream schedulers / webhook senders notified
  [ ] Export directory contains launchd, scripts, state, Brewfile, required.txt
  [ ] No secret values present (grep export dir for known key prefixes)

NEW MACHINE
  [ ] Homebrew installed; brew bundle check exits 0
  [ ] Scripts installed with mode 0755
  [ ] launchd plists present under ~/Library/LaunchAgents
  [ ] Secrets pulled fresh from secret manager AND rotated at source
  [ ] job.state restored and matches last good checkpoint

REGISTRATION
  [ ] Old runner removed (or within auto-removal window)
  [ ] New runner registered with fresh token and expected labels
  [ ] New runner shows Online before traffic shift

CUTOVER
  [ ] Smoke test passed end to end
  [ ] Drain flag removed on new machine
  [ ] Upstream triggers redirected
  [ ] Old machine drained, reachable, monitored 24-48 h

DECOMMISSION
  [ ] No rollback events during hold
  [ ] Old launchd agents bootout'd; service uninstalled
  [ ] Old rental cancelled or repurposed
```

## What can go wrong, and how do I recover?

Match the symptom:

| Failure | Symptom | Recovery |
|---|---|---|
| Missing secret on new host | Auth error on first real job | Pull from secret manager; never copy from old host |
| Tool version drift | Unexpected output, crash | `brew list --versions <formula>`; pin and reinstall |
| Runner stays offline | No jobs dispatched after cutover | Check `./svc.sh status` and `launchctl print gui/$(id -u)/...` |
| State divergence | New host replays or skips work | Compare `job.state` with upstream; replay only verified clean checkpoints |
| Hard failure on new host | Jobs failing within hold window | Reinstate old machine: `rm ~/agent/.drain`, re-point triggers |

## What does the overlap cost?

You pay for both machines while they overlap: a drained or shut-down Mac still bills until you stop it in Figment or cancel its monthly plan. Use the plan units to keep the overlap short. A rehearsal on a daily plan costs $2 a day on the Intel VM or $6 a day on the Apple Silicon VM, and an hourly Mac bills its first hour at the order, then by the minute. A monthly plan renews on the payment date until you cancel, and cancelling stops renewal while access runs to the end of the paid period. Your first Figment purchase is at least $25 of account credit that pays for usage. Unused credit does not expire and is not refundable. If you need several Macs, Figment quotes enterprise plans on a call.

Keep the old machine running until the hold window closes, and keep your own copy of the exported configuration. Figment does not back up your Mac, so the export is the copy you rely on.

## Where do I start the move?

Pick the target plan on the [Mac hosting page](/mac-hosting), then work through the five phases above.

**Related guides:**
- [Mac agent artifact delivery](/blog/mac-agent-artifact-delivery)
- [Mac agent signed webhooks](/blog/mac-agent-signed-webhooks)
- [Mac GitHub Actions self-hosted runner](/blog/mac-github-actions-self-hosted-runner)
