How to protect your Mac from AI agents with Agent Sentry
AI coding agents such as Claude Code, Codex, Gemini CLI, Cursor and GitHub Copilot run commands on your Mac with your permissions. Whatever you can read, they can read: SSH keys, cloud credentials, .env files, browser cookies. Whatever server you can reach, they can reach too.
Most of the time that's what you want. It goes wrong when an agent reads something it shouldn't have trusted: a prompt injection in a web page, a poisoned package, a README with instructions hidden in it, a malicious MCP server. Then the agent is working for somebody else, with your keys.
This guide shows how to put limits around AI agents on macOS with Agent Sentry, feature by feature, with screenshots. The limits are kept by macOS itself, outside the agent, so an agent that can run any command still can't switch them off.
What you need
- A Mac with Apple silicon and macOS 26 or later.
- Agent Sentry from the Mac App Store. It's a firewall for AI agents: a Network Extension content filter that decides which servers agents may reach.
- Agent Sentry Guard, a free download from codice.pl. It adds file and program rules through Endpoint Security, Apple's framework for security software.
The App Store app is complete without the Guard. The Guard is a separate download only because apps that use Endpoint Security can't be sold on the Mac App Store.
Step 1: Install Agent Sentry and allow the network filter
Install Agent Sentry and open it. The welcome window explains what it does, and macOS asks you once to allow its network filter. Allow it. From then on a shield sits in your menu bar.
Open Settings from the gear in the panel. General shows both protections:
The filter only looks at connections made by AI agents and the processes they start. Every other app on your Mac is let through untouched. It reads the host a connection names, never what the connection carries.
Step 2: See what your agents are doing
Click the shield. The panel lists every running agent with its project folder, the command it runs right now, its MCP servers, and the hosts it reached or was kept from.
A few things to read on each agent's card:
- Confirmed means the agent's code signature proves who made it. Unconfirmed means it's known only by its name or location, so it gets stricter rules.
- A green tick is an allowed connection, a red cross a blocked one, and a yellow mark one that no rule covers.
- Approvals off warns you that the agent was started with
--dangerously-skip-permissions,--yoloor a flag like them: nothing asks you before it acts. - A shell, script, build tool or MCP server the agent starts belongs to that agent. When Claude Code runs
curl, the program connecting is Apple's, but the rules that apply are Claude Code's. Your own Terminal stays yours.
Step 3: Network rules, or which servers an agent may reach
Open Settings › Network › Rules.
Agent Sentry starts with three built-in rules:
- Paste and file-drop services are blocked. Pastebin, transfer.sh, webhook catchers and the like are the usual way to slip data out of a machine. An agent has no reason to upload your files there.
- Package registries are allowed, so
npm install,pip installandcargo buildkeep working. - Git hosts are allowed, so cloning and pushing keep working.
Your Mac and your local network are always reachable, and an agent's own app, signed by its maker, may reach its maker's servers.
Edit a rule
Click a rule to open it. Every host is a chip you can remove, and the field under them adds one. *.example.com covers example.com and every host under it. The pencil opens the full editor, and the bin deletes the rule. That goes for the built-in rules too.
Add your own rule
Scroll down and click Add Rule…. Give it a name, add hosts, choose Block or Allow, and choose who it applies to: every agent, or only the ones you pick.
Here I'm blocking tunnelling services, another way data leaves a machine:
Your rules decide before the built-in ones. So an Allow rule of yours can open a host that a built-in rule blocks, and a Block rule can close one that a built-in rule allows. To make an exception for one agent, add an Allow rule for that host and set Applies to to that agent only.
If you ever tie yourself in a knot, Reset All Rules… puts everything back as installed.
Review the connections
Settings › Network › Connections lists the hosts agents reached lately, with the rule that decided each one.
This is the quickest way to write rules. Find a host you don't like, open its ⋯ menu and choose Block. Find one that was blocked and shouldn't have been, and choose Allow. Agent Sentry writes the rule for you.
Step 4: Ask before a new host
By default, a host that no rule covers is let through and listed as not reviewed. If you'd rather decide each time, open Settings › Notifications and turn on Ask when something an agent runs connects to a host no rule covers.
Now the connection waits while you answer Allow or Block, once or always, in the panel or right in the notification. "Always" becomes a rule. You also choose what happens if you don't answer in 30 seconds.
The same pane has the alert for agents that run with approvals off. I'd leave it on:
Step 5: Check which secrets an agent could read
Settings › Files › Exposure answers a simple question: if an agent working in this folder went bad, what could it take?
Click Add Folder… and choose a project, or your whole home folder. Agent Sentry looks for .env files with values in them, private keys without a passphrase, and tokens in agent and MCP configurations. It shows where each one is and what kind it is, never the secret itself, and nothing leaves your Mac.
Fix what you can: put a passphrase on the key, move the token to the keychain. The file rules below cover the rest.
Step 6: Install Agent Sentry Guard for file protection
Network rules stop data from leaving. File rules stop an agent from reading the secret in the first place, and from changing files that run code later, such as your shell profile. Deciding who may open a file takes Endpoint Security, and that's what Agent Sentry Guard is: a small system extension that only answers Agent Sentry.
To install it:
- Download the disk image from the Guard's page and open it.
- Drag Agent Sentry Guard to Applications and open it from there.
- Click Install Extension. macOS asks you to allow it in System Settings › General › Login Items & Extensions. Turn it on there.
- Give it Full Disk Access in System Settings › Privacy & Security, so it can see the files agents open.
Agent Sentry connects to it by itself. The Guard's window should now say that protection is on:
You can quit the Guard's app. Its extension keeps running. In Agent Sentry, Settings › Extension shows its state and what it adds:
The Guard is notarized by Apple, never goes online, and only accepts connections from apps signed by the same developer. With it installed, an agent can't quit Agent Sentry or the Guard either.
Step 7: File rules, first recording, then blocking
Open Settings › Files › Rules. The Guard starts in recording mode, on purpose. Nothing is blocked yet. It only records what the rules would have stopped.
The built-in rules cover what attackers go for first:
- SSH keys in
~/.ssh/. - Cloud and developer credentials:
~/.aws/,~/.azure/,~/.config/gcloud/,~/.kube/and more. - Keychains, browser cookies and saved passwords, password managers, private keys.
- Shell startup files, login items and launch agents, which run code by themselves later. A changed
~/.zshrcis how a one-off compromise becomes a permanent one. - Programs such as
osascriptandsecurity, which do work outside the agent's reach. A program rule covers a renamed copy too. .envfiles, recorded on the agent's card each time one is opened.
Each rule has a verdict. Block rules stop the access once blocking is on. Record rules let it through and show it on the agent's card.
Work with your agents for a day or two in recording mode. Each rule shows what it would have blocked and when, and so does each agent's card in the panel. If something you need shows up there, add an exception before you turn blocking on.
Edit a file rule
The pencil on a rule opens its editor. A file rule has more to it than a network rule:
- Verdict: Block or Record.
- Covers: reading; changing, creating, renaming or deleting; running as a program. The SSH keys rule covers only reading, so an agent can still create a new key.
- Paths:
~/.ssh/means that folder in every home folder, and the slash at the end covers everything in it.*.pemmatches by extension,.envmatches.envfiles, and a bare name such asosascriptmatches a program.
Add exceptions
Scroll down in the editor to Except. These are paths inside the rule's paths that the rule leaves alone.
The SSH keys rule already excepts *.pub, known_hosts and ~/.ssh/config, because git and ssh need those and none of them is a secret. Add your own the same way. For example, if one agent has a deploy key of its own, add that key's path here.
Applies to works as it does for network rules: every agent, or only the ones you pick. So you can also copy a rule's idea into a narrower one. Keep the Block rule for every agent, and let one agent you trust through with a Record rule of its own.
Turn blocking on
When the "would block" list holds only things you really want stopped, turn on Block what Block rules cover at the top.
From now on a blocked read fails with "Operation not permitted". To the agent it looks like a file it has no rights to.
Blocking in action
Here's the panel with both protections on, while three agents work:
Read it card by card:
- Claude Code ran
npm test. Something in that run tried to reachpastebin.com. The network rule for paste and file-drop services blocked it. The registry, GitHub and the agent's own API went through. - Codex CLI runs with approvals off. Something it started ran
/usr/bin/security, the tool that reads the keychain, and tried to write to~/.zshrc. Both were blocked by file rules. Its build went on. - Gemini CLI is unconfirmed, and tried to read
~/.ssh/id_ed25519, a private SSH key. Blocked.
None of these agents was stopped from doing its job. The build, the tests and the API calls all worked. Only the parts that had no business happening were refused, and each one is on the card so you can see it and ask why.
A setup that works
If you want the short version, this is what I'd do on a new Mac:
- Install Agent Sentry and allow its network filter. The built-in network rules work from that moment.
- Leave the alert for approvals off turned on.
- Run the exposure check on your projects folder, and fix what's easy to fix.
- Install Agent Sentry Guard and give it Full Disk Access.
- Work for a day or two in recording mode. Add exceptions for what you really need.
- Turn blocking on.
- Once in a while, look through Connections and block what you don't recognise.
Private by design
Agent Sentry has no account, no analytics and no tracking. What your agents do and the rules you set stay on your Mac. It only goes online to send a problem report you've read first, and the Guard never goes online at all.
Get it
$12.99, once. No subscription, and updates are free. The Guard is free.
- Download Agent Sentry on the Mac App Store
- Agent Sentry Guard, free from codice.pl
- Everything about Agent Sentry at codice.pl/agentsentry
If an agent you use isn't recognized, or a rule gets in your way, write to me at piotr@codice.pl.