7 Habits for Securing Your AI Agents and Systems
How I lock down my AI agents and the machines they run on

I've worked as a sysadmin, network engineer and developer for years. My AI agents run on my own machines: a few always-on Linux servers, a Mac, a GPU box, small boards and a test box. Claude Code is the main agent. Grok, Codex and Gemini run alongside it as reviewers and tools.
These are the seven habits I use to secure them.
Habit 1: Keep admin on a private network
Every machine is on Tailscale, a private WireGuard network. Machines talk to each other over their Tailscale addresses, not their public IPs.
SSH and every admin page are reachable only over Tailscale: the reverse proxy's admin page, the monitoring dashboards, the file browser and the AI tools' web pages. None of them are on the public internet.
Habit 2: Deny by default, then check from outside
My public server once had no host firewall at all. Every service listening on all addresses was public.
When it was locked down, its firewall was set to deny all incoming traffic by default, and to allow Tailscale and ports 80 and 443 for the reverse proxy.
Before you do the same, connect over Tailscale and keep that session open. If you're on SSH over the public IP, enabling UFW can cut you off. With UFW, the change looks like this:
sudo ufw allow in on tailscale0
sudo ufw allow 41641/udp
# only if this machine runs a public reverse proxy:
# sudo ufw allow 80/tcp
# sudo ufw allow 443/tcp
sudo ufw default deny incoming
sudo ufw enable
Open a new SSH session over Tailscale before you close the one you have. Then check sudo ufw status numbered for old rules that still allow SSH on the public side, and remove them.
The allow rules go in first. 41641 is Tailscale's default UDP port; use yours if you changed it. If the machine runs a public reverse proxy, keep admin pages off 80 and 443. allow in on tailscale0 opens every port to your tailnet. If you share the tailnet, add a narrower rule for your SSH port before you remove that one.
Turn off what you don't use. An old file share on that server was turned off.
Then check from a machine outside your network that isn't on Tailscale. That shows what the internet actually sees, not what you think is open.
Habit 3: Bind Docker ports to localhost or Tailscale
UFW doesn't filter ports that Docker publishes. Docker adds its own firewall rules, and they go around UFW. A container published on all addresses is public, even with the firewall set to deny.
So every port in my Compose files is bound to 127.0.0.1 or to the machine's Tailscale address, never to all addresses. A port written as "8080:8080", with no address, is bound to all of them:
ports:
- "127.0.0.1:8080:8080"
To reach it from other machines on Tailscale, use the Tailscale address in place of 127.0.0.1. UFW doesn't see that port either, so a narrower Tailscale rule won't limit it. Docker has to start after Tailscale, or the container can't bind that address after a reboot.
Habit 4: Lock each AI tool in its own container
Grok, Codex and Gemini each run only in their own Docker container. Each gets:
- its own Linux user
- a read-only root filesystem
- no Linux capabilities
- one work folder
- no access to Claude's config
None of them gets installed directly on a machine without my OK. When one of them needs locking down further, the change goes in that tool's own config, never in Claude's.
AI tools I run for other jobs, like a music generator, each have their own Compose stack, with their web pages on Tailscale only.
More on how I run the other agents in Docker is in 7 Habits of My AI Agent Setup.
Habit 5: Keep secrets in one locked-down place
Each machine keeps user secrets in one folder: the folder is mode 700, and each file is mode 600. Secrets that a root system service reads go in a separate system folder instead.
Before writing a new secret, check both folders.
For code that goes public, scan it first. Before my agent-setup repo went public, it was scanned with gitleaks and searched for my own names, hosts and IPs. GitHub Secret Scanning and Push Protection are on for that repo now. The steps are in 7 Habits Before You Make a Repo Public.
Habit 6: Keep secrets out of logs people share
People paste logs into support threads.
My OBS logs could carry a stream key. Now OBS reads the stream from loopback, so new OBS logs can't carry the key.
Check what your logs record before you share them, and change the setup so the secret never reaches the log.
Habit 7: Watch your machines over the private network
My machines report to a self-hosted Beszel hub over Tailscale. A self-hosted Uptime Kuma runs TCP checks and push heartbeats.
Their dashboards are reachable only over Tailscale, like the admin pages in Habit 1.
The checklist
- Every machine on Tailscale. SSH and admin pages on Tailscale only.
- Firewall denies incoming by default, with the allow rules added first and a Tailscale session kept open. Unused services off. Checked from outside.
- Docker ports bound to
127.0.0.1or the Tailscale address. - Grok, Codex and Gemini each in their own locked container. Other AI tools in their own Compose stack, web pages on Tailscale only. No direct installs without a yes.
- User secrets in one folder (folder 700, each file 600). Root-service secrets in a separate system folder. Both checked before adding one. Code scanned before it goes public.
- Logs checked before they're shared. Secrets kept out of them at the source.
- Machines report to monitoring over Tailscale. Services have uptime checks.
The agent itself works under its own rules. It asks before installs, credentials, production config, deletes or anything public. It never changes a password or a key without a yes. Those rules are in 7 Habits for Letting an AI Agent Work on Your Machines.