# Safe8bit: keep .env files and API keys out of Cursor's agent (beforeReadFile / beforeShellExecution hooks, macOS)

**URL:** <https://forum.cursor.com/t/safe8bit-keep-env-files-and-api-keys-out-of-cursors-agent-beforereadfile-beforeshellexecution-hooks-macos/177822>\
**Category:** Built for Cursor\
**Tags:** hooks, macos, security\
**Created:** [November 9, 2026, 12:00pm UTC](https://forum.cursor.com/t/safe8bit-keep-env-files-and-api-keys-out-of-cursors-agent-beforereadfile-beforeshellexecution-hooks-macos/177822 "2026-11-09T12:00:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chingling](https://avatars.discourse-cdn.com/v4/letter/c/7ab992/32.png) [@chingling](https://forum.cursor.com/u/chingling)\
**Post date:** [November 9, 2026, 12:00pm UTC](https://forum.cursor.com/t/safe8bit-keep-env-files-and-api-keys-out-of-cursors-agent-beforereadfile-beforeshellexecution-hooks-macos/177822/1 "2026-11-09T12:00:58Z")

</div>

Cursor’s agent reads `.env` files whenever it needs to understand a config, and the key ends up in the chat context.

I built **Safe8bit** , a secrets vault for macOS, and its **Shield** plugs into Cursor’s hooks (`beforeReadFile` and `beforeShellExecution`):

- denies reading `.env` files, private keys and credential files (`.netrc`, `~/.aws/credentials`…), directly or through `cat`/`grep`/`python`/`curl @file`
- denies reading any file that contains a value stored in the vault
- asks you before `printenv`, `env` or `safe8bit read`, including inside `sh -c` and `safe8bit run --`
- tells the agent to use `safe8bit run -- npm run dev` instead, which puts the variables into the process. Touch ID asks you, not the agent.

Install: `brew install --cask safe8bit-app/tap/safe8bit`, then `safe8bit shield install` (it finds `~/.cursor` and `~/.claude`).

The vault is encrypted on the Mac (AES-256-GCM, Argon2id, key in the Secure Enclave), with no account and no server. It’s a guardrail against accidental leaks, not a sandbox: code the agent runs can still read its own environment.

Lite is free forever (the Shield only logs there); Pro is $39/year and blocks. I’m the developer, happy to answer questions.

Demo and download: [Safe8bit — the secrets vault for developers](https://safe8bit.com/en/)

Curious how others keep secrets away from the agent today.
