# Separate Project Workspaces on an Agent Mac

Canonical: https://figment.so/blog/mac-agent-workspace-isolation

Give each project its own macOS user, a mode-700 home directory and its own LaunchAgents and Keychain, then run three checks to prove the separation works.

**Create one macOS user per project, set each home directory to mode 700, and keep each project's LaunchAgents and login Keychain under that user.** Then run the three checks below to confirm Project A cannot read Project B's files, agents or secrets.

Two automation projects under the same macOS user share one environment. That is how API keys from Project A end up in Project B's process, and how a cleanup script wipes the wrong working directory. Separate users remove that shared state.

## What do I write down before I create anything?

Record these inputs per project. Keep secret names in your runbook, never the values.

| Per-project input | Example |
|---|---|
| Short user account name | `agent-projecta` |
| Home directory | `/Users/agent-projecta` |
| Working directory | `/Users/agent-projecta/workdir` |
| Secret names (not values) | `PROJECTA_API_KEY`, `PROJECTA_DB_URL` |
| Automation binary path | `/Applications/ProjectA/agent` |
| Required network destinations | `api.projecta.com:443` |

Load the real values into each user's own login Keychain, or inject them from your CI service's secret manager at job start. Never write secret values into provisioning scripts, LaunchAgent plists or a shared `.env` file, because that recreates the shared state you are removing.

## How do I create one OS user per project?

Run `sysadminctl -h` to confirm the flags for your macOS version, then create each user from an administrator session over SSH or remote desktop:

```bash
# Project A agent user
sudo sysadminctl -addUser agent-projecta \
    -fullName "Project A Agent" \
    -password - \
    -home /Users/agent-projecta \
    -shell /bin/bash

sudo createhomedir -c -u agent-projecta
sudo chmod 700 /Users/agent-projecta

# Project B agent user
sudo sysadminctl -addUser agent-projectb \
    -fullName "Project B Agent" \
    -password - \
    -home /Users/agent-projectb \
    -shell /bin/bash

sudo createhomedir -c -u agent-projectb
sudo chmod 700 /Users/agent-projectb
```

The `-password -` form prompts interactively, so no password lands in shell history. With `chmod 700`, only the owning user can list or read the home directory. Each user then has its own login Keychain under `~/Library/Keychains/`, its own `~/Library/LaunchAgents/`, its own environment and its own `crontab` and `at` namespaces.

## What if one user must handle several projects?

Keep each checkout in its own mode-700 directory and never cross-reference paths:

```bash
mkdir -p ~/workspaces/projecta ~/workspaces/projectb
chmod 700 ~/workspaces/projecta ~/workspaces/projectb
ls -la ~/workspaces/
# drwx------  ... projecta
# drwx------  ... projectb
```

This blocks accidental reads. It does not stop a compromised job from reading sibling directories under the same uid, so use separate users whenever you can.

## How do I run each project's LaunchAgent as its own user?

Apple's [Creating Launchd Jobs](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html) documents that agents in a user's `~/Library/LaunchAgents/` are launched by that user's own `launchd` and are not visible to other users. Install the plist as the target user with mode `600`, then bootstrap it in that user's GUI domain:

```bash
sudo -u agent-projecta install -m 600 \
    /tmp/com.yourorg.projecta.plist \
    /Users/agent-projecta/Library/LaunchAgents/com.yourorg.projecta.plist

AGENT_UID=$(id -u agent-projecta)
sudo launchctl bootstrap gui/"$AGENT_UID" \
    /Users/agent-projecta/Library/LaunchAgents/com.yourorg.projecta.plist
```

`bootstrap gui/<uid>` is the current form on modern macOS. `launchctl load` still works but is deprecated. Run `launchctl help` on your Mac to see the subcommands in your release.

If the Mac is also a GitHub Actions self-hosted runner, read GitHub's [hardening for self-hosted runners](https://docs.github.com/en/actions/reference/security/secure-use#hardening-for-self-hosted-runners) and run the runner service under the project's dedicated user, not an administrator account.

## What is the provisioning checklist for each new project?

- [ ] OS user created with `sysadminctl -addUser`
- [ ] `/Users/agent-projectX` mode is `700` (`ls -ld`)
- [ ] Working directory inside home exists and is mode `700`
- [ ] Secret values loaded into that user's login Keychain, not into env files or plists
- [ ] LaunchAgent plist in `~/Library/LaunchAgents/` for that user only
- [ ] Plist is owned by the agent user and mode `600`
- [ ] Plist bootstrapped in that user's GUI domain (`bootstrap gui/<uid>`)
- [ ] `launchctl list` as Project A's user does not show Project B's agents
- [ ] `ls /Users/agent-projectb` as Project A's user returns `Permission denied`
- [ ] Logs write to the agent user's home, not a shared path
- [ ] Cleanup scripts reference `$HOME` paths only, never hardcoded `/Users/agent-*`

## How do I prove the separation works?

Run all three checks before you point production schedules at the agents.

**Check 1: cross-user read is blocked.**

```bash
sudo -u agent-projecta ls /Users/agent-projectb/workdir
# Expected: ls: /Users/agent-projectb/workdir: Permission denied
```

**Check 2: the LaunchAgent namespace is separate.**

```bash
sudo -u agent-projecta launchctl list | grep projectb || echo "isolated"
# Expected: isolated
```

**Check 3: the Keychain is scoped.** Add a test item to Project A's login Keychain with `security add-generic-password`, then run `sudo -u agent-projectb security find-generic-password -a agent-projecta`. It should fail to find the item, because the lookup runs against Project B's own Keychain.

If any check fails, stop and fix it before loading real agents.

## How many agent workspaces fit on each Figment Mac?

All three plans give you administrator access to your own Mac or VM, so you can create users with the commands above. For two or three light agents that run one after another and build Intel-compatible targets, the Intel Mac VM ($25 a month, macOS Sequoia, Xcode up to 26.3) is enough. Choose the Apple Silicon Mac VM ($39 a month, $6 a day) for arm64-only binaries or Xcode 26.4 and later. Choose the Dedicated M4 Pro 48 GB ($349 a month, 48GB of memory) when several agents run at once and each needs its own memory. VM vCPUs are shared, not reserved. Compare the plans on [Figment Mac Hosting](/mac-hosting).

## How do I move an existing setup over?

Export each project's LaunchAgent plist, rewrite absolute paths under the new user's home, load secrets into the new login Keychain, bootstrap the plist in the target user's GUI domain, then re-run the three checks.

**Related guides:**
- [Mac Agent Key Rotation](/blog/mac-agent-key-rotation)
- [Mac Agent Action Approvals](/blog/mac-agent-action-approvals)
- [GitHub Actions Self-Hosted Runner on Mac](/blog/mac-github-actions-self-hosted-runner)
