The convenience of autonomous coding agents comes with a terrifying default: if your user account can read a file, so can the AI. Jeff Feldman’s recent DEV.to breakdown highlights a common nightmare scenario where an agent debugging a Stripe webhook simply runs cat .env, dumping live secret keys into a chat transcript. This isn't a bug; it's a feature of the current permission model. Unless you explicitly configure deny rules or sandbox environments, your AI assistant has the same read access as you do, potentially exposing credentials to third-party logs or local history.

The Built-in Shields: Claude Code and Codex

For users of Anthropic’s Claude Code, the first line of defense is native configuration. By adding specific deny rules to ~/.claude/settings.json, you can prevent the Read tool from accessing .env files entirely. However, the Read tool is only half the battle. Claude Code’s Bash sandbox, which is off by default, leverages macOS’s Seatbelt framework to restrict writes and network access. It can also hide sensitive directories like ~/.ssh and environment variables like GITHUB_TOKEN from sandboxed commands. Meanwhile, OpenAI’s Codex CLI ships with a more restrictive default, using a workspace-write mode that limits file modifications and disables network access unless explicitly enabled.

Secret Management and Isolation

Relying on plain text .env files is archaic in the age of AI agents. Feldman recommends replacing actual keys in .env with references to 1Password CLI, using the op run command to inject secrets only into the process environment. This ensures that if an agent reads the file, it sees references, not keys. For SSH security, the tool Secretive stores keys in the Mac’s Secure Enclave, making them non-exportable and requiring Touch ID for use. This provides a tangible audit trail; if an agent unexpectedly runs git push, you get a notification.

Monitoring and Outbound Control

Prevention isn't enough; you need detection. Tools like gitleaks act as a pre-commit hook to fail commits containing secrets, while GitHub’s push protection blocks pushes to public repos. For visibility into usage anomalies, TokenBar aggregates usage data for Claude, Codex, and others, helping identify forgotten headless scripts burning quota. Finally, since macOS’s firewall only blocks inbound connections, Objective-See’s LuLu is essential for alerting on new outbound connections, catching any process phoning home to an unknown host.

Key Takeaways

  • Default agent permissions mirror user permissions, exposing .env files unless explicitly denied.
  • Claude Code and Codex CLI offer distinct sandboxing methods; Codex is more restrictive by default.
  • Secret references via 1Password CLI prevent agents from reading plaintext keys from disk.
  • Outbound monitoring with LuLu and usage tracking with TokenBar are critical for detecting rogue agent behavior.

The Bottom Line

Stop trusting your agent with raw file system access. Implement deny rules, use secret injection, and monitor outbound traffic immediately. If your agent can read your .env file, it can leak your credentials; if you haven't locked it down, you're already exposed.