Security · ~7 min
The trifecta's "private data" leg is the one you can shrink in an afternoon. Don't let a secret into context, and there's nothing to exfiltrate.
Pasting an API key into a prompt sends it to the model API, writes it into session logs, and risks the agent echoing it back in a comment or generated file. Once a secret enters the context window, you've lost control of where it goes. The fix: agents need results, not credentials.
Set secrets as environment variables before the agent process starts. The agent's tools consume
$VAR internally — the value is inherited by child processes but never travels through a tool call as text.
Go one step further: a wrapper script consumes the credential internally and returns only output. The agent calls the script by name; the key never appears in the tool input.
Design wrappers to accept intent and return results. The Vault token, the 1Password service account, the raw key — none ever enter the agent's context.
Injecting all available credentials expands blast radius for free. Before starting, list what the agent will inherit and strip anything the task doesn't need:
For CI, never use long-lived keys: prefer short-lived OIDC-federated tokens scoped to the minimum, stored in the platform's secret store (GitHub Actions secrets), rotated between runs. GitHub Actions auto-redacts registered secrets from logs.
A permissions.deny rule on .env stops the agent reading it — but if the secret is
already in an env var, the file rule is irrelevant. Use both: inject via env and deny reads of credential
files. Belt and suspenders, because either alone has a gap.
Shared containers: sibling processes may read /proc/<pid>/environ unless the
container is hardened. Sub-process stripping: some harnesses spawn tools with a cleaned env — your
parent-shell vars won't be inherited. In-session retrieval: fetching a secret during the
task puts the retrieval command and its output in context — always retrieve before the
session starts.
Retrieval practice — recall, don't peek
Question 1The safest place to supply a secret to an agent is…
Question 2A wrapper script protects a credential by…
Question 3In CI pipelines you should prefer…
Question 4Fetching a secret during a session is risky because…
Question 5 · spaced recall from Lesson 2Prompt injection works because attention is…
direnv + Vault setup that loads scoped secrets on
cd, or to see how a scoped-credentials proxy keeps broad tokens entirely outside the sandbox? Next:
Two Walls, Not One — sandboxing primitives.