← All posts

Why coding agents need access control

Claude Code and Codex can read your files, reach any host and use your credentials. How sandboxing, scoped API keys and MCP tool rules give coding agents access control.

Short answer: coding agents run with your files, your network and your credentials. Access control means a profile decides what an agent can reach, and a sandbox and a proxy enforce it, so the agent can call real APIs without ever seeing the real keys.

Coding agents like Claude Code and Codex stopped being autocomplete a while ago. They run shell commands, install packages, read your files, call APIs and talk to MCP servers. They do this on your machine, under your user account, with whatever credentials happen to be lying around.

That is what makes them useful, and it’s also why most people don’t trust them to run on their own: they watch every command, approve every tool call and hesitate before letting a session run unattended.

The answer isn’t to watch harder. It’s to decide up front what an agent is allowed to touch, and have something enforce it.

The problem

An agent session inherits your environment. In practice that usually means:

  • Your secrets. The .env file in the repo, tokens exported in your shell, cloud CLI credentials in your home directory. If the agent can read them, they end up in its context, and from there in logs, transcripts and sometimes in code it writes. (More on that in how to stop coding agents from reading your .env file.)
  • Your network. The agent can reach any host your machine can. A prompt injection in a README, an issue comment or a package’s docs can tell it to send data somewhere it shouldn’t.
  • Your filesystem. It can read and write far more than the repo it’s working on.
  • Your tools. An MCP server exposes every tool it has. If the Linear server has delete_issue, the agent has delete_issue.

None of this requires a malicious agent. It only takes a confused one, or one that read the wrong text at the wrong time.

What goes wrong today

The usual workarounds each fix part of the problem and create a new one.

Approving every action. Permission prompts are the default safety net, and they work right up until you’ve clicked “allow” for the fortieth time. At that point you’re either reviewing every step yourself or you’ve switched to auto-approve and the net is gone.

Keeping secrets out of the agent’s reach. You can strip credentials from the environment, but then the agent can’t do the work that needs them: checking a Stripe customer while debugging, reading a GitHub issue, querying an internal API. You end up pasting values into the chat, which is worse.

Giving the agent its own broad token. A separate API key is better than your personal one, but most tokens are all-or-nothing. A Stripe key that can look up customers can usually issue refunds too. How to secure API keys when using Claude Code walks through scoping one.

Storing secrets in a vault. A secrets manager answers where a secret lives. It doesn’t answer what an agent may do with it once it’s in the process environment. The moment the value is handed over, the vault is out of the loop.

The common gap is that nothing sits between the agent and the outside world deciding, request by request, whether this action is allowed.

How Stashbase approaches it

Stashbase treats this as access control. You write a profile for the agent once, and every run is held to it.

Profiles live in your repo. Each agent profile is a TOML file under .stashbase/agents/. It says which network destinations the agent can reach, which files it can’t read or write, which sandbox to use, and which credentials it can use, and how.

egress_hosts = ["api.anthropic.com", "platform.claude.com", "api.stripe.com"]

[filesystem]
deny_read = [".env"]
deny_write = [".env"]

[secrets]
project = "my-app"
environment = "agents"

[secrets.STRIPE_API_KEY]

[[secrets.STRIPE_API_KEY.rules]]
effect = "allow"
hosts = ["api.stripe.com"]
methods = ["GET"]
paths = ["/v1/customers/*"]

[sandbox]
backend = "native"

The agent runs in a sandbox. Sandboxing uses the native OS sandbox or a Docker container, on your laptop, in Docker or on your own server. Outside the profile’s rules, files and hosts are simply not there for the agent.

The agent never sees the real credential. Inside the sandbox, STRIPE_API_KEY holds a placeholder. When the agent makes a request, the Stashbase Agent Proxy checks it against the profile and swaps in the real value only if the rule allows it. In the example above, GET /v1/customers/cus_123 goes through with the real key. POST /v1/refunds doesn’t, and the placeholder is useless anywhere else. Rules can go further and match JSON request bodies, so you can allow a call but only with specific values.

MCP tools are filtered too. For HTTP and stdio MCP servers, the profile decides which tools the agent can see and call:

[mcp_servers.linear]
url = "https://mcp.linear.app/mcp"
binding = "LINEAR_API_KEY"
allow_tools = ["*"]
deny_tools = ["delete_issue"]

Every request is logged, without the secrets. The proxy records metadata-only audit logs, so you can see what the agent did after the fact without the logs becoming another place secrets leak.

The result is that you stop approving individual actions and start reviewing a policy. The policy is a file in your repo, so it gets code review like everything else.

Your apps can use Stashbase secrets too

Stashbase isn’t only for agents. stashbase run starts any command with secrets in its environment, so you don’t need a .env file for local development:

stashbase run -p my-app -e development -- npm run dev

With a stashbase.yaml in the repo, stashbase run -- npm run dev is enough. The secrets go only to that process, not to your shell, and --only limits which ones it gets.

You decide how to organize them. Your app and your agents can share secrets, or use different ones from different projects and environments. Environments are just groups of secrets, so you can split them however suits your team. Your app gets real values. Your agents get placeholders that only work for requests their profile allows.

Getting started

The CLI is open source. Install it on macOS or Linux:

curl -fsSL https://stashbase.dev/cli/install.sh | bash

Create a profile and run your agent inside it:

stashbase agent init local
stashbase agent run --profile local -- claude

Swap claude for codex to run Codex instead. Sandboxing, the local proxy and agent profiles are free with no limits. The docs walk through writing your first profile, testing rules with stashbase agent policy test, and moving to the remote proxy when a team needs it.