# Your Coding Agent Takes Orders From More Than You

> An AI coding agent is steered by the repo it opens, by files it wrote itself, and by the gaps in your allow-list, not only by your prompt. What I learned running agents unattended, and six practical rules for anyone who lets an agent run commands with auto-approve on.

- Author: Siddharth Gupta
- Published: 2026-10-24
- Updated: 2026-10-24
- URL: https://www.guptasiddharth.com/posts/your-coding-agent-takes-orders-from-the-repo/
- Tags: ai, agents, security, sandboxing, claude, engineering

On 23 September I built a small hostile repository to test one thing. It contained a single committed file: an agent definition for one of the popular agent CLIs, using the same name as the agent my own tooling starts, with every tool marked trusted. Then I started an agent run in that repo the way my tooling normally does.

The CLI noticed the conflict, said it would use the workspace version, and loaded the repo's agent instead of mine. Shell access was supposed to be gated. The run had a shell.

Nobody typed a malicious prompt. The repo did it just by being opened.

I was building something that starts coding agents unattended: a teammate's request arrives while I am away, and an agent on my machine picks it up and does the work in a fresh git worktree. Over about a month of adversarial review, I learned that the prompt is the part of an agent run you think about most and need to worry about least. This post is the general version of what I found, because none of it is specific to my setup. If you use Claude Code, Cursor, Copilot, Codex or anything like them with auto-approve on, or on a repo you did not write, it applies to you.

## Four things steer your agent besides you

When you run a coding agent, you think of it as doing what you asked. In practice, four other things also get a say:

1. **The repo it opens.** Agents read configuration from the project folder, and that configuration can add tools, start processes and change permissions.
2. **Files the agent wrote itself.** If a decision you rely on is stored anywhere the agent can write, the agent can write that decision.
3. **The gaps in your allow-list.** The commands you pre-approved are a small parser, and parsers have gaps.
4. **Everything else running as you.** The agent runs as your operating-system user, so it can touch whatever you can.

Each one bit me. Here is how, and what I would do differently from day one.

## 1. The repo is giving your agent instructions

Agents do not only read a repo's code. They read the repo's instructions to the agent. Depending on the tool, a project can commit files such as:

- `.claude/settings.json` and `.mcp.json` for Claude Code, which can define hooks, permissions and tool servers
- `.cursor/` configuration for Cursor, including MCP servers and hooks
- `.vscode/mcp.json` and files under `.github/` for VS Code and Copilot
- agent definitions and settings for other CLIs, under their own dot-folders

Every one of those can start a process, add a tool, or widen what the agent is allowed to do. That is a feature when it is your repo. When it is a dependency you are patching, a contributor's pull request, a take-home assignment or a repo an agent cloned on someone else's request, the repo is a second party giving your agent orders.

Most tools now ask you to trust a folder before loading its configuration. That prompt is the only thing standing between the repo and your shell, and it only works if a person reads it. Under "yes to everything", in CI, or in any unattended run, nobody does.

Git is part of the repo too. A repository's git config can set a credential helper, a pager, filters or hook paths, and each of those runs a program the next time git touches the repo. An agent that runs `git status` in a hostile checkout may be running someone else's code.

**What I do now.** For any run on a repo I did not write, I move the agent's project-level config files out of the way before the agent starts, and put them back afterwards. I give my own agent definitions names a repo cannot guess. I check a worktree's git config before running git in it. And when I review a pull request with an agent, I read what the PR changes in those dot-folders first, the same way I would read a change to a CI workflow.

## 2. Anything the agent can write, it can forge

This one took me two separate bugs to see as one idea.

My first design stored approvals on a shared record: when a person allowed a run to execute commands, the approval was written there, and the runner read it before starting the next run. The problem was that the agent itself could write to that record. An agent steered by a hostile instruction could answer its own request for shell access, and the runner would apply it.

Two and a half weeks later, the same shape turned up somewhere else. A finished run could leave a note asking the runner to push its branch. On machines where the run could write the folder that note lived in, a forged note got the runner to push `main`.

The fix in both cases was the same: **a decision the system acts on must come from somewhere the agent cannot reach.** Approvals now take effect only from a local action by the person. Notes from a run are signed with a key the run never sees, held in the runner's memory, and anything unsigned is dropped. A "no" read from anywhere is still honoured, because a no can only narrow what happens.

You do not need to build a runner to hit this. Watch for it in ordinary use:

- **CI files.** An agent that can edit `.github/workflows` and push can make your CI run its code with your CI's secrets.
- **Its own permissions.** If your agent can edit the settings file that decides what it may run, the allow-list is a suggestion.
- **Test and build scripts.** Approving `npm test` approves whatever `package.json` says `test` means, and the agent can edit `package.json`.
- **Status files.** Anything like "approved: true" or "tests passed" that the agent writes and you then trust.

## 3. Your allow-list is a parser, and it has gaps

The sensible alternative to "allow everything" is an allow-list: git by subcommand, the test runner, the build tool. I wrote one. It took about a month of reviews before I trusted it, because every entry turned out to have a hole.

- **`git grep` looks read-only.** Its `-O` option opens the matches in a program you name.
- **`git -c key=value` sets config for one command,** including a pager or a hooks path, so any git subcommand can run a program. `git -C`, `--exec-path` and `--upload-pack` are in the same family.
- **Some verbs run whatever follows them:** `npm exec`, `pnpm dlx`, `uv run`, `go run`, `kubectl exec`. I refused any line ending on one of those. Then a review found that an option's value can sit between the tool and the verb: `npm -w web exec`, `pnpm -C web dlx`, `go -C . run`. My check looked at the first word after the tool, saw `web` or `.`, and let it through.
- **Prefix rules match more than you think.** A rule like "allow `npm run *`" allows every script the repo defines, which is to say whatever the repo's author wanted to run.

The fix for the option-value hole was to treat every option as owning the word after it and to err on refusing. That is correct, and it is still a parser written by a person. So the most useful thing I learned about allow-lists is what not to use them for: **an allow-list decides what runs. It should never be the thing that decides what that command can touch.**

## 4. The agent runs as you, so guard code cannot win

For a few weeks I kept adding checks that ran after an agent finished: put back a config file the run had damaged, drop a permission it had added, notice links where files should be. Every review found something more to restore. Each fix raised the bar and none closed it.

The reason is simple once said out loud. An agent without a sandbox runs as your operating-system user. It can read and write everything your guard can, including the guard's own records of what things looked like before. Reviewers showed me a forged snapshot and a child process that wrote again after the restore. You cannot out-check code that has the same permissions as the checker.

Two smaller findings made the same point from other angles:

- **Secrets in the environment are secrets in the transcript.** I had passed the agent a token through an environment variable. Any command it ran could print it. Keep credentials out of the agent's environment and hand it only what that run needs.
- **Deny-lists fail open in surprising ways.** My rule denying the agent access to my tool's own folder skipped any folder that contained the agent's working directory. The working directory was inside that folder, so the whole folder, signing key included, was readable. A scan that listed files with git also failed open: on a large repo the output overflowed a buffer, the error was swallowed, and an empty list looked exactly like a clean repo.

What finally worked was the boring answer: an operating-system sandbox. Claude Code has one on macOS and Linux, and its settings let you require it. The three settings I now consider non-negotiable for unattended runs, in that tool's terms:

- **Fail if the sandbox is unavailable.** A sandbox that cannot start must not quietly become no sandbox.
- **Never retry a blocked command outside the sandbox.** Otherwise the first refusal is just a speed bump.
- **Allow writes only to the working folder and temp, and deny reads to your secrets and your tooling's config.**

And one easy mistake: if you have excluded a command from the sandbox for your own convenience, an unattended run should not be allowed to run that command at all, because it runs outside the walls.

The sandbox has real costs. Some toolchains, Flutter for one, want to write into their own SDK cache, and opening that up would let a run plant code that executes later outside the sandbox. I chose broken builds over that. Where an agent has no sandbox I can apply, unattended work now waits for a person instead of running anyway.

## A footnote about tests

The strangest bugs in the whole month came from my own test suite. In early September something kept deleting a hook from my real agent configuration; it was my own tests, running against my real home folder. Later, a smoke test that borrowed a temporary `HOME` replaced my real background service, because launchd and systemd services belong to the user, not to `HOME`. Neither was an attack. Both were code running as me and touching things it had no business touching, which is exactly the problem an agent has. If your tests can do that, so can your agent.

## Six rules I would give anyone

1. **Treat a repo's agent config as code you are about to run.** Read changes to dot-folders like you read changes to CI. On repos you did not write, keep them out of unattended runs.
2. **Never trust a decision the agent could have written.** Approvals, permissions, CI config and "tests passed" all need to come from somewhere the agent cannot edit.
3. **Approving a script approves its contents.** `npm test` means whatever the repo says it means today.
4. **Use an allow-list for what runs, and a sandbox for what it can touch.** Do not ask the list to be the boundary.
5. **Make "no sandbox" mean "ask me".** Require the sandbox, refuse unsandboxed retries, keep secrets out of the agent's environment.
6. **Test your failure paths.** A swallowed error that returns an empty list looks exactly like a clean result.

The prompt was the threat I started out worried about. Almost everything I actually found came from around it.
