Keep live API keys out of prompts and source code, and prevent the assistant from accessing files and tools it does not need. Use the specific assistant’s file-deny controls, limit cloud-agent network access, and scan and review changes before merging. If a key may already have been exposed, revoke or rotate it promptly; deleting the visible copy is not enough.
How an AI coding assistant can expose a key
A key does not have to appear in a committed source file to be at risk. An assistant may read a credential-bearing file, receive a secret pasted into a prompt, run a command that prints credentials into tool output, or be steered by malicious instructions in repository content, an issue, or a web page. The risk depends on what the assistant can read, execute, and reach over the network—not just which model you use.
As an Amazon Associate I earn from qualifying purchases.
OpenAI describes prompt injection as an evolving security challenge and recommends limiting an agent’s access to the data it needs and reviewing consequential actions: Understanding prompt injections. Treat repository files, issue text, web pages, and command output as untrusted, even when they look like ordinary project instructions.
Set up access controls before starting
Find where credentials are available
Check more than the obvious .env file. Credentials may also be in local settings, shell environment variables, cloud credentials, CI variables, command output, or MCP and extension configuration. Identify these locations before choosing the assistant’s permissions.
#1 Best Overall
- POWERFUL SECURITY KEY: The Security Key C NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
- WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key C NFC secures 100 of your favorite accounts, including email, password managers, and more.
- FAST & CONVENIENT LOGIN: Plug in your Security Key C NFC via USB-C and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
- TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
- BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.
Exclude secret-bearing files using the product’s own controls
Use a tool-level deny or ignore rule so the assistant cannot read credential files in the first place. The syntax is product-specific; one assistant’s rule is not portable to another.
- Claude Code: its FAQ gives
"Read(.env*)"as a deny-rule example in.claude/settings.json. See the Claude Code permissions FAQ. - Cursor: its documentation describes
.cursorignorefor excluding files from agent access. See Cursor’s ignore-files documentation.
Confirm the rule applies to the active workspace and the mode you are using. Cursor says its first-party agent defaults require approval for sensitive actions and recommends keeping those defaults enabled; check the current Cursor agent security guidance rather than assuming settings are unchanged.
Rank #2
- POWERFUL SECURITY KEY: The YubiKey 5C NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
- WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5C NFC secures 100+ of your favorite accounts, including email, password managers, and more
- FAST & CONVENIENT LOGIN: Plug in your YubiKey 5C NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
- MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
- PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts
Keep secrets out of prompts and examples
Do not paste live credentials into prompts, repository instructions, issues, or examples. OpenAI’s guidance says, “Never commit your key to your repository,” and recommends environment variables instead of embedding keys in source code: Best Practices for API Key Safety. Put placeholders—not usable values—in sample files such as .env.example.
Environment variables keep values out of source code, but they are not an access-control boundary by themselves. An agent or a command it runs may still be able to read or print the process environment. Minimize what the agent can access and use platform controls where available.
Rank #3
- POWERFUL SECURITY KEY: The YubiKey 5 NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
- WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5 NFC secures 100+ of your favorite accounts, including email, password managers, and more
- FAST & CONVENIENT LOGIN: Plug in your YubiKey 5 NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
- MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
- PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts
Limit what the agent can do while it works
Use narrow permissions and review commands
Choose the assistant’s mode and permission profile deliberately. Keep manual approval for sensitive actions when the product offers it. Read shell commands before approving them, avoid broad unbounded permissions, and do not ask an assistant to print environment variables, credential files, or complete command output that could contain secrets.
Constrain cloud agents’ outbound access
If a cloud agent can access secrets, limit the destinations it can contact to those the task requires. Cursor documents network-egress controls, redacted runtime secrets, file exclusion, and OIDC credentials for its cloud agents: Cursor cloud-agent security. GitHub documents internet-access restrictions for Copilot cloud agent: About GitHub Copilot cloud agent. Availability and configuration differ, so verify the controls for your product and administrator policy. Allowlisting too narrowly can also block legitimate work.
Rank #4
- POWERFUL SECURITY KEY: The Security Key NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
- WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key NFC secures 100 of your favorite accounts, including email, password managers, and more.
- FAST & CONVENIENT LOGIN: Plug in your Security Key NFC via USB-A and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
- TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
- BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.
Prefer scoped, short-lived production credentials
For production workloads, consider a key management service or secret store and grant access only to the workload that needs it. Where your provider and architecture support it, short-lived credentials or workload identity reduce dependence on long-lived stored keys. These approaches still require correct permissions and configuration; they do not make an over-privileged agent safe by themselves. OpenAI recommends considering a key management service for production use, while Cursor documents OIDC credentials for cloud agents in the security guidance linked above.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsCompare the controls by what they protect
| Control | Primary purpose | Important limitation |
|---|---|---|
| Tool-level file deny or ignore rule | Keep credential files outside the agent’s accessible context | Product-specific; verify coverage across modes and paths. |
| Environment variables | Keep key values out of source code | An agent or command may still read or print the process environment. |
| Key management service or secret store | Centralize storage and access control | Workload permissions and configuration must be correct. |
| Short-lived credentials or workload identity | Reduce credential lifetime and reliance on persistent keys | Provider and workload support varies. |
| Network-egress restrictions | Limit destinations an autonomous agent can contact | Allow carefully to avoid blocking necessary tasks. |
| Secret scanning and code review | Detect accidental insertion before merge | Detection happens after access or generation and cannot retract a value already sent elsewhere. |
Check changes before committing or merging
- Inspect the diff and generated files. Look for credentials in code, configuration, logs, and other agent-created output.
- Run secret scanning. Use repository scanning or the host’s equivalent before committing and before merging. GitHub says Copilot cloud agent scans generated code for secrets as part of validation: About GitHub Copilot cloud agent.
- Have a person review the changes. GitHub requires human review before a Copilot cloud-agent pull request can merge; Cursor describes a draft pull-request handoff for its cloud agents in the cloud-agent security documentation.
A clean scan is not proof that no secret reached a model, transcript, log, or other destination. Scanners catch recognized patterns in the places they inspect; review is a later detection step, not a substitute for preventing access.
Best Value
- Security Key : Protect your online accounts against unauthorized access by using FIDO2 and U2F authentication with T110. It's the world's most protective security key that works with windows, Mac OS, Linux as well as Chrome, Firefox, Edge and many other major browsers.
- Certified with the new FIDO2 standard, T110 provides the benefit of fast login and strong protection against phishing, account takeover as well as many other online attactks.
- Works with : Bank of America, Github, Google, Microsoft, DUO, Twitter, Facebook, Dropbox, Apple, ebay, BINANCE, mor and more.
- Fits USB-A port : Insert the T110 security key into the USB-A port of each service and log in conveniently with one touch
- For the driver download and user guide, please visit TrustKey Solutions Home support page.
If you may have exposed an API key
- Revoke or rotate it promptly. Issue a replacement and update the legitimate application or workload. OpenAI specifically recommends immediate rotation when a key is believed to be leaked in its API key safety guidance.
- Check account activity. Look for unexpected requests or charges. OpenAI warns that a compromised key can consume account quota and recommends monitoring usage in the same guidance.
- Remove the exposed value where appropriate. Remove it from tracked files and history as needed, but do not treat deletion as a fix: copies may remain in clones, logs, caches, or provider-side systems. Rotation addresses the credential’s validity; cleanup reduces further accidental exposure.
What to do if you pasted a key into an AI chat
Treat the key as exposed and rotate or revoke it rather than relying on deleting the message. Then replace it in the authorized workload and review account activity for unexpected use. If the key was also committed or printed into logs, clean up those copies as part of the response.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




