# How does a credential end up in my agent's output?

Usually because a tool call hands the agent something raw and it repeats that back. An agent that reads a `.env` file to check a setting, prints a debug log, or calls a tool that returns headers and environment variables now has that content in its context, and the next thing it writes often quotes it verbatim, in an explanation, a retry, or a line it logs.

The common paths are reading config or env files directly, verbose debug output, a credential passed into a tool call itself (an MCP server configured with a key, an HTTP parameter carrying a token), generated code that hardcodes a key it just saw, and child processes inheriting the same environment variables the agent has. None of that needs a bug in the model. The agent is doing what a language model does with whatever sits in its context: repeating what's relevant to the answer.

That's the gap secret_leak exists to close: nothing has to be misconfigured for a credential to end up somewhere it shouldn't.

---

Sources:
- NoBoxDev: 6 ways AI agents leak your API keys and secrets: https://noboxdev.com/blog/five-ways-ai-agents-leak-secrets (fetched 2026-08-25)

Source: https://tessary.ai/answers/tessary-secret-leak/how-does-a-credential-end-up-in-my-agents-output
More on Tessary secret leak: https://tessary.ai/answers/tessary-secret-leak
From Tessary, agent reliability for AI agents in production: https://tessary.ai
