DEV Community

Qingfeng
Qingfeng

Posted on

Your agent has shell access. So does everything in ~/.aws.

A sandbox decides where the agent may write. It says nothing about what it may read — and the reading is where the damage happens.

The first time I gave a coding agent a shell, I did the responsible thing. I turned on its sandbox. I pointed it at one project directory. I told myself the agent could only touch what I had given it.

Then I watched it run a build.

The build read ~/.npmrc. It read the package manager's cache. It touched a socket under /tmp. It printed a path that started with /home/me/.ssh — not because the agent was curious, but because a tool it invoked had that path baked into its own defaults.

None of that was the agent misbehaving. All of it was ordinary. And a sandbox that draws a line around "your project" has almost nothing to say about any of it, because the line was never the whole story.

The line is drawn around writes, not reads

Nearly every agent sandbox I have used is honest about this in its own documentation, and almost nobody reads that part: the boundary is about where a command may write. Reads are treated as harmless. Reads are how you inspect things. Reads are safe.

Reads are also how credentials leave.

An env dump is a read. cat ~/.aws/credentials is a read. A subprocess that inherits the shell's environment has read your entire secret store without executing a single line that mentions it. The agent does not need to be malicious or even confused. It needs to run one command whose output happens to contain a token, and then that token is in the conversation transcript, in the log, and in whatever context gets summarised and re-sent on the next turn.

I have had exactly this happen with a config file. Not because the agent went looking — because it asked a reasonable question and the answer was the config.

Four things that have to be true before shell access is acceptable

After a few of these, I stopped trying to make the sandbox smarter and started asking a narrower question: can the process read the credential at all?

1. The credential should not be on the filesystem the agent can see.
The strongest version of this is not a permission rule — it is absence. If the secret is not in the container's filesystem, no read reaches it, no matter what the agent invents. Anything short of absence is a policy, and policies have defaults you did not choose.

2. If it must be reachable, make it reachable only at call time, and only for one call.
Attach the secret to the specific tool call that needs it, and let it expire with that call. This turns "the agent has my AWS key for the whole session" into "one command had a scoped token for four seconds." It also makes the audit question answerable later: which call used which credential.

3. Inherited environment is the leak nobody logs.
A subprocess does not need permission to see os.environ. Whatever you export into the parent shell is available to everything downstream, including the tool you forgot about. The fix is boring and effective: do not export secrets into the shell that runs the agent, and if you must, mask them at the point of use rather than storing them in the ambient environment.

4. Audit by hash, not by value.
Here is the trap I walked into: the audit log is itself a read surface. If it records "the agent read the config, here are the contents", you have built a second copy of the secret and given it a longer retention period. Record the fact and the fingerprint — path, time, hash before, hash after — and keep the contents out of it. The log should be able to tell you "this changed" without being able to tell you what it changed to.

What this looks like in practice

I build a runtime called GAL, so I am not a neutral party here — but the design constraint is the one I would hold any tool to: scope every call, log the hash, keep the secret out of the process that does not need it, and make the first irreversible write leave a checkpoint behind it.

That last part matters more than it sounds. The moment an agent has both read access and write access, the interesting failure is not "it deleted a file." It is "it deleted a file, and the reason is buried in a transcript that was summarised three times since."

If you are wiring an agent to a shell this week, the question worth answering before you start is not which sandbox — it is what can this process read, and would I be comfortable if it read it out loud.

If the answer is "the AWS credentials," you have found your first task.

Top comments (0)