Coding agents
How to give a coding agent an API key safely
Short answer
Put a restricted API key in an environment variable set outside the project, tell the coding agent the variable’s name, and let the commands it runs read the value. Do not paste the key into the prompt.
Use a separate key for agent work so you can revoke it without breaking anything else. When the key comes from a client or a colleague, have it sent as an Argoned sealed link, an encrypted link that opens once, rather than a chat message.
The risk
Why pasting an API key into the prompt is risky
- The prompt is part of the conversation, which the AI provider receives and your tool may keep as a transcript.
- Coding agents write files, logs, test fixtures and commit messages. A key in the conversation can be copied into any of them.
- Anything committed to git is hard to take back, even after you delete the line.
- Agents read pages, issues and documents. Hidden instructions in that content, known as prompt injection, can try to make an agent use a key it knows somewhere else.
Compared
Where to keep an API key, compared
| Approach | Exposure | Notes |
|---|---|---|
| Pasted into the prompt | In the transcript, and possibly in files the agent writes | Avoid |
| .env file inside the project | Plain text on disk, inside the folder the agent works in | Keep it out of git and block the agent from reading it |
| Environment variable set outside the project | Not in the repository; processes you start can read it | A good default |
| Secret injection tool, such as Bitwarden’s aac run | Injected into one process after you approve | Bitwarden calls its Agent Access SDK an early preview |
| Argoned sealed link | Used for the handover only | Then store the key in an environment variable |
Step by step
Step by step: give a coding agent an API key
-
Create a key just for agent work
Use a test project, a read-only scope or a spending limit if the provider offers one. Name it so you know it is the agent key.
-
Receive it sealed, if someone else creates it
Ask the key owner to send it as a sealed link and to give you the access code by a different route. Open it in your browser.
-
Set it as an environment variable
Set it in your shell profile or your operating system’s secret store, not in a file inside the project.
-
Give the agent the name, not the value
Tell the agent “use the PAYMENTS_TEST_KEY environment variable”. It can run commands that read it without the key appearing in the prompt.
-
Block secret files
In Claude Code, add Read deny rules such as Read(./.env) to your settings. In Cursor, list secret files in .cursorignore. Both tools note that terminal commands can still read files, so do not auto-approve commands such as cat.
-
Revoke it when the work is done
Delete the agent key at the provider. If it was ever pasted into a prompt or committed, revoke it straight away.
# Option 1: in your shell profile (such as ~/.zshrc), outside the project
export PAYMENTS_TEST_KEY="replace-with-your-test-key"
# Option 2: this terminal only, typed at a hidden prompt so it stays out of shell history
read -rs PAYMENTS_TEST_KEY && export PAYMENTS_TEST_KEY
# Then start the coding agent from this same terminal
# What you tell the agent, never the key itself
"Call the payments test API using the PAYMENTS_TEST_KEY environment variable." Argoned
Where Argoned fits
Argoned does not plug into Claude Code, Cursor or Codex. Its job is the handover: getting a key from the person who owns it to the person who sets up the agent, without the key sitting in a chat, an email or a ticket.
A coding agent in a terminal usually cannot type an access code into a web page, and you should not give it the code in the prompt. Open the sealed link yourself and put the value in an environment variable.
FAQ
Questions
Can Claude Code or Cursor read my .env file?
They can read files in the project unless you block them. Claude Code supports Read deny rules for files such as .env, and Cursor blocks files listed in .cursorignore from its agent. Terminal commands can still read blocked files, so review commands before you approve them.
I already pasted a key into a prompt. What now?
Revoke it at the provider and create a new one. Deleting the message does not un-send it.
Should each agent or project get its own key?
Yes. Separate keys let you see which one was used and revoke one without breaking the others.
Can a coding agent open an Argoned sealed link?
Not usefully. The link needs an access code typed into a web page. Open it yourself, then set the environment variable.
Next
Keep reading
- API keys in MCP config files Keep secrets out of mcp.json.
- Hand over API keys for n8n, Zapier or Make Collect client keys without email or chat.
- Encrypted credential sharing for AI agents How a sealed link works, step by step.
- Password managers for AI agents compared Argoned, 1Password, Proton and Bitwarden.
- AI agents Five ways to hand over a login, compared.
- Pricing Free: 8 items and sealed sharing with AI agents and people, no card. Pro: £2.99 a month for 512 items and import.
- Security How Argoned encrypts each item and each shared credential in your browser, what our servers store, and what is not protected yet.
Sources
- Configure permissions · Claude Code Docs, read 16 October 2026
- Ignore file · Cursor Docs, read 16 October 2026
- bitwarden/agent-access · GitHub · bitwarden, read 16 October 2026
Your agent needs a login. Send it sealed.
Seal a login or API key in your browser and send a link instead of the password.
£0 · Free plan, no card needed · Encrypted in your browser