# Scan for secrets and restrict agent access before pushing

> Scan Git history and staged files, check agent skills, and restrict access to secret files before pushing.

Source: https://fullbytedeveloper.com/blog/scan-secrets-before-pushing-ai-code
Keyword: KEYS
Originally posted: 2026-11-05
Published here: 2026-11-07

API keys and other secrets leaked about twice as often in AI-assisted code in 2025, per a GitGuardian vendor report on 1.94 billion public GitHub commits [1]. The claim is based on commits by AI bot accounts or with an AI co-author line, not a controlled experiment, so take the exact number as an estimate. The fix is straightforward: run a scanner before every push.

## Install TruffleHog

TruffleHog scans your repo for secrets and verifies whether each one still works [2]. That tells you which leaks are urgent.

```bash
brew install trufflehog
```

You should see TruffleHog added to your path.

## Scan for verified and unknown secrets

Run this on repos you own, in the project folder:

```bash
trufflehog git file://. --results=verified,unknown
```

You should see a list of findings, or no output if the repo is clean. Verified findings mean the key still works and needs rotating.

## Install Betterleaks for old commits

Betterleaks scans current files and also checks older commits [3]. A secret you deleted months ago is still in the history.

```bash
brew install betterleaks && betterleaks git .
```

You should see findings from Git history. To include uncommitted files, run `betterleaks filesystem .` [3].

## Install detect-secrets for new secrets only

detect-secrets flags only new secrets by comparing against a baseline file [4]. This is useful in a pre-commit hook where you want to ignore known patterns.

```bash
pip install detect-secrets
detect-secrets scan > .secrets.baseline
```

Review the baseline before treating existing findings as accepted. To check staged files against it, run the hook command from the repo [4]:

```bash
git diff --staged --name-only -z | xargs -0 detect-secrets-hook --baseline .secrets.baseline
```

The hook reports new findings that are absent from the baseline. Creating or committing the baseline alone does not install a hook or block a push.

## Install SkillSpector for agent skills

Before you install an agent skill, scan it for hardcoded secrets or unsafe patterns [5]. SkillSpector is from NVIDIA and works on any skill folder.

```bash
uv tool install git+https://github.com/NVIDIA/skillspector.git
skillspector scan ./some-skill/ --no-llm
```

You should see a report of any risky patterns in the skill.

## Sandbox your agent's commands

Sandbox Runtime wraps any command you give it in a filesystem sandbox [6]. You can deny reads of `.env` and other sensitive paths:

```json title="~/.srt-settings.json"
{
  "filesystem": {
    "denyRead": ["**/.env"]
  }
}
```

```bash
npm install -g @anthropic-ai/sandbox-runtime
srt "your command"
```

You should see your command run with the sandbox active. Attempts to read `.env` fail.

## If a scan finds a live key

Revoke it first, then delete the line. Deleted lines stay in the repo's history, and anyone who clones the repo can find them. Create a new key in your provider's dashboard and update your secrets store.

## Sources

1. [GitGuardian State of Secrets Sprawl 2026 (vendor report)](https://www.gitguardian.com/state-of-secrets-sprawl-report-2026)
2. [TruffleHog repo](https://github.com/trufflesecurity/trufflehog)
3. [Betterleaks repo](https://github.com/betterleaks/betterleaks)
4. [detect-secrets repo](https://github.com/Yelp/detect-secrets)
5. [SkillSpector repo](https://github.com/NVIDIA/SkillSpector)
6. [Sandbox Runtime repo](https://github.com/anthropics/sandbox-runtime)

## Original posts

- [Instagram reel](https://www.instagram.com/reel/DfXoHBakXHb/)
- [Facebook reel](https://www.facebook.com/reel/1536860085158354)
- [TikTok video](https://www.tiktok.com/@fullbytedeveloper/video/7704749030395645204)
- [Threads post](https://www.threads.com/@fullbytedeveloper/post/DfXoJPWibnd)
