Sub topic 5
What an agent can do: shell, file writes, network, credentials
This chapter assumes you know the agent loop from the earlier chapters: the model reads context, picks a tool call, and receives the result. It also assumes basic command-line use and the ability to read short Python snippets. Here we look at what those tool calls can reach. An injected instruction can only do what the agent is able to do, so the agent's capabilities set the upper limit on the damage.
Capabilities come from tools, not from the model
A language model produces text. It affects the world only through tools that the agent program runs on its behalf. Each tool runs with the permissions of the user or service account that started the agent. The model does not add permissions of its own, and it does not enforce any limits of its own either.
Most coding agents expose four groups of capability:
| Capability | Typical tools | What it can reach | What misuse looks like |
|---|---|---|---|
| Shell | run command, run tests, package install | Anything the user account can execute | Deleting files, running a downloaded script, starting a background process |
| File access | read file, edit file, search | Files in the repository and often outside it | Reading `~/.ssh`, rewriting a CI workflow, planting a backdoor |
| Network | fetch URL, web search, `curl`, package managers | Any host the machine can reach | Sending data to an attacker's server, pulling attacker-controlled code |
| Credentials | Environment variables, config files, tokens, signed-in CLIs | Whatever those secrets authorize | Pushing commits, opening pull requests, calling cloud APIs |
These groups overlap. A shell can read files, open network connections, and use any credential it can find, so shell access alone covers all four rows.
Shell access
The shell is the broadest tool. Agents use it to run tests, build projects, and inspect git history, and each of those is a normal task. But the same tool accepts any command string the model writes. If the model has been steered by injected text, the command is still just a string in a tool call.
Three properties of the shell matter for security:
- Inherited identity. The command runs as you. It can use your git configuration, your SSH agent, and your logged-in command-line tools.
- Composition. A harmless-looking command can wrap a dangerous one.
pytestruns test code from the repository, andnpm installruns install scripts from dependencies. Approving the outer command approves whatever the repository's code does inside it. - Persistence. A command can modify shell startup files, add a git hook, or leave a background process. The effect can outlast the agent session.
File writes
Writing files looks safe because git can undo most changes. That view misses two cases.
First, some files change what runs later. Edits to a CI workflow, a Makefile, a test fixture, a package script, or a git hook run with whatever privileges that later process has. A small edit made now can execute in a CI job with secrets next week.
Second, files outside the repository are not covered by git history. An agent that can write anywhere in your home directory can alter shell startup files or other tools' configuration. Many agents confine writes to the working directory by default, but the confinement is a setting of that agent, so check it instead of assuming it.
Reading files is also a capability. Many secrets sit in plain files in predictable places. You can check what exists in your own home directory:
ls -a ~ | grep -E '^\.(ssh|aws|npmrc|netrc|git-credentials|pypirc)$'Any name this prints is a file that a shell-capable agent running as you could read.
Network access
Network access has two roles, and they carry different risks.
- Inbound. The agent fetches web pages, documentation, packages, and API responses. This is a main route for untrusted content to enter the context, covered in the earlier chapter on sources.
- Outbound. The agent, or code it runs, sends data to a host. This is a route for data to leave. The chapter on exfiltration channels covers the variants.
A single fetch tool does both at once. A request to https://example.com/page?q=anything retrieves content and also tells that server everything placed in the URL. A model that has read a secret can include it in a URL without any other tool.
Credentials
Credentials are the most valuable thing an agent can reach, and they arrive through several routes:
- Environment variables inherited from your terminal, such as
GITHUB_TOKENor cloud keys. - Files in your home directory, such as the ones listed above.
- Authenticated command-line tools. If
ghor a cloud CLI is signed in, the agent can use it without ever seeing the token. - Credentials the agent platform supplies, such as a token that CI mounts for a job.
The last two routes are easy to overlook. An agent can use a signed-in tool without reading any secret, so hiding the token file does not remove the access.
This script lists the environment variable names in your current session that look like secrets. It prints names only, not values:
import os
MARKERS = ("TOKEN", "SECRET", "KEY", "PASSWORD", "CREDENTIAL")
def secret_like_names(env=None):
env = os.environ if env is None else env
return sorted(
name for name in env if any(marker in name.upper() for marker in MARKERS)
)
if __name__ == "__main__":
for name in secret_like_names():
print(name)Run it from the terminal where you normally start your agent. Every name it prints is visible to the agent process and to every command the agent runs, because child processes inherit the environment.
How capabilities combine
An injected instruction is rarely a single step. It chains tools, and each link uses a different capability.
Notice what the chain needs: a way to find a secret, and a way to send it. Removing either link stops this path. This observation drives the next chapter's combination of private data, untrusted input, and an outbound channel, and it is why limiting capabilities works better than trying to detect bad instructions.
Mapping your own agent
Before you decide on defenses, write down the real capabilities of the setup you use. Answer these questions for each agent:
- Which user or service account does it run as?
- Which directories can it read, and which can it write?
- Which environment variables and signed-in tools does it inherit?
- Which hosts can it reach, and does any tool fetch URLs?
- Does it run repository code, such as tests or install scripts, and with what access?
Exercise
An agent runs as you, has no file-read tool, and can only run pytest -q. A repository's tests are attacker-controlled. Name two capabilities from this chapter that the attacker could still reach, and explain why.
Show answer
The attacker could reach the shell-level capabilities of the test process: it can read files and environment variables, because test code runs as your user, and it can use the network, unless the machine blocks outbound connections. The tool list looks narrow, but running repository code gives that code your identity and inherited credentials. Credentials in the environment or in files in your home directory are therefore exposed.
Exercise
Why does hiding ~/.config/gh/hosts.yml from the agent not fully remove its access to your GitHub account when gh is signed in?
Show answer
The agent can run gh commands, and the CLI reads the token itself. The agent uses the access without reading the file or seeing the token. To remove the access, you must stop the agent from running the signed-in tool or run it where that credential is absent.