# Keep your .env away from three coding agents

> The real .env switch in Claude Code, Cursor and GitHub Copilot, checked Nov 8 against each vendor's docs.

Source: https://fullbytedeveloper.com/blog/env-block
Published here: 2026-11-10

A .claudeignore file does nothing. Your agent can read your .env keys. Here is the real switch in each coding agent, checked Nov 8, 2026 against each vendor's docs.

## Claude Code

Put deny rules in `.claude/settings.json` [1][2]:

```json title=".claude/settings.json"
{
  "permissions": {
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(./secrets/**)"
    ]
  }
}
```

These rules also block `cat`, `head`, `tail` and `sed` on those files. They do not cover a command that reads without naming the file, like `grep -r pattern .` [1].

For that, turn on the sandbox by typing `/sandbox` in Claude Code. It applies your Read deny rules to every shell command [3]. Works on macOS, Linux and WSL2. Not native Windows.

## Cursor

`.env*` is on the default ignore list [4]. Add other secret files to `.cursorignore` in the project root (gitignore syntax):

```text title=".cursorignore"
secrets/
*.pem
*.key
```

**Warning:** terminal and MCP tools used by Agent can still reach ignored files [4].

## GitHub Copilot

For Copilot Business and Copilot Enterprise only. Go to Repo Settings > Copilot > Content exclusion [5][6]. Add:

```text
- ".env*"
- "/secrets/**"
```

Takes up to 30 minutes in IDEs that already loaded the settings. GitHub says it is not a filesystem security boundary [5].

## Rule for all three

Keep live keys out of the project folder the agent works in.

Each vendor's docs say these switches are not a filesystem security boundary. Use them to reduce accidental exposure, not to protect production secrets.

Send this to the friend who thinks a .claudeignore file keeps their keys safe.

## Sources

1. [Claude Code docs: permissions](https://code.claude.com/docs/en/permissions)
2. [Claude Code docs: settings reference](https://code.claude.com/docs/en/settings-reference)
3. [Claude Code docs: sandboxing](https://code.claude.com/docs/en/sandboxing)
4. [Cursor docs: ignore files](https://cursor.com/docs/context/ignore-files)
5. [GitHub docs: content exclusion](https://docs.github.com/en/copilot/concepts/context/content-exclusion)
6. [GitHub docs: configure content exclusion](https://docs.github.com/en/copilot/how-tos/configure-content-exclusion/exclude-content-from-copilot)
