Sub topic 5
What an agent can do: shell, file writes, network, credentials
This chapter assumes you know how the agent loop works: the model reads context, picks a tool call, and reads the result. It also assumes you can read basic Python. Here we list what those tool calls can reach, because an injected instruction can only do what the agent is able to do.
Capabilities are the attack surface
Injected text cannot run code by itself. It can only persuade the model to request a tool call. The harm therefore depends on which tools exist and what each one can reach.
The four capabilities
| Capability | Typical use | What an attacker gains |
|---|---|---|
| Shell | Run tests, builds, `git` | Run any command the user's account can run |
| File writes | Edit code, create files | Change source, build scripts, CI files, or agent settings |
| Network | Fetch docs, install packages, call APIs | Send data out, or pull in more hostile instructions |
| Credentials | Push code, call cloud APIs | Act as the user or the CI job |
Shell
A shell is the broadest tool. Most other capabilities can be reached through it. If the agent can run curl, it has network access. If it can run cat ~/.ssh/id_ed25519, it can read files. Restricting the file-edit tool does little while the shell is unrestricted.
File writes
Writes matter beyond the source files. A write to Makefile, package.json scripts, a test file, or a CI workflow becomes code execution the next time someone runs it. A write to the agent's own rules or settings files changes the agent's future behavior.
Network
Network access works in two directions. Outbound requests can carry secrets to an attacker. Inbound content, such as a fetched web page, can carry new injected instructions.
Credentials
Agents usually inherit credentials without anyone deciding that they should. Child processes copy the parent's environment, so a token in your shell is visible to every command the agent runs.
import os
import subprocess
os.environ["DEMO_TOKEN"] = "not-a-real-secret"
# By default the child process inherits the full environment.
inherited = subprocess.run(
["python", "-c", "import os; print('DEMO_TOKEN' in os.environ)"],
capture_output=True, text=True, check=False,
)
print("inherited:", inherited.stdout.strip())
# Passing a minimal environment removes the token from the child.
clean_env = {"PATH": os.environ.get("PATH", "")}
scrubbed = subprocess.run(
["python", "-c", "import os; print('DEMO_TOKEN' in os.environ)"],
capture_output=True, text=True, check=False, env=clean_env,
)
print("scrubbed:", scrubbed.stdout.strip())The first line prints inherited: True and the second prints scrubbed: False.
Common mistakes
- Treating "read-only" as safe. Reading is how secrets are collected.
- Assuming the agent has only the permissions you meant to give it. Check which user, token, and environment variables it actually runs with.
- Forgetting that the agent's permissions combine. File writes plus a shell mean that a written script can be executed.
Exercise
An agent has no network tool, but it can run shell commands. Does it have network access? Explain, and name one other capability that the shell also provides.
Show answer
Yes. The shell can run commands such as curl or git push, which make network requests, unless the environment blocks them. The shell also provides file reads and writes, for example cat on a key file or echo >> script.sh. Restricting a dedicated tool does not help while the shell is open.