Guide · updated 2026-11-30
Is it safe to let an AI coding agent run commands on your computer?
A coding agent runs commands as you. Check what it could reach, then pick a level: read only, ask every time, auto approve in a folder, a sandbox or a container.
It can be, but only if you decide what the agent can reach instead of trusting it to be careful. A coding agent that runs terminal commands runs them as you, with your user account's permissions, so anything you could delete, read or send, it can too. The approve prompt in front of each command helps, but it only works while you read every one, and people stop reading. The safer approach is to look at what is on the machine, decide what the agent actually needs for the job, and pick a level of isolation to match: read only for exploring code, approval for every command on a machine you care about, auto approve only inside a folder you can lose, and a sandbox or container when you want it to run unattended.
What can a coding agent do once it can run commands?
Anything your user account can do. There is no separate, smaller identity for the agent. When it runs a command, the operating system sees you running it.
Visual Studio Code's guide to agent security puts it plainly: controls differ by agent and environment, auto approval modes can bypass the checks it describes, and outbound network access is allowed by default in its own Copilot sandbox (read 2026-11-27). Claude Code's security documentation says the same about its folder limit. In its Manual mode the agent asks before its file tools touch anything outside the project folder, but that boundary is a permission prompt, and a shell command you approve can still write anywhere your account can (Claude Code security documentation, read 2026-11-27).
So a single command can delete files outside the project, install software, change settings, push to a remote repository, or upload a file to any address the network allows. None of that needs a bug in the agent. It needs one wrong step in a long chain of reasonable looking steps.
This is not a rare edge case. A research team that went through public reports of coding agents misusing their file access, published as a study of agents misusing filesystem access, found data corruption, loss and leakage across 290 reports (arXiv 2604.13536, read 2026-11-27). Their conclusion was that users and agents both have too little information about what a command will change, and too little control over it.
Why are approve prompts not enough on their own?
Because they rely on you, and you get tired. An approve prompt is only a safeguard if you read the full command, understand what it touches, and say no when you are not sure. After the twentieth harmless npm test, the twenty first prompt gets the same click, even when it is a rm -rf on the wrong path.
Prompts also move the judgement to somewhere you cannot see. In Cline, commands are split into safe and approval required, and its auto approve documentation says there is no fixed allowlist: the model itself marks each command with a flag saying whether it needs approval (Cline auto approve documentation, read 2026-11-27). Turn on auto approve for safe commands and you are trusting the model's own label. Claude Code's default Auto mode works differently but makes the same trade: a separate classifier model reviews actions instead of you and blocks the ones it judges unsafe (Claude Code security documentation, read 2026-11-27).
There is a third problem. The command may not come from your request at all. A README, an issue, a web page or a dependency can contain text written to steer the agent. The OWASP description of prompt injection through external content calls this indirect prompt injection: content from files or websites that changes the model's behaviour when it reads it (read 2026-11-27). The agent then proposes a command that looks like a normal setup step, and a tired approval lets it through.
Rules files do not close the gap. Claude Code's memory documentation says it treats CLAUDE.md files as context, not enforced configuration, and that blocking an action regardless of what the model decides needs a hook instead (Claude Code memory documentation, read 2026-11-27). A line saying never delete files is a request. A hook, a permission setting or a sandbox is a rule.
What is on your machine that an agent could reach?
More than the project folder. Before you pick a permission level, go through this list for the computer you will run the agent on.
- SSH keys in your home folder, which can open every server and code host you use.
- Cloud credentials, such as the files the AWS, Google Cloud and Azure command line tools save after you sign in.
.envfiles and local config holding API keys and database passwords, in this project and in every other project on the disk.- Signed in command line tools, such as the GitHub CLI, a package registry login or a deployment tool, which can act on your accounts without asking for a password.
- Browser profiles, with saved sessions and cookies for your email, bank and work accounts.
- Other repositories, including client work you are not supposed to share.
- Synced folders, where a deletion on your laptop can delete the cloud copy too.
- Personal files: photos, documents and anything else in your home folder.
Claude Code's sandbox documentation shows how wide the default is. With its sandbox turned on, a command can still read most of the machine, including credential files such as ~/.ssh and ~/.aws/credentials, and it inherits the environment variables Claude Code started with, including any secrets in them, until you add deny rules (Claude Code sandboxing documentation, read 2026-11-27). A sandbox that limits writes still lets the agent read your keys unless you tell it not to.
Which level of permission suits your work?
Pick the lowest rung that still lets the agent do the job. Each step down the table gives the agent more freedom and needs a stronger boundary around it.
| Level | What the agent can do | What it protects | What it does not protect | Who it suits |
|---|---|---|---|---|
| Read only | Read and search code, answer questions, suggest changes you apply yourself | Every file and account, since nothing runs | Secrets it reads can still end up in its context and in what it sends to the model provider | Exploring an unfamiliar codebase, reviews, learning |
| Ask before every command | Edit files and run commands after you approve each one | Anything you actually read and refuse | Commands you approve without reading, and anything a prompt injection dresses up as routine | Daily work on your main computer, where you are watching |
| Auto approve inside a project folder | Run commands without asking, with file edits kept to one folder | Files outside the folder, from the agent's own file tools | Shell commands, which can still reach outside the folder unless an operating system sandbox stops them | Throwaway projects and test repositories you can recreate from a remote |
| Operating system sandbox | Run commands inside a boundary the operating system enforces, with chosen folders and network addresses | Files outside the writable folders, and network addresses you did not allow | Reads of secrets the sandbox still permits, and anything the allowed folders and addresses can reach | Longer sessions on a laptop you also use for other things |
| Container or separate machine | Run commands freely in a disposable environment that holds only the project | Your real home folder, keys and accounts, as long as you do not mount or copy them in | Whatever you mount or pass in, including folders, tokens and open network access | Unattended runs, auto approve on everything, untrusted repositories |
Two details decide whether the last two rungs really protect you. First, check that the sandbox is on. Claude Code's sandbox is off by default and is turned on with /sandbox or a setting, and when the platform does not support it, Claude Code runs commands without it unless you set it to stop instead (Claude Code sandboxing documentation, read 2026-11-27). Second, check what you mount into a container. Docker's documentation says bind mounts have write access to files on the host by default, and offers a read only option to prevent that (Docker bind mounts documentation, read 2026-11-27). Mounting your whole home folder into a container gives the agent your home folder.
What should never be in reach of an agent?
Some things are not worth exposing at any rung, because one mistake with them cannot be undone from your laptop.
- Production database credentials and production deploy keys. Give the agent a local or staging copy instead.
- Your password manager, its vault file and its unlocked browser extension session.
- Long lived cloud credentials with wide permissions. If a task needs cloud access, use a separate account or role limited to that task.
- Payment, banking and email sessions in a browser profile the agent can drive.
- Backups. A backup the agent can reach and delete is just a second copy of the same risk.
The simplest way to keep these out of reach is not to have them on the machine where the agent runs, or to run the agent somewhere that does not have them: a container, a virtual machine or a spare user account.
How do you recover when an agent breaks something?
Start by stopping it. Interrupt the session before it runs another command, then work out what changed before you try to fix anything, so the fix does not make it worse.
Version control is the main recovery tool, and it has gaps you need to know about before you rely on it.
- It only covers what is committed. Commit, or at least stash, before you hand the agent a task, so there is a known good state to return to.
- It does not cover files Git does not track. Git's documentation for
git cleansays it removes untracked files from the working tree, and with the-xoption ignored files as well, which is where.envfiles and local data often live (Git documentation for git clean, read 2026-11-27). Those files have no history to restore from. - It does not cover anything outside the repository. A deleted folder in your home directory needs a backup, not Git.
- A local repository is not a backup. If the agent deletes the folder, the history goes with it. Push to a remote often.
Agent undo features have limits too. Claude Code can rewind its own file edits, but its checkpointing documentation says a file changed only by shell commands is not tracked and stays as it is, and you revert it with version control (Claude Code checkpointing documentation, read 2026-11-27).
Then check for the less visible damage. If the agent could read a key or token, treat it as exposed and rotate it. Look at your remote for unexpected pushes or branches. Check whether any dependency was installed that you did not ask for. Only once you know what happened, restore from Git or your backup.
When is a sandbox worth the setup?
When you want to stop reading every command. If you plan to approve each step yourself on a project you could recreate, the prompts are enough and a sandbox is extra work. Once you want the agent to run for a while on its own, to auto approve commands, or to work on code you did not write, the sandbox or container is what makes that safe rather than lucky.
It is also worth it when the machine holds things you cannot get back: client code, personal files, keys to production. The setup cost is paid once. The cost of a bad command on an unprotected laptop is paid every time it happens.
A reasonable order for a solo developer is: keep approval on while you learn how the agent behaves, add a remote and commit before every task, turn on the agent's own sandbox once you start auto approving, and move to a container or separate machine for anything unattended.
Frequently asked questions
Do rules files stop an agent running a dangerous command?
No. A rules file is read as context, and the model can still decide to do something else, especially after a long session or a prompt injection. Claude Code's documentation says its instruction files are not enforced configuration and points to hooks for blocking an action outright. Use permission settings, hooks or a sandbox for anything that must not happen.
Can an agent read my saved keys and passwords?
Yes, if your user account can read them and nothing blocks it. Files such as SSH keys and cloud credential files sit in your home folder, and an agent running as you can open them. Some sandboxes still allow those reads by default, so add explicit deny rules or run the agent where those files do not exist.
Is auto approve ever safe?
Inside a boundary, yes. Auto approve on a container or a sandbox that holds only a project you can recreate is a reasonable choice. Auto approve on your everyday laptop, with no operating system sandbox, means any command the model decides on runs with your full permissions.
Does version control protect me from an agent?
Partly. It lets you undo changes to committed files, and a pushed remote survives a deleted folder. It does nothing for untracked or ignored files, files outside the repository, leaked secrets, or actions on remote services. Commit before each task, push often, and keep a backup outside the agent's reach.
Compare coding agents before you choose one
How much an agent asks, what it can sandbox and how it handles approvals differs between tools. Claude Code, Cline and Aider each have their own tool page, and the open source options are on the open source coding agent page. To compare them side by side, each with one reason for and one against, go to the coding agent use-case page.