← All lessons

Every Agent Is a White Hat: Hats Are Permission, Teams Are Roles

Where it went wrong

I was writing the brief for the next piece of my agent tooling: a security pass over every merge request, and later, an on-demand mode that attacks a staging environment to see what breaks. Somewhere in the first draft I caught myself reaching for words like “hacker mode” and “black hat checks”, because that’s how security tooling gets talked about.

That’s fine in conversation. It isn’t fine in an instruction to an agent. An agent takes words at face value. If the brief blurs “attack this” with “you’re allowed to attack this”, the agent inherits the blur, and the first time a task points somewhere it shouldn’t, the blur decides what happens.

So before writing any code I pulled the vocabulary apart.

Hats are permission and intent

The hat colours answer one question: were you allowed, and what were you trying to do?

  • White hat: authorized, with good intent. You have permission, you stay in scope, you report what you find. Penetration testing, bug bounties and application security reviews are white hat work.
  • Black hat: unauthorized, with bad intent. Stealing, ransoming, exfiltrating, damaging. Illegal.
  • Gray hat: unauthorized, but claiming good intent. “I scanned your site without asking, but I was only trying to help.” It’s still unauthorized. Meaning well doesn’t create permission after the fact.

None of the hats is about skill. A brilliant attacker with permission is a white hat; a clumsy one without it is not.

Teams are roles

The team colours answer a different question: what job are you doing right now?

  • Red team: plays the attacker against a system, to find out what an attacker could do.
  • Blue team: defends: detects, responds, hardens.
  • Purple team: red and blue working together in real time, so every attack becomes a defence the same day.

A red team isn’t a hat. A red teamer with written permission, a defined target and a time window is doing white hat work. The role is “attacker”; the authorization is still white.

And Red Hat is a Linux company. It’s on this list only because the name trips people up.

The rule

Once the two questions are separate, the rule for my tooling is short:

Every agent is a white hat agent. There are no black hat agents and no gray hat agents. Red team mode is white hat work: authorized attack simulation against systems we own, in staging only, with an audit of every attempt.

The test an agent applies is one sentence: do we have explicit permission for this exact target, in this exact scope? If the answer isn’t a clear yes, it isn’t white hat, and the agent doesn’t do it.

That includes the “helpful” cases. “Just check this one site, it’s probably fine” is a gray hat request. The agent refuses that part, says why, and carries on with the parts it is allowed to do. It doesn’t interpret its way around the rule, because an agent that can argue itself into one unauthorized target can argue itself into the next.

Limits live in code, not prompts

Writing the rule into a prompt is the easy half. A prompt is advice: the model reads it, weighs it, and usually follows it. “Usually” is not a security property.

So the rule gets enforced where the agent can’t negotiate with it:

  • Scope is data, not prose. A red team run starts only with a recorded target, the attack classes allowed, a time window and the name of the person who approved it. Missing any of those, or a production target, and the run refuses to start.
  • Commands and paths are allow-listed in code. What an agent may run, which files it may change and where it may connect are checked by the program that runs it, not by the model’s good judgment.
  • Failure stops the work. If a guardrail can’t be checked (a policy is missing, a sandbox didn’t start), the work stops. There is no unguarded fallback mode.
  • Proof over claims. “I fixed it” counts when there’s a diff and a clean re-run of the same check, and not before.
  • Everything is audited. Who started it, what was in scope, what was tried, what was found.

Doing this properly also meant taking an honest inventory first: every place an agent in my setup can read, write, run a command, push or reach a secret. Some of what I found was already solid. Some of it was a guardrail I’d written in a prompt and assumed was a guardrail in code. That gap is exactly what this rule exists to close.

What I’d tell anyone building agent tooling

Decide the authorization question before the capability question. It’s tempting to start with what the agent can do: scan, exploit, fix. Start instead with what it’s allowed to do, write that down as data, and make the code check it.

The best security tooling isn’t the one that can break the most things. It’s the one you can prove only broke what it was allowed to break.

← All lessons