Mac hosting guide

Rotate Agent API Keys on a Hosted Mac Safely

Issue the new key, test it, switch the agent to it, wait out a rollback window, then revoke the old key. A Figment Intel Mac VM ($25 a month) has the Keychain, `security` and launchd you need.

Figment editorial teamPublished Updated Facts checked November 10, 2026

Figment Mac plans

US East. Pay before use. Hourly and daily too.

Intel Mac VM4 shared vCPUs, 4GB RAM, 80GB SSD$25per monthApple Silicon Mac VM4 shared vCPUs, 4GB RAM, 65GB SSD$39per monthDedicated M4 Pro12-core CPU, 24GB RAM, 512GB SSD$199per month

Minimum first purchase: $25 of account credit, used for your rental.

Rotate an agent API key in stages: issue the new key, store it in the Keychain, smoke test it, point the agent at it, wait out a rollback window, and only then revoke the old key. A rotation that breaks the running agent is worse than no rotation, and this order keeps the old key alive until the new one has proven itself. A Figment Intel Mac VM ($25 a month) has everything the work needs.

Which Figment Mac plan do I need to manage agent keys?

The Intel Mac VM is enough for credential work and scripting: 4 shared vCPUs, 4GB of RAM and an 80GB SSD on macOS Sequoia, at $25 a month, $2 a day or $0.15 an hour. It runs real macOS, so the security command, the login Keychain and launchd all work. You get SSH, encrypted remote desktop and browser access, with administrator access to your own VM.

Choose the Apple Silicon Mac VM ($39 a month) if the agent runs arm64-only binaries, or needs Xcode 26.4 or later. Choose the Dedicated M4 Pro 48 GB ($349 a month) if the agent holds credentials that should live on a Mac no other customer shares.

For a price check against a whole-Mac vendor, CloudMac lists a dedicated M4 (16 GB, 256 GB) at $99.99 a month or $999 a year on cloudmac.org/pricing. That is a different hardware class from Figment's VMs, so pick by the job and not by the headline price.

Run key-management scripts over SSH, from the remote desktop terminal, or from an outbound CI runner you connect to your own service. Do not type key values on a shell command line, where they would land in history.

Why should keys live in the Keychain and not in files?

The Keychain stores secrets encrypted and lets you restrict which binary may read each one, while a .env file is plain text that any process under the user can read. The security command manages the Keychain from the terminal with no GUI. Apple's Keychain Services documentation describes the storage model and access control. Run man security on your macOS version to confirm flags for that release.

Store an API key interactively:

# Add a generic-password item to the login keychain.
# -s service  -a account  -T pre-authorises a binary  -w prompts for the value
security add-generic-password \
  -s "openai-agent" \
  -a "prod" \
  -T /usr/bin/python3 \
  -w

-T pre-authorizes the named binary, so background launchd jobs do not trigger a GUI prompt ("User interaction is not allowed"). -w with no argument makes the shell prompt for the value, so the secret never appears in history.

Read the key in a script:

key=$(security find-generic-password -s "openai-agent" -a "prod" -w)

Never write the secret to a .env file, and never export the whole environment to disk, because it will contain other credentials. If a key has to move to a CI service, transfer the secret's name and paste the value into that CI's secret manager by hand.

What are the stages of a safe rotation?

Work eight stages in order and verify each row before moving on.

StageActionVerifyRollback if it fails
1. GenerateCreate a new key in the provider dashboardKey ID appears in the dashboardDelete it in the dashboard
2. Store newsecurity add-generic-password -s "openai-agent" -a "staging" -wfind-generic-password … -a "staging" -w returns a valuesecurity delete-generic-password -s "openai-agent" -a "staging"
3. Smoke testRun one agent job against the staging account labelJob exits 0, API returns a valid responseFix the key or config. Do not continue
4. PromotePoint the agent config at staging, restart the agentFirst production job exits 0Revert config to prod, restart
5. MonitorLet the agent run through the rollback window (at least 2 hours, 24 hours for critical jobs)No auth errors in the agent logRevert config, keep the prod key alive
6. Revoke oldRevoke the old key in the provider dashboardOld key returns 401 on a direct requestNone. Rollback is no longer possible
7. Remove entrysecurity delete-generic-password -s "openai-agent" -a "prod"find-generic-password for prod reports the item is missingNone
8. RenameDelete staging, re-add the same value under account prodRetrieval under prod succeedsNone

Do not compress stages 3 to 5 on a Friday afternoon. If you cannot watch the rollback window, delay stage 6 to the next business day.

When should I rotate a key right away?

Rotate immediately in any of these cases:

  • A teammate with key access leaves the project.
  • The key appears in a log line, error, screenshot or commit.
  • The provider flags unusual usage on the key.
  • You rebuild the Mac image or re-provision the VM.

Also rotate on a schedule. Every 90 days is a reasonable floor, and a launchd calendar reminder (below) keeps the date from drifting.

How do I keep secret values out of logs?

Log metadata only, and keep the key out of every field. A good log line looks like this:

2026-11-10T14:32:01Z job=openai-agent account=prod status=200 tokens_in=1240 tokens_out=380 cost_usd=0.00052

What must never appear:

# BAD — key value is visible
Authorization: Bearer sk-proj-abc123...
OPENAI_API_KEY=sk-proj-abc123...

Retrieve the key into a local variable, use it only in the HTTP header, and keep it out of loggers. In Python, silence noisy HTTP debug output with logging.getLogger("urllib3").setLevel(logging.WARNING) so request headers are not echoed.

Add a log-scan test to the pipeline that matches every line against your key prefix (for example sk-proj-[A-Za-z0-9]{40,}). If the pattern ever hits, fail the job and fix the logging path before the next rotation.

How do I schedule a rotation reminder with launchd?

Put a small plist in ~/Library/LaunchAgents/. Apple's launchd Creating Jobs guide covers StartCalendarInterval. When it is an array of dicts, each dict fires independently.

<!-- com.example.key-rotation-reminder.plist -->
<plist version="1.0"><dict>
  <key>Label</key><string>com.example.key-rotation-reminder</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/bin/osascript</string>
    <string>-e</string>
    <string>display notification "90-day API key rotation due" with title "Agent maintenance"</string>
  </array>
  <key>StartCalendarInterval</key>
  <array>
    <dict><key>Hour</key><integer>9</integer><key>Minute</key><integer>0</integer><key>Day</key><integer>1</integer><key>Month</key><integer>1</integer></dict>
    <dict><key>Hour</key><integer>9</integer><key>Minute</key><integer>0</integer><key>Day</key><integer>1</integer><key>Month</key><integer>4</integer></dict>
    <dict><key>Hour</key><integer>9</integer><key>Minute</key><integer>0</integer><key>Day</key><integer>1</integer><key>Month</key><integer>7</integer></dict>
    <dict><key>Hour</key><integer>9</integer><key>Minute</key><integer>0</integer><key>Day</key><integer>1</integer><key>Month</key><integer>10</integer></dict>
  </array>
</dict></plist>

Load it with launchctl load ~/Library/LaunchAgents/com.example.key-rotation-reminder.plist. The notification only prompts you to run the checklist by hand. Automatic rotation without stages 3 to 5 skips the human smoke test and is the main way rotations silently break production.

How do I move an agent off a .env file?

Follow these five steps, in order:

  1. Add the current key to the Keychain with security add-generic-password -w (prompted value).
  2. Change the agent to read it with security find-generic-password … -w into a local variable, not os.environ and not a temp file.
  3. Delete the .env and remove the variable from any shell profile, Dockerfile or service file.
  4. Run one manual job on the Mac and confirm the agent authenticates.
  5. Only after that run succeeds, remove the old value from any CI secret manager you previously synced it to.

Once the agent reads from the Keychain, the rotation workflow above replaces every "edit .env and restart" scramble. See the Mac hosting plans to choose a machine.

Related reading

Which Figment Mac fits this work?

Intel Mac VM from $25 a month, Apple Silicon Mac VM from $39, or a Dedicated M4 Pro for $199. Hourly and daily plans too. You pay before use, starting with at least $25 of account credit.

Choose a Mac plan