An agent reads instructions from places you don't control: web pages, emails, documents, other people's messages. When one of those instructions gets acted on with your authority, that's the classic confused deputy: the agent has your permissions but follows someone else's words. You can't fully stop an agent from being confused. You can decide how much a confused agent is able to do. That's least privilege.

Five things to scope

SurfaceThe questionExample of too much
ToolsWhat can it call?Every MCP tool a server offers, when it needs two
DataWhat can it read and write?Your whole home folder for a task in one repo
AccountsWhose identity and which permissions?Your personal Gmail with full send access
AudienceWho can give it instructions?A chat bot anyone in the workspace can message
TimeHow long does access last?A scheduled job nobody remembers creating

Allow, ask, deny: how rules are evaluated

Most agents let you allow, ask about, or deny actions. The order they're checked in matters. In Claude Code, rules are evaluated deny, then ask, then allow, and the first match wins regardless of how specific a rule is. A broad deny like Bash(aws *) blocks aws s3 ls even if you also allowed that exact command: an allow can't carve an exception out of a deny.

That makes a practical pattern possible: deny whole categories you never want, ask for risky ones, and allow narrow, read-only commands so you aren't approving noise.

PROMPT / COPY-PASTE
{
  "permissions": {
    "deny": ["Bash(aws *)", "Read(./.env)", "Read(./secrets/**)"],
    "ask": ["Bash(git push *)", "mcp__email__send_message"],
    "allow": ["Bash(npm run test *)", "Bash(git status)", "Bash(git diff *)"]
  }
}

Rules match text, not intent

Here's the nuance most guides skip. A command rule matches the text the agent writes, not the program that ends up running. Claude Code's docs list the gaps directly:

RuleStopsDoesn't stop
Bash(curl *)curl https://example.com/usr/bin/curl ..., sh -c 'curl ...'
Bash(rm *)rm -rf build//bin/rm -rf build/, bash -c 'rm -rf build/'
Bash(git push *)git push origin maingit -C . push origin main

So command rules are guardrails for the normal path: they cut down prompts and catch honest mistakes. They aren't a boundary against an agent that's been steered. Containment needs enforcement below the agent: a sandbox with filesystem and network limits, the next article in this series.

Scope tools one by one

An MCP server can offer dozens of tools. Turn on the ones the task needs, not the whole server:

  • Claude Code rules work per tool: mcp__github__* covers a whole server, mcp__github__create_issue one tool. Deny write tools you don't need.
  • n8n's MCP server exposes nothing by default. You enable each workflow individually.
  • Make separates run scopes from management scopes, which can change scenarios and connections. MCP toolboxes limit a client to the scenarios you pick.
  • Zapier MCP pre-enables actions for apps already connected to your account, and the agent can enable more actions as part of a request. Review what's enabled, and remove what you don't use.

Watch for tools that change the agent's own powers: enabling new tools, editing config, spawning other agents. OpenClaw's guidance is to deny its gateway, cron, sessions_spawn and sessions_send tools for any agent that handles untrusted content. A confused agent that can rewrite its own permissions has no limits left.

Give the agent its own identity

Don't let the agent act as you when it can act as something smaller:

  • A separate account for the agent where possible: its own email, its own bot user, its own API key.
  • Read-only OAuth scopes when it only needs to read. "Read calendar" and "manage calendar" are different grants.
  • A shared agent gets its own everything. OpenClaw recommends running a team agent on a dedicated machine or container, with a dedicated OS user, browser profile and accounts, never signed into anyone's personal accounts.

Control who can instruct it

For a chat-based agent, every sender is an instruction source. Defaults matter here:

  • Hermes denies anyone not on your allowlist or paired through a one-time code.
  • OpenClaw sends unknown direct-message senders a pairing code and allowlists groups, usually behind a mention.
  • Cross-channel sending is often on by default. In OpenClaw, an agent that can send messages can send them to other conversations and other platforms unless you set allowWithinProvider and allowAcrossProviders to false.

And one agent should serve one circle of trust. If people who don't trust each other share an agent, any of them can steer it toward the others' data.

Watch for access that outlives the chat

A scheduled job is persistence: it keeps running with the agent's access after the conversation ends. That's why OpenClaw treats cron as a sensitive control-plane tool, and why Hermes denies dangerous commands in scheduled runs by default. Treat "create a recurring job" like any other privileged action: it should ask, and you should review the list now and then.

Least privilege checklist:

  • Destructive and outbound categories denied; risky ones set to ask; only narrow reads allowed
  • MCP servers trimmed to the tools each task uses, with write tools reviewed
  • No tool that lets the agent change its own permissions, for agents that read untrusted content
  • A separate identity and read-only scopes wherever the task allows
  • Chat agents allowlisted, cross-channel sending off unless needed
  • Scheduled jobs reviewed and removed when they're no longer needed

Go deeper: Secrets and API keys when agents run code · Prompt injection · Claude Code permission modes · MCP vs CLI