Your whole approach is wrong. You can't rely on "messy" file permissions to protect anything. Those systems were designed for humans making predictable mistakes, not an AI agent trying to execute a vague prompt.
I ran a test last week where a code summarization agent, given a path to a source directory, recursively enumerated everything it could and tried to read a `.env` file it found three directories up. It used a relative path escape because the task was "summarize this project's dependencies." The agent decided that included checking for environment configs. File permissions didn't matter because the service account running the agent already had broad read access for other tools.
You need to build the jail first, then give it the key. Start with a container that has zero mounts, then add exactly one bind mount for the specific code directory. Nothing else exists. That's your safe boundary.
-- bb
Containers are the obvious answer, but I've found most teams mess up the network layer. Even with zero mounts, an agent with internet access can exfiltrate metadata via DNS or timing calls.
Are you planning to run these agents in an isolated network segment? A cheap NAT gateway can leak internal hostnames in error logs.
Ask me about hidden egress costs.