ThisCalculator

Everyday

Keep Secrets Out of AI Coding Assistants

Updated · Standard formula, shown below

AI coding assistants can boost productivity, but they also pose a risk: code you paste into them may be sent to external servers and used for training or review. This guide shows you how to configure tools, adjust workflows, and enforce policies so proprietary code and secrets stay on your machine.

What You’ll Need

  • Access to the settings of the AI coding assistant you use (e.g., GitHub Copilot, Tabnine, Codeium, or an in-house tool).
  • Administrator rights on your computer or IDE if you need to change global settings.
  • A code repository or project where you can test the settings.
  • Optional: a secrets scanning tool (like gitleaks or trufflehog) to verify nothing leaks.

Step-by-Step

  1. Identify what data the assistant sends. Most AI coding assistants send the code you select or the file you have open to their servers. Some also send surrounding context. Check the documentation for your specific tool to see exactly what is transmitted.
  2. Turn off telemetry and data collection. In the assistant’s settings (often in the IDE extension or a web dashboard), disable options like “telemetry,” “usage statistics,” or “improve the product by using my code.” This reduces what is stored, though it may not stop all transmission.
  3. Enable the “do not train” or “no retention” option if available. Many providers offer a setting that tells their servers not to store or train on your code. Turn it on. This is not the same as blocking transmission, but it reduces long-term risk.
  4. Use a local-only or on-premise assistant. If your organization handles highly sensitive code, consider tools that run entirely on your machine or on your own servers. Examples include Tabnine’s Enterprise self-hosted option or open-source local models like StarCoder. This keeps code from ever leaving your network.
  5. Set up a blocklist or ignore files. Some assistants let you specify files or directories that should never be sent. Add files containing secrets, such as .env, config/secrets.yml, or any file with API keys. If your tool doesn’t support this, use your IDE’s file exclusion settings to avoid opening those files while using the assistant.
  6. Use a separate, sanitized workspace for AI experiments. Create a copy of your code with all placeholders for secrets (e.g., YOUR_API_KEY) and use that copy when asking the assistant for help. This way, even if the code is sent, it contains no real secrets.
  7. Adopt a code review process that checks for leaks. Before committing code that was generated with AI, run a secrets scanner. This catches accidental inclusion of keys or tokens that might have been inserted by the assistant.
  8. Train your team on what not to paste. Create a short policy: never paste entire files with secrets, never paste production database credentials, and always redact tokens. Use a code snippet that shows what is acceptable (e.g., a function that uses a placeholder) versus what is not.
  9. Use environment variables instead of hardcoded secrets. Even if code leaks, the actual secret values remain in your environment, not in the code. This is a best practice regardless of AI assistants.
  10. Monitor your assistant’s network traffic (optional). For advanced users, use a proxy or network monitor to see exactly what is being sent. If you see unexpected data, adjust your settings or switch tools.

Common Mistakes

  • Assuming the assistant only sends what you select. Many tools send the entire file or the whole project context. Always check the documentation.
  • Relying solely on the “no training” toggle. That toggle prevents training, but it doesn’t prevent transmission or storage for other purposes. It is not a substitute for blocking sensitive files.
  • Forgetting that comments can leak secrets. A comment like // password: admin123 is still sent. Strip all comments that contain credentials.
  • Using the assistant on a production server. If you SSH into a server and use the assistant there, the code might be sent from the server. Use a local dev environment instead.
  • Not updating the blocklist when new files are added. If you add a new config file with secrets, update your ignore list. Otherwise, it might be sent.

Tips

  • Use a dedicated test repository. Create a repo with dummy data and test your assistant’s behavior there before working on sensitive code.
  • Keep your assistant’s version updated. New versions often add better privacy controls. Check release notes for security features.
  • Use a local model for the most sensitive work. Even if it’s less capable, it’s the only way to guarantee zero transmission.
  • Encourage teammates to report accidental leaks. If someone pastes a secret, rotate the key immediately. Have a response plan ready.
  • Consider a code obfuscation step. If you must ask for help on a sensitive algorithm, replace variable names and logic with generic placeholders that convey the structure but not the actual implementation.

Troubleshooting

My assistant still sends code despite the settings. Some tools ignore certain settings if you are using a free tier. Check your plan’s privacy policy. If you cannot disable transmission, switch to a local tool.

I can’t find the blocklist option. Not all assistants have one. Workaround: use your IDE’s file watcher to automatically close or encrypt files that contain secrets. Or, use a pre-commit hook that removes secrets before you copy code.

The assistant is slow after disabling telemetry. This is unlikely to be related. Check your network connection or try restarting the IDE.

I accidentally pasted a secret. Immediately rotate the credential. If it’s an API key, revoke and regenerate. If it’s a database password, change it. Then, review the assistant’s logs if available to see if it was sent.

My team refuses to follow the policy. Make it easy: provide a script that automatically redacts secrets from the clipboard before pasting. Or, use a shared development environment where secrets are not present in the code at all.

Frequently Asked Questions

Q: Does GitHub Copilot store my code? A: Copilot can store code snippets for product improvement unless you disable that in settings. Enterprise plans offer options to prevent storage. Check your admin settings.

Q: Can I use AI assistants on classified or highly confidential code? A: Generally no, unless you use a fully on-premise solution. Even with privacy settings, there is always a risk of transmission. For classified work, use local models only.

Q: What is the difference between “telemetry” and “training”? A: Telemetry is usage data (like clicks and errors). Training means using your code to improve the model. Both can be disabled, but they are separate settings.

Q: Will using a VPN or firewall block the assistant? A: It can block the connection entirely, which might break the assistant. Better to use the assistant’s built-in controls to limit what is sent.

Q: Are open-source AI assistants safer? A: Not automatically. If you run them locally, yes. If you use a hosted version, the same risks apply. Always check where the code is processed.

Q: How do I know if a secret has leaked? A: Use a secrets scanner on your codebase and monitor for unexpected external connections. Also, check if your API keys appear in public GitHub repositories using tools like GitHub secret scanning.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.