Coding agents don’t just suggest code anymore. They run your tests, install packages, edit dozens of files, and push branches—often while you’re off making a coffee. That’s the point, and it’s also the risk: an agent can do anything your user account can do, and it takes instructions from whatever text lands in its context.
“She’ll be right” isn’t a security model. This post covers the three controls that matter most—sandboxes, permissions, and secrets—and how to combine them so an agent gets room to work without getting the keys to everything.
Why this matters: Agents read untrusted text
Prompt injection ranks first in the 2025 OWASP Top 10 for LLM applications. A README, an issue comment, a dependency’s docs, or a web page can contain instructions, and models can’t reliably tell those apart from yours.
Simon Willison calls the dangerous combination the “lethal trifecta”: access to private data, exposure to untrusted content, and the ability to communicate externally. A coding agent on a typical developer laptop has all three by default—SSH keys and .env files, arbitrary code and web pages, and an open network.
And you don’t even need an attacker. A misread instruction can mean a wrong rm -rf, a force push, or a migration against the wrong database. OWASP files this under excessive agency: too much functionality, too many permissions, too much autonomy.
1. Turn on your tool’s sandbox, and know what it covers
The major coding CLIs now ship OS-level sandboxes, but their defaults and scope differ (as of November 2026):
- OpenAI Codex CLI offers three sandbox modes:
read-only,workspace-write, anddanger-full-access. Inworkspace-write, the agent can edit files and run commands inside the workspace, network access is off unless you enable it, and.gitstays read-only. - Claude Code has a sandboxed Bash tool that uses Seatbelt on macOS and bubblewrap on Linux, limits writes to the working directory, and routes traffic through a proxy that only allows approved domains. The docs are upfront that it restricts only Bash commands—built-in file tools, MCP servers, and hooks still run on the host.
- Gemini CLI can run inside Docker or Podman, or use Seatbelt on macOS. Its default Seatbelt profile mainly blocks writes outside the project; stricter profiles also limit the network.
The lesson: read what your sandbox actually restricts. Filesystem isolation without network isolation still lets a confused agent send your files somewhere; network isolation without filesystem isolation lets it tamper with your machine.
2. Use a container or VM for anything unattended
If an agent runs for an hour without you watching, give it a machine of its own. Options range from a dev container to a throwaway cloud environment to microVM tools such as Docker Sandboxes, which give each session its own kernel and Docker daemon.
Whatever you pick, a few rules make the difference:
- Mount the project, not your home directory.
- Don’t mount the host’s Docker socket; control of the Docker daemon is effectively root on the host.
- Make the environment disposable, so a mess costs a rebuild, not a weekend.
3. Treat permissions as guardrails, not walls
Allow, ask, and deny rules are great for keeping an agent on track. A sensible split: allow routine commands (tests, linters, builds), ask before anything that changes state beyond the repo (git push, deployments, package publishing), and deny what you never want (rm -rf, editing CI secrets, production CLIs).
For Codex, a cautious everyday setup looks like this:
sandbox_mode = "workspace-write"
approval_policy = "on-request"
[sandbox_workspace_write]
network_access = false
But rules that match tool calls or command patterns are not a security boundary. Denying the agent’s file tool access to .env doesn’t stop a shell command from printing it, unless the sandbox enforces the same restriction. Agents are good at finding another way to reach a goal—that’s what makes them useful.
So keep the flags that skip all checks, like --dangerously-skip-permissions or danger-full-access, for environments you’re happy to throw away.
4. Keep secrets out of reach
The safest secret is one the agent never sees.
- Use development credentials. Production keys don’t belong on the machine or in the container where an agent works. Test accounts and sandboxed payment keys cover most tasks.
- Scope and expire tokens. If an agent needs GitHub access, a fine-grained personal access token limited to the repositories it needs, with an expiration date, beats your all-powerful personal token. A separate bot account makes its actions attributable and easy to revoke.
- Inject, don’t store. Secret managers can pass a value to a single command instead of leaving it in a file the agent can read.
- Don’t paste secrets into prompts. Whatever you type goes to the model provider and may end up in logs.
- Scan before you commit. Tools like Gitleaks catch keys that slipped into code—whether you or the agent put them there.
5. Watch the extras and the output
MCP servers, plugins, and skills extend what an agent can do, and each one adds to the trifecta. Install only those you trust and need, and review their permissions like you would a new dependency.
Finally, read what the agent did. A clean git diff, the agent’s command log, and a quick look at new dependencies catch most surprises before they ship.
A sensible baseline
- Sandbox on, with network access limited to what the task needs.
- A container or VM for long or unattended runs.
- Permission rules for routine work, approvals for anything irreversible.
- No production secrets in reach; scoped, expiring tokens for the rest.
None of this makes agents perfectly safe. It makes their mistakes small, visible, and cheap to undo—which is exactly what you want from a tool that works this fast.

Hi, I’m Owen! I am your friendly Aussie for everything related to web development and artificial intelligence.
