# Sensitive Data Leakage

> The Sensitive Data Leakage is the risk of exposing secrets or personal data through AI tools.

## How do I stop AI tools from leaking secrets and personal data?

The risk that API keys, passwords, personal or proprietary data end up in prompts, logs, generated code or responses. Prevented by keeping secrets out of the context, using '.env' files ignored by agents and reviewing outputs.

- Topic: Security & Ethics
- Type: concept

## Example

Wrong:

```js
const body = JSON.stringify(req);
await llm(`Debug this error:\n${body}`);
```

Right:

```js
const safe = redact(JSON.stringify(req), [
  /Bearer\s+[\w.-]+/g,
  /[\w.+-]+@[\w-]+\.[\w.]+/g,
]);
await llm(`Debug this error:\n${safe}`);
```

Redacting tokens and emails before the request leaves the app keeps secrets and personal data out of prompts and provider logs.

## Common mistakes

- Pasting production logs with customer data into a chat to debug them.

## Key points

- Secret files like '.env' are excluded from what the agent can read.
- Prompts and logs are scanned so API keys and personal data are redacted before sending or storing.
- Secrets are never pasted into prompts or committed, and come from environment variables at runtime.

## Interview questions

### Do AI providers store my prompts?

Many store prompts for some time for abuse monitoring, and some may use them for training depending on the plan and settings. Check the data policy.

### How do I stop a coding agent from reading .env files?

Add deny rules for '.env' and credential folders in the agent's permissions, and keep real secrets out of the project folder where possible.

### Can AI-generated code leak secrets?

Yes, for example by hardcoding a key it saw in context or logging sensitive values. Scan generated code with a secret scanner before committing.

## Related cards

- [Agent Permissions](https://wonderium.dev/ai/agent-permissions.md)
- [Agent Sandbox](https://wonderium.dev/ai/agent-sandbox.md)
- [AI Observability](https://wonderium.dev/ai/ai-observability.md)
- [.env](https://wonderium.dev/processes/env.md)
- [.gitignore](https://wonderium.dev/processes/gitignore.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/sensitive-data-leakage
- Last updated: 2026-11-25
