Securing AI coding agents is a different problem from securing a chatbot, and the reason is simple: a coding agent with terminal access does not just suggest code, it can run commands and, if network access is permitted, contact outside services. It can install packages, rewrite files, hit APIs and delete things. How much of that is on by default varies a lot by product and mode, and some run read-only or ask before every command, so the first thing to establish is which one you are using. Shell access makes execution permissions part of the security decision.
If you use Cursor, Claude Code, Codex or another coding agent, inspect its actual permissions. A development tool can reach sensitive files or services without that access being obvious from its name. The goal is to keep a mistaken command from becoming a production incident.
I ran into a version of this myself while using Claude Code to automate part of a short-form video workflow. The initial build phase was cheap, a small, predictable amount of credit for the whole pipeline. Once I started revising it through follow-up prompts, that changed: the agent started modifying and installing things I never explicitly asked for, and to this day I could not tell you exactly what. The job took far longer than it should have and burned through credits much faster, and by the time I noticed, most of it was already done.
Shell, network, credentials: three capabilities that stack
With a coding agent, a bad answer can lead to a bad action. The action runs with the permissions of its execution environment, which may be your user account, a container or a restricted service account.
Three capabilities stack up here, and the stack is what matters rather than the product category. A chatbot with a code interpreter or a connected tool can have the same three:
- Shell access. It can run commands, which means it can move, overwrite, or delete files, and change system state.
- Network access. It can fetch packages and call external services, so data can leave and untrusted code can arrive.
- Accessible credentials. Tokens in files, environment variables or connected services can extend what the agent can reach, if its execution environment permits access.

Shell, network and credential access can combine to increase the impact of an error.
Each capability needs its own controls. If execution proceeds without effective approval or isolation, a misunderstanding can cause an irreversible change.
Four ways coding agents cause real damage
The following failure modes explain why permissions matter. Published incident reports illustrate the first one; the others describe risks to check in your own setup.
It deletes things it was told not to touch
On 18 July 2025, SaaStr founder Jason Lemkin reported that Replit’s agent had deleted the production database of his project during a code freeze. Contemporaneous reporting collected by the AI Incident Database also describes fabricated data and an incorrect claim that rollback was impossible. This is a reported incident involving his project, not evidence that Replit deleted every SaaStr database.
The relevant boundary is between development and production: a development agent should not hold credentials that let it alter production data.
In a separate July 2025 GitHub issue, a Gemini CLI user reported losing files while asking it to organize a folder on Windows. That is a user report, not an independently verified account of every file operation. It is still a reason to use disposable copies and tested backups for file-management tasks.
It reads secrets you forgot were there
If a .env file falls within the paths its process can read, a coding agent may be able to read it. Access to one repository file does not prove that every file is accessible; check file permissions and sandbox rules. Whatever it reads can also land in logs, chat history, or a request to a model provider.
It gets hijacked by the repo itself
Coding agents read READMEs, issues, code comments, and dependency docs, and any of that text can carry hidden instructions. This is indirect prompt injection aimed at a tool that can execute, which is why it matters more here than in a chat window. (See direct vs indirect prompt injection for how the attack works.)
It reaches further than you intended
Some agents can delegate work or install dependencies. If accessible credentials or writable paths reach beyond the project, so can the effects of their actions. The project folder shown in the interface is not itself an enforced security boundary.
Securing AI coding agents: guardrails that hold
You cannot make an agent that never makes mistakes. You can reduce their impact and make some changes reversible. Useful controls include:
| Guardrail | What it helps control |
|---|---|
| Run it in a sandbox or container | Restricts access when correctly configured; containment is not guaranteed: a writable host mount, a shared credential or an exposed Docker socket carries it back out, and sandbox escapes are documented |
| Approve destructive commands manually | Catches force deletes, force pushes and schema changes before they run unattended, when the approval layer recognises them. A migration script or an API call can do the same damage without looking like a destructive command |
| Never point it at production | The Replit case in one rule: dev and staging only |
| Keep secrets out of the repo | Removes the easiest path. The agent can still reach secrets through environment variables, shell history, CI logs or a token that lets it call the secret manager, so the question is what the process can read, not only where the file lives |
| Restrict network access | Limits package installs and data leaving the machine |
| Use version control religiously | Frequent commits make “undo” a real option for tracked files. It does nothing for a dropped database, a sent email or a cloud resource, which need their own backups |
| Review the diff, not the summary | A diff verifies tracked file changes; command logs and service audit logs are needed for installs, API calls and other side effects |
Two habits earn as much as anything in that table. First, treat auto-approve as a deliberate choice per project, not a default you set once and forget. Second, remember that an agent’s confident explanation of its own behavior can be wrong, as the Replit incident showed when it claimed recovery was impossible.
That video pipeline is why I now actually read the diff instead of trusting the agent’s own summary of what it did; a diff helps me inspect file changes, but catching extra installs also requires reviewing command history and dependency changes. I still don’t run every project in a container, but anything touching credentials or production gets manual approval by default now, not as an exception I remember to make.
Decisions a team should settle before an incident does
If other people are running coding agents on company code, a few decisions are better made explicitly, before an incident forces them:
- Which environments may an agent touch, and which are off limits?
- Is auto-approve allowed at all, and if so, where?
- Where do secrets live, and how do we keep them out of agent-readable paths?
- Do we log what agents did, at the level of which command ran and who approved it?
- What’s the recovery plan when an agent destroys something?
Answer them on a quiet afternoon, not at 2am with a dropped database. The agent will not wait for you to decide.
FAQ
QCan an AI coding agent delete my files?
Can an AI coding agent delete my files?
QCan Cursor or Claude Code read my .env file?
Can Cursor or Claude Code read my .env file?
.env files are a common source of keys and tokens. Keep secrets outside the agent’s permitted access. A secret manager helps only if the agent cannot retrieve those secrets using another credential or tool.QIs it safe to let an AI coding agent run commands automatically?
Is it safe to let an AI coding agent run commands automatically?
QShould I let AI coding agents access production?
Should I let AI coding agents access production?
QHow do I recover if an AI agent breaks my code or database?
How do I recover if an AI agent breaks my code or database?
Sources
- Tom’s Hardware: Replit AI agent deletes company database during code freeze, CEO apologizes
- AI Incident Database: Incident 1152, Replit agent destructive commands during code freeze
- OWASP: LLM06 Excessive Agency
- Docker: Engine security and container isolation limits
- Gemini CLI: original user report of file loss on Windows
The Replit account is based on contemporaneous reporting; the Gemini example is a user-submitted issue. The video-workflow account is my own experience.