Last month, I was reviewing a junior developer's PR when I noticed something that made my stomach drop. They'd been using Claude Code to help scaffold out a feature, and in their commit history was a .claude/settings.local.json file. That file doesn't belong in git. Ever. It contained API keys, database credentials, and permissions they'd granted to the agent without thinking twice. I realized then that I'd been treating AI coding agents like trusted colleagues when I should have been treating them like powerful tools that need guardrails, just like any other tool that can read your filesystem.
Here's the thing: AI agents are genuinely useful. I use them daily. But I'd been naive about the security model. I was assuming the tool would protect my secrets by default. Spoiler alert: it doesn't. The agent running on your machine has the same access as you do, unless you explicitly restrict it. That's not a flaw in the tool, it's just reality.
The Real Problem: Defaults Are Permissive
When you fire up Claude Code, Cursor, or any other AI agent for the first time, the default configuration is "user can do anything." Your .env file is sitting there. Your AWS credentials are in ~/.aws/credentials. Your SSH keys are accessible. The agent sees all of it and can be prompted, tricked, or simply confused into reading or exposing these secrets.
I've seen this play out in real ways. A colleague ran an agent in a project that happened to have credentials hardcoded in an old config file. One bad prompt later, those credentials were logged in the chat history, which syncs to the cloud. It wasn't the agent's fault, it was ours for not setting boundaries.
The article I read this week laid out exactly what I wish I'd known earlier: you don't need to trust the agent. You need to configure the tools you're already using. Git, file permissions, sandbox settings, ignore rules, these all exist. We just have to use them intentionally.
Layered Defense: What Actually Works
The practical advice here is solid, and I've started implementing it. The first layer is predictable: add .env* files and agent-specific settings files to .gitignore. This stops secrets from ever leaving your laptop in a commit.
# .gitignore additions
.claude/settings.local.json
.env
.env.*
!.env.example
That's table stakes. But the real work starts with deny rules and sandboxing. If you're using Claude Code, you can configure explicit deny rules in .claude/settings.json:
{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)",
"Bash(curl *)"
]
},
"sandbox": {
"enabled": true,
"allowUnsandboxedCommands": false,
"filesystem": {
"denyRead": ["./.env", "~/.ssh", "~/.aws/credentials"]
}
}
}
This isn't bulletproof, the article is refreshingly honest about that. A deny rule doesn't stop a custom script from opening files directly. But it's enough to prevent casual exposure, and combined with the sandbox, it makes the agent's environment genuinely restricted.
What I'd Do Differently
The article covers Claude Code, Codex, and Cursor, which is thorough. But what strikes me is that none of these tools are designed with zero-trust defaults. They're built for convenience first. That's fine, it's the developer's job to restrict them afterward.
I'm going to be more systematic about this. The article suggests a 15-minute inventory: open your terminal and check what credentials are actually in your environment variables and config files. I'm doing that this week. I'm also going to test each agent with a harmless prompt asking it to read .env, just to confirm my deny rules are working. That feels like a good sanity check.
One thing I want to push back on slightly: calling these "guardrails" or "permissions" might give false confidence. Sandboxes are real security boundaries, but only if they're correctly configured. Deny rules are more like speed bumps. I'll be treating them as such.
Your Turn
If you're using AI agents in your development workflow, and honestly, most of us are now, this deserves an afternoon of your time. Check your .gitignore. Test your agent's access to credentials. If you're on a team, make this part of your onboarding.
What's your current setup? Are you running agents with unrestricted access? I'd genuinely like to know what configuration patterns others are settling on.
Source: This post was inspired by "How to stop your AI coding agent reading .env and secrets" by Dev.to. Read the original article