Keep test credentials out of AI agent transcripts
QA agents and simulated users need logins, API keys and test cards, and those values leak into what they record. Five patterns that keep them out.
How do I give an AI agent a password without it seeing it?#
Assume anything an AI test agent can read will end up in a record somewhere: its prompt, its transcript, a screenshot, a trace, a log or the test report. Records are hard to clean. Keep the values out of the agent's reach instead: give each run its own test account that expires with the run, log in before the agent takes over, add API keys to requests outside the agent, scrub every artifact for the exact values the run used, and limit the network so a value that does leak has nowhere to go.
Where test credentials end up#
A QA agent that tests a web app needs to get in. It needs a username and password for each role it plays, maybe an API key to seed data, and card numbers to get through checkout. A simulated user on a docs site or an SDK needs a sign-up flow and a key.
Each of those values can land in more places than people expect:
- The prompt, when the task says "log in as qa-admin with password ..."
- The transcript, every time the model repeats or reasons about the value
- Screenshots, if the agent captures a page with the field visible or a settings page that shows a key
- Browser traces, which record a lot: Playwright's trace viewer keeps "a set of complete DOM snapshots for each action", a screencast, console output and the network requests with their headers and bodies
- Logs from the agent, the test runner and the app itself
- The test report, the bug ticket filed from it and the chat message that links the ticket
Most of those records outlive the run by months. Some leave your company: transcripts go to your model provider, and reports are shared with the people who asked for the test. A test password in a ticket is still a password. Until it expires, it works.
Why agents make this harder#
A scripted Playwright test fills a field from an environment variable, and the value appears in the trace and nowhere else. An agent is different. It reads the page, decides what to do and writes down why. If it knows the password, it can repeat it in its reasoning, paste it in the wrong field or quote it back in a summary.
The agent also reads text it did not write. A web page under test, a support widget or a seeded comment can carry instructions, and a model that holds a secret can be talked into sending it somewhere. The OWASP GenAI Security Project lists Sensitive Information Disclosure among its 2025 risks for LLM applications, and its advice includes to "limit access to sensitive data based on the principle of least privilege". Least privilege for a test agent starts with the values it never sees.
Pattern one: a test account per run#
Shared test accounts are the usual source of trouble. One account used by every run collects state, gets locked by failed logins and ends up with its password in a hundred transcripts. Accounts are cheap to make.
Create a fresh account at the start of each run instead, with a random password, test data of its own and only the role the scenario needs. Delete it or disable it when the run ends. A password that is valid for twenty minutes and then gone is a much smaller problem when it shows up in a screenshot six months later.
Runs also stop interfering with each other. Two agents that test checkout at once no longer fight over one cart.
Pattern two: credentials that expire with the run#
Apply the same idea to API keys and tokens. Issue a key for the run, limited to the test tenant and the actions the run needs, set to expire soon after the run's timeout. Your test setup does this through your app's own admin API before the agent starts.
Test cards are a special case. Payment providers publish card numbers that only work in test mode, and those numbers are not secret. The test-mode API key behind them is. Live payment keys should never be in a test environment at all.
Pattern three: log in before the agent starts#
The safest password is one the model never reads. For browser tests, let your harness do the login step with plain code: open the page, fill the form from an environment variable, wait for the dashboard. Then hand the logged-in browser to the agent and start the trace after that point.
The agent begins its task already signed in. It never sees the form. Its prompt says "you are signed in as a user with the editor role", which is all it needs to know. If a scenario tests the login flow itself, use a throwaway account created for that run and treat its password as public.
API keys allow one step more: add the key to requests outside the agent. Something outside the agent attaches the key to calls bound for one API, so the agent makes the call and gets the answer without ever holding the value.
Pattern four: scrub every artifact for the exact values#
Redaction by pattern guesses at what a secret looks like. You can do better, because the run knows its own values. Record every credential the run used, then scan every artifact before it is stored or shared: the transcript, the trace, the logs, the screenshots' text layer and the report. Replace each exact value, and its common encodings such as URL encoding and base64, with a marker.
Cover screenshots too. Mask password fields and API key panels before capture, or exclude those pages from screenshots altogether. Then fail the report step if a known value survives the scrub. A failed build is cheaper than a leaked key.
Pattern five: a network that only reaches what the test needs#
Every pattern above can slip. The last line is the network. If the environment can reach only the app under test, its test data service and the model API, then a value that leaks into the agent's context has no address to be sent to.
Start with the list of destinations a run needs and refuse the rest. Enforce it outside the agent, where neither the agent nor a page it reads can change it. Review that list whenever a test starts calling something new.
What to ask of the sandbox your agents run in#
The patterns work best when the environment makes them the default. Before you pick where your QA agents run, check five things:
- Can a secret be stored once and given only to the runs or commands that name it?
- Are secret values kept out of the platform's own logs and outputs?
- Is there a way to bind a key to one API so the sandbox never sees the value?
- Can you choose between no network, a list of allowed destinations and open access, with the list enforced outside the sandbox?
- Does every run start from a clean copy, so one run's accounts and files never reach the next?
How Promigence handles secrets and the network#
Promigence gives each run its own sandbox, started from a snapshot you built and verified, and the sandbox ends when the run's command exits (unless you pass --keep). Nothing carries over between runs.
You store a secret once and name it on the runs or commands that need it. It is encrypted at rest, given only to the commands that name it, and kept out of logs and outputs. Values are never shown when you list secrets. A secret is never written into a snapshot you build, and a snapshot of a sandbox that was given a secret is refused unless you force it.
Some keys should never be readable inside the sandbox at all. A secret bound to one API with --host and stored with --no-raw stays out of the sandbox: requests the sandbox sends to the address Promigence prints for that API can use it, as promigence secrets set --help shows, and no run can ask for the value itself. That suits a model API key, or a key your setup uses to call your app's admin API.
Each sandbox can have full outbound access, none, or an allow list of the destinations it needs. Agents that read untrusted input, such as web pages, belong behind an allow list. If a run looks wrong while it is going, promigence sandbox network SID --cut cuts the sandbox's outbound access at once, and it cannot be turned back on.
CI jobs and schedules should get a key that can start work and nothing more: one created with run access can start sandboxes and builds but cannot change secrets, keys or billing.
The Run AI-written code safely guide shows the secret and network settings in practice. The security-testing guide walks through a fresh copy of an app per run, behind an allow list that names only the model API, with the model key kept out of the sandbox.
FAQ#
How do I give an AI agent a password without it seeing it?#
Do the login step in your test harness with plain code, then hand the signed-in browser to the agent. The model never reads the password. With API keys, have something outside the agent add the key to requests for one API, so the agent makes the call without holding the value.
Do Playwright traces contain passwords?#
They can. A trace keeps complete DOM snapshots for each action, a screencast, console output and network requests with headers and bodies. Start tracing after the login step, mask sensitive fields, and scan the trace for known values before you store or share it.
Should AI test agents use real user accounts?#
No. Create a test account per run, with its own data and only the role the scenario needs, and delete it when the run ends. A credential that expires with the run is far less damaging if it appears in a transcript or screenshot later.
How do I redact secrets from AI agent transcripts and test reports?#
Record every credential the run used and replace each exact value, plus common encodings, in every artifact before it is stored. Fail the report step if a known value is still present. Exact matching beats guessing what a secret looks like.
How do I stop an AI agent from sending a leaked key somewhere?#
Limit the network. An allow list enforced outside the agent, naming only the app under test and the APIs the run needs, leaves a leaked value nowhere to go.
Try Promigence#
With Promigence, each test gets its own sandbox, with secrets named per run, keys bound to their API with --host and --no-raw, which stay out of the sandbox, and an allow list on the network. Request access for free credit to start, then follow the quickstart.
Sources#
| Source | What it supports | Read |
|---|---|---|
| OWASP GenAI: LLM02:2025 Sensitive Information Disclosure | the risk; least-privilege access to sensitive data | 24 Nov 2026 |
| Playwright: Trace viewer | what a trace records: DOM snapshots per action, screencast, console, network requests | 24 Nov 2026 |