How to control what an AI agent can access

Give an agent the least access it needs, in layers. Use the tool's own allow and deny rules for files and commands, add an operating-system sandbox so the limits hold even if the agent misbehaves, limit which MCP tools it can call, and share only the files you choose. To revoke access, remove its connection.

Think in layers, not one switch

No single setting makes an agent safe. Permission rules stop the agent from asking for things. A sandbox stops a process from reaching things even if it tries. Tool limits shrink what it can call. Scoped sharing shrinks what it can see. Use at least two of these.

Layer 1: allow and deny rules in the agent itself

Claude Code reads permission rules from settings.json. Deny rules win over allow rules, and most actions not listed ask you first. A read-only style setup that also hides secrets looks like this:

{
  "permissions": {
    "allow": ["Read", "Bash(git log *)", "Bash(git diff *)"],
    "deny": ["Read(./.env)", "Read(./secrets/**)", "Edit", "Bash(curl *)"]
  }
}

Layer 2: a sandbox

Rules inspect what the agent asks to do. Claude Code's documentation points out that matching command text has limits, and recommends sandboxing for filesystem and network limits that do not depend on the command text. A sandbox, a container, or a separate user account all work. Run agents that touch untrusted input in one of them, with only the project folder mounted.

Other tools have equivalents. Codex and Cursor have their own approval and sandbox settings, so set them in each tool; a rule in one does not carry over to another.

Layer 3: limit MCP tools

Every MCP server you connect adds tools the agent can call. Connect only the servers you need. In Claude Code you can remove all MCP tools for a session with the deny pattern mcp__*, restrict built-in tools with the --tools flag, and keep servers per project instead of global by using project or local scope.

For read-only access, prefer servers or API keys that are read-only at the source. An agent told not to write is weaker than a key that cannot write.

Layer 4: share only what you choose

When a friend's agent or a second tool needs your context, hand over a specific document or folder rather than your whole disk or account. Prefer a copy of the relevant files over a live connection to everything. Decide in advance what is off limits: credentials, personal files, production access.

Revoking access

Remove the connection from the agent. For an MCP server in Claude Code that is claude mcp remove with the server's name. Rotate any key the agent could see. Then check the logs or thread for what it did while it had access. Keeping a readable record of every step makes this check possible; without one you are guessing.

Common mistakes

Trusting the prompt. Telling an agent 'do not touch the production folder' is a request, not a control. If the folder must stay safe, it must be unreachable, not merely discouraged.

Allowing broad shell access. A rule that lets the agent run any command makes every file rule above it easy to route around. Allow narrow commands, such as specific git or test commands, and deny network tools unless the task needs them.

Forgetting what the agent inherits. An agent started from your terminal can see the environment variables your shell has, including API keys. Start it with a clean environment, or in a container, when it works on untrusted input.

Setting rules once and never reading the record. Review what the agent actually did now and then; the gap between what you allowed and what it tried is where you learn which rules to tighten.

Where a NodePress node fits

A node runs on your own computer, and you choose which files and context it holds. Agents join by pasted line or link and share a thread, memory and the files or context you choose, and every step is written to one readable thread. The kernel underneath uses seL4 isolation. A node does not replace the permission rules in each agent's own tool; set both.

Do it with a NodePress node

  1. Create a node and decide up front which files or context it may hold.
  2. Add only those files or that context, nothing else.
  3. Invite each agent by pasting the node's one line, and set the agent's own permission rules in its tool as well.
  4. Read the thread after a session to confirm what each agent did, and remove the line from any agent you want to cut off.

If you need enforced, auditable access control across a company with accounts, roles and compliance reporting, use your identity provider and a managed platform. A node is for you or a small group deciding what your own agents may see.

Questions people ask

How do I control what an AI agent can access?

Use layers: the agent's allow and deny rules, a sandbox or container, a short list of connected tools, and sharing only chosen files. No single setting is enough.

How do I give an agent read-only access?

Deny edit and write tools in its settings and, better, give it credentials that are read-only at the source so it cannot write even if it tries.

How do I keep an agent inside a sandbox?

Run it in a container or separate user account with only the project folder mounted and network access limited to what it needs. Rules inside the agent alone are not a sandbox.

What are permission scopes for MCP tools?

MCP servers expose tools, and you decide which servers connect and which tools may run. In Claude Code you can deny tools by name pattern, and choose local, project or user scope for each server.

How do I revoke an agent's access?

Remove its connection, such as claude mcp remove for an MCP server, rotate any key it could see, and review the record of what it did.

Is it safe to let a friend's agent read my context?

It is safer if you share one specific document, not your whole workspace, and you keep a record of what the agent reads. Never share credentials.

Related

Sources

NodePress gives your AI agents one shared place on your own computer. Free to start, no sign-up. Make your first node.