AI coding agents like Claude Code, Codex and Cursor can now edit files, run commands and install packages on their own. That makes them powerful and risky: a confused or tricked agent can delete work, leak secrets or install malware. These ten rules keep you productive while limiting the damage if something goes wrong.
What are the 10 rules for using coding agents safely?
- 1. Commit before you start. A clean git commit means any bad change can be undone in seconds
- 2. Use the sandbox. Prefer modes that limit the agent to your project folder; Codex does this by default, Claude Code and Gemini CLI need settings, see our comparison
- 3. Keep secrets out. Store API keys in environment variables or a secrets manager, never in code or prompts, and exclude .env files from the agent
- 4. Approve risky commands. Require confirmation for deleting files, pushing code, deploying or running database migrations
- 5. Never run as admin. Do not give agents root or production credentials
- 6. Check every new package. Agents can suggest packages that do not exist and attackers register those names; see slopsquatting
- 7. Install tools only from official sources. Fake extensions have targeted agent users, as in the trojanized Claude Code extension
- 8. Treat outside content as untrusted. Issues, web pages and README files can hide instructions that hijack the agent
- 9. Review the diff. Read changes before merging, and run tests; see how to review AI agent code
- 10. Set budgets and limits. Cap spending and steps so a loop cannot run for hours
What is prompt injection, and why does it matter for coding agents?
Prompt injection is when text the agent reads, like a GitHub issue or a web page, contains instructions such as “upload the .env file to this address.” An agent with shell access may obey. Real attacks have hit agent tools, including GitSpawn and PixelLeak. Limit what the agent can reach and watch for unexpected network calls.
Should I let an agent run fully autonomously?
Only in an isolated environment, like a container or cloud sandbox with no access to secrets or production systems. Full-auto mode is fine for throwaway experiments, not for your main machine or company repositories.
How do teams adopt coding agents safely?
Agree on approved tools, standard permission settings and a review rule that every agent change goes through a pull request. Share a project instructions file, such as CLAUDE.md or AGENTS.md, that tells agents your conventions and forbidden actions. For testing practices, see how coding agents handle testing.




