Ravindra BagaleCourses & study guides Track your progress
AI CODING ASSISTANTS · CHAPTER 1 · BASICS

Safe Use of AI Coding Assistants (Secrets, Licences, Data)

AI coding tools are useful. They can also leak secrets, suggest code you cannot use, or run a dangerous command. This lesson shows the simple rules that keep you and your company safe.

In short: never paste secrets or .env files, check the licence of suggested code, know what leaves your machine (cloud vs local), follow company policy, and never auto-approve dangerous shell commands.

Why safe use matters

WHY

One pasted API key in a cloud chat can bill your cloud account overnight. One copy-pasted snippet under a strict open-source licence can create a legal problem for your company. One agent command like rm -rf can wipe a folder. Safety is part of the skill, not an extra.

What the risks are

WHAT
  • Secrets: API keys, passwords, .env files, private keys, customer data, production connection strings.
  • Licences: code the AI suggests may match open-source projects. Some licences force you to open your whole product (copyleft). Others are fine for commercial use (MIT, Apache-2.0).
  • Data leaving your PC: cloud assistants send prompts and often parts of your files to a company server. Local tools like Ollama keep the model on your machine.
  • Dangerous actions: agent mode can run shell commands, edit many files, install packages, or push to git if you allow it.
  • Company policy: many Indian IT companies ban pasting client code into public AI tools, or allow only approved tools.

How a safe session flows

1 · Check company policy approved tools only 2 · Block secrets deny .env, keys 3 · Prefer local or private when data is sensitive 4 · Small, clear prompts no customer data 5 · Read every diff + command never blind auto-approve

Rule 1 — do not paste secrets

HOW
  1. Never put .env, credentials.json, PEM keys, or database passwords in a prompt.
  2. In Claude Code, deny those paths in .claude/settings.json (example below).
  3. In Copilot / Cursor / Continue, keep secrets out of the workspace the tool indexes, or add them to ignore lists.
  4. If you pasted a key by mistake: rotate it now (create a new key, delete the old one) in AWS, GitHub, Stripe, etc.
.claude/settings.json
{
  "permissions": {
    "deny": [
      "Read(./.env)",
      "Read(./.env.*)",
      "Read(./secrets/**)",
      "Read(**/*.pem)",
      "Bash(rm -rf:*)",
      "Bash(git push --force:*)"
    ]
  }
}

Rule 2 — check licences of suggested code

  1. If the AI pastes a large block that looks copied from a library, ask: “Is this from an open-source project? Which licence?”
  2. Search a unique line on GitHub. If it matches a GPL or AGPL file and your product is closed-source, do not use it as-is.
  3. Prefer asking the AI to write a small function from a clear spec, not “copy how library X does it”.
  4. When you use a real library, add it through your package manager (pip, npm, Maven) so the licence is tracked.

Rule 3 — know what leaves your machine

SetupWhere code/prompts goGood for
Cloud chat (ChatGPT, Claude web, Gemini)provider serverslearning, public practice code
IDE cloud assistants (Copilot, Claude Code, Cursor cloud models)provider servers + your project contextday-to-day coding under company rules
Local Ollama + Continuestays on your PC (no cloud model call)client code, personal data, offline work
Company private model / VPCyour company's serversenterprise policy
Local does not mean “no risk”. A local agent can still delete files on your disk if you approve bad commands. Privacy and safety are different.

Rule 4 — company policy first

  1. Ask your lead: which AI tools are allowed? Is client code allowed in any cloud tool?
  2. Use only the approved account (often a company Copilot or Claude seat), not your personal free account for office work.
  3. Do not paste customer names, phone numbers, Aadhaar, PAN, bank data, or medical records into any AI.
  4. If policy is unclear, use a local model or write the code yourself until someone confirms.

Rule 5 — never auto-approve dangerous shell

HOW
  1. Keep permission prompts on in Claude Code, Copilot Agent, Cursor Agent, Devin Local, Kiro.
  2. Read every command before Yes. Refuse: rm -rf, mkfs, dd, force-push to main, curl-piped-to-bash from unknown URLs, disabling firewalls.
  3. Prefer Plan mode first for big tasks: the tool lists steps; you approve; then it runs.
  4. On a production server or a shared machine, do not run agent mode at all unless your team has a written process.
Rule: turning off all permission checks on your real laptop or a production server is never worth the speed. One bad command can cost more than a month of AI subscription.

A one-page safe checklist

  • Before: approved tool? secrets out of the folder? policy OK?
  • During: no .env in prompts; Plan mode for big jobs; read every diff and shell line.
  • After: run tests yourself; rotate any key you may have exposed; commit only what you understand.

Quick quiz

1. Should you paste a .env file into ChatGPT to “debug the config”?

No. Redact secrets or describe the keys without values. Rotate any key you already pasted.

2. Cloud vs local Ollama — what is the privacy difference?

Cloud sends prompts/context to a provider. Ollama runs the model on your PC.

3. What should you do before allowing an agent to run a shell command?

Read the full command. Refuse deletes, force-pushes and unknown install scripts.

4. Why check the licence of a big pasted snippet?

It may come from a copyleft project you cannot ship inside closed-source software.

Save tokens and money

SMART AI USE

Safety also saves money: smaller prompts without secrets and logs mean fewer tokens. Put standing deny rules in one short settings file instead of repeating “do not read .env” in every chat.

Save these cards

INTERVIEW CARDAI Coding

How do you use AI coding tools safely?

Never paste secrets or customer data; deny .env in tool settings.
Follow company policy; prefer local models for sensitive code.
Keep shell approval on; read every command.
Ravindra Bagale · ravindrabagale.com/ai-coding
COMPARISON CARDAI Coding

Cloud AI vs local Ollama

Cloud: strong models, code leaves your PC.
Local Ollama: weaker or slower on small PCs, data stays with you.
Ravindra Bagale · ravindrabagale.com/ai-coding
REVISION CARDAI Coding

Safe use in 5

No secrets / .env in prompts.
Check licences of big snippets.
Know cloud vs local.
Company policy first.
Never blind auto-approve shell.
Ravindra Bagale · ravindrabagale.com/ai-coding