Handling secrets when AI agents do the work: a token map, encryption and one secret at a time
API keys and passwords are where agentic automation gets dangerous. Our rules: secrets never in git or chat, one map of which token lives where, encrypted backup with age, a copy-only field for one-time keys, and entering one secret at a time.
- Secrets never go into git, chat or bus messages. Agents refer to them by name, not by value.
- One token map says which token exists, what it is for and where it lives. Check it before creating anything new; new secrets need the owner's yes.
- Files with secrets are encrypted with age before backup; the private key stays in the keychain.
- Entering keys: one secret at a time, the clipboard step last, and pages that show a one-time key have a copy button that copies only the value.
Agents that do real work need real credentials: a token for the hosting account, a key for the mail flow, access to a database. That is exactly where an otherwise careful automation can leak. Most leaks we have seen elsewhere were not hacks; they were a key pasted into the wrong place. Our rules are built around making the wrong place hard to reach.
Where secrets never go
- Git. A secret committed once stays in the history even after the file is deleted. CI runs a secret scanner on every push as a safety net, but the rule is not to need it.
- Chat. Conversations are stored. An agent should never ask for a key in chat, and should never print one back.
- The agents' message board. Not even in private messages. A message may say where a secret lives, never what it is.
- Logs. Scripts must not echo values. A useful habit: if a log suddenly shows masked characters in odd places, a secret with a strange value has been set somewhere, and it is worth checking.
One map of every token
Without a map, every new automation creates a new token "just for this", and a year later nobody knows which ones are still used. Our token map lists each secret by name, its purpose, its scopes and the file it lives in, never its value. The rule for agents is simple: need a token? Find it in the map. If it is there, use that file and create nothing. If it is genuinely missing, ask the owner; new secrets are his decision.
In depth: storage, backup and entry
Encrypted backup with age
Local secret files are encrypted with age, a small modern encryption tool, and backed up to a private repository. The private key stays in the macOS keychain, with a copy in the password manager. Losing a laptop then costs a restore, not a week of rotating every key. The same key encrypts our database backups, so there is one thing to protect, not two (more in backing up a Cloudflare stack).
Verify capability, not names
A token with the right name and the wrong permissions is worse than no token: a backup quietly returns empty and you find out on the day you need it. Setup scripts therefore test what a token can actually do (read the database, list zones, export DNS) and refuse to continue if something is missing, saying exactly which permission.
Entering a secret: one at a time
When a person has to supply a key, for example after creating it in a provider's dashboard, our preferred flow is:
- The agent opens and prefills the form in the browser, everything except the secret.
- The person gets one command that copies the value to the clipboard, pastes it and confirms.
- The agent checks the result immediately and fixes any error.
One secret per round, no values shown on screen, and the clipboard step always last, right before pasting, so the value does not sit in the clipboard while other things happen.
Pages that show a one-time key
When one of our systems issues a key that is shown only once, the value sits in its own field with a copy button that copies only the value. Explanations and sample configuration go above or below, never mixed into the copied text. It sounds minor; it removes a whole class of "the key does not work" problems caused by a stray space or a line of instructions pasted along with it.
Agents never widen their own access
Agents that reach our systems through the MCP hub cannot grant themselves or each other more permissions. They request access, the hub administrator evaluates it, and the change happens only after the owner's explicit yes. See orchestrating agents through one MCP hub.
Start here
Write your own token map today, even if it has five lines. Move any key that lives in a repository or a chat into a proper secret store and rotate it. The Academy lesson OAuth for connectors explains when you do not need a long-lived key at all.
Frequently asked questions
Can I paste an API key into a chat with an AI assistant?
Avoid it. Chat history is stored and may be read later or by other tools. Put the key directly where it is used, such as a secret store, an environment variable or a connector's settings, and let the agent refer to it by name.
What is age?
A small, modern file-encryption tool. We use it to encrypt files that contain secrets before they are backed up to a private repository; the private key stays in the operating system's keychain.
What is a token map?
A single document listing which token exists, what it is for and in which file it lives, without the values. Before anyone creates a new secret, they check the map; most of the time the right token already exists.
Why one secret at a time?
Because entering several keys in one go is where mistakes happen: a value pasted into the wrong field, a key left in the clipboard, a form submitted with half the fields wrong. One secret, one confirmation, one check.
Written from our own production systems by the Flowsmith editorial team, with AI assistance.
Want this running in your company?
Flowsmith designs and operates automations like this for small and mid-sized teams — with a person approving anything that leaves the building.