AI coding agents can read your .env file
An agent working in your project folder sees the same files you do, including secrets. Keep real keys out of its reach.
AI coding agents now open files, run commands and edit code across whole projects. That’s what makes them useful. It also means they can read .env, config files with database passwords, SSH keys in your home folder, and anything else the terminal can reach.
Most of the time nothing bad happens. But secrets can end up in the conversation sent to the model provider, in logs, or in a commit the agent wrote. And a prompt injection hidden in a README or an issue could ask the agent to send them somewhere.
- Use development keys with limited access in your project, never production keys.
- Configure the agent to deny reading secret files and running network commands without approval. Most tools support ignore or permission rules.
- Run agents in a container or separate user account for untrusted repositories.
- Keep a pre-commit secret scanner, so a leaked key is caught before it’s pushed.