Fallen Zen

← All posts

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:

Agent Sentry's General settings on macOS: network protection is active, file protection is recording only
General: network protection is active. File protection comes with the Guard.

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.

Agent Sentry's menu bar panel: a question about a new host, and Claude Code, Codex CLI and Gemini CLI with the hosts they reached
The panel: a question waiting, and each agent with what it did.

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, --yolo or 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's network rules: paste and file-drop services blocked, package registries and Git hosts allowed, this Mac and the local network always allowed
The built-in 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 install and cargo build keep 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.

A network rule opened in Agent Sentry: the hosts of the paste and file-drop services rule as removable chips, with a rule of my own above it
A rule opened: remove a host, add one, edit or delete the rule.

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:

Adding a network rule in Agent Sentry: a Block rule named Tunnels for *.ngrok.io and *.trycloudflare.com, applied to every agent
A Block rule of my own, for every agent.

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.

Agent Sentry's Connections list: the hosts Claude Code, Codex CLI and Gemini CLI reached, each allowed, let through or blocked, with the rule that decided
Connections: who reached what, and which rule decided.

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.

Agent Sentry's Notifications settings: asking about hosts no rule covers, what happens without an answer, and the alert for agents running with approvals off
Questions and alerts.

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.

A macOS notification from Agent Sentry: Gemini CLI wants to connect to storage.googleapis.com, a host no rule covers
A question for a host no rule covers.

The same pane has the alert for agents that run with approvals off. I'd leave it on:

A macOS notification from Agent Sentry: an AI agent is running with approvals off
An agent started without approvals.

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:

  1. Download the disk image from the Guard's page and open it.
  2. Drag Agent Sentry Guard to Applications and open it from there.
  3. Click Install Extension. macOS asks you to allow it in System Settings › General › Login Items & Extensions. Turn it on there.
  4. 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:

Agent Sentry Guard's window on macOS: protection is on, with buttons to open Agent Sentry and to uninstall
Agent Sentry Guard, installed.

You can quit the Guard's app. Its extension keeps running. In Agent Sentry, Settings › Extension shows its state and what it adds:

Agent Sentry's Extension settings: what Agent Sentry Guard adds, such as stopping agents from reading SSH keys and from changing shell profiles
Settings › Extension: what the Guard 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.

Agent Sentry's file rules in recording mode: SSH keys, cloud and developer credentials, npm settings and agents' sign-ins, with a read of an SSH key marked as would block
Recording only: “Would block ×1 lately, last ~/.ssh/id_ed25519”.

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 ~/.zshrc is how a one-off compromise becomes a permanent one.
  • Programs such as osascript and security, which do work outside the agent's reach. A program rule covers a renamed copy too.
  • .env files, 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:

Editing the SSH keys file rule in Agent Sentry: the verdict Block or Record, what it covers (reading, changing, running), and its paths
A file rule: its verdict, what it covers, and its paths.
  • 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. *.pem matches by extension, .env matches .env files, and a bare name such as osascript matches 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 exceptions of the SSH keys rule in Agent Sentry: public keys, known_hosts and the SSH config are left alone, and the rule applies to every agent
Exceptions: public keys, known_hosts and the SSH config stay readable.

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.

Agent Sentry's file rules with blocking turned on: a read of an SSH private key by an AI agent was blocked
Blocking on: “Blocked ×1 lately, last ~/.ssh/id_ed25519”.

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:

Agent Sentry's panel with all protections on: pastebin.com blocked for Claude Code, keychain access and a change to .zshrc blocked for Codex CLI, and a read of an SSH key blocked for Gemini CLI
All protections on. The red crosses are what didn't happen.

Read it card by card:

  • Claude Code ran npm test. Something in that run tried to reach pastebin.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:

  1. Install Agent Sentry and allow its network filter. The built-in network rules work from that moment.
  2. Leave the alert for approvals off turned on.
  3. Run the exposure check on your projects folder, and fix what's easy to fix.
  4. Install Agent Sentry Guard and give it Full Disk Access.
  5. Work for a day or two in recording mode. Add exceptions for what you really need.
  6. Turn blocking on.
  7. 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.

If an agent you use isn't recognized, or a rule gets in your way, write to me at piotr@codice.pl.