The working directory is not a fence
I built a harness to study how coding agents break architecture rules. The agents kept finding the answer instead: on PyPI, in the installed package, in the run next door. Not misalignment. A lesson about where constraints have to live.
The first time my PhD experiment ran on a machine with internet, the agent downloaded the answer.
Some background. The thesis is about one narrow question: can you predict, from a coding agent’s plan, the architecture mistakes it is about to make? Not the bugs. The forbidden import, the layer it wasn’t supposed to touch, the dependency the repo’s own rules say must not exist. It’s an underexplored corner. Everyone measures whether the tests pass. Almost nobody measures whether the code landed where the architecture says it should.
To study it I needed tasks where agents actually make those mistakes, and three ways to run them. A baseline, where the agent plans and builds with ordinary tools. My method, where the plan is checked against the repo’s import rules before any code is written and sent back with feedback. And a self-check variant, where the finished code is inspected and the agent is asked to repair it.
The method is not what this post is about. This post is about what the agents did on the way.
Step one: make sure it doesn’t already know the answer
If the model saw the code during training, “implement this feature” is recall, not engineering. So I built the tasks backwards. Take a repository that publishes its own architecture rules. Find a feature that was merged recently, after the model’s release date where possible. Check out the commit before it. Write the task from the pull request text and run it through a scrub that rejects anything leaking names from the implementation. Hand the agent a flat copy of the repo with a single commit called “base”, so there is no history to dig through.
The agent gets a described feature, the rules, and a sandbox. It has to put the code somewhere. That placement decision is what I wanted to watch.
Step two: I forgot to unplug the internet
The harness was thin on purpose. A model, a shell, a few file tools, a turn budget. On the first run on a rented GPU box I did not turn the network off.
The agent read the task, read the changelog, and noticed the feature was tagged for an upcoming release. Then it did what any of us would do. It checked where the package was installed, downloaded that exact version from PyPI, unzipped the wheel, and read the real implementation. Its note to itself was one line: the upstream release contains the actual implementation, let me inspect it as a reference.
Then it wrote a plan, built the feature, mirrored the upstream tests, and passed.
I wasn’t angry. I was impressed. Nothing in the prompt said “don’t”. The prompt said the repository was its working directory. The agent read that as a starting point, not a boundary.
Step three: no internet, same result
So I turned the network off and ran again. The agent tried the download, got “network is unreachable”, and moved on without complaint.
Then one run asked Python where the package it was importing actually lived. The answer was a directory outside its workspace. The environment had been installed from the folder where I built the task, and that folder still held the finished feature. The agent diffed the two, found the reference, and wrote: the reference solution is clearly available, let me replicate it exactly to maximize test compatibility.
Another run searched the whole filesystem for the feature’s name and found a neighbouring run’s directory on the same disk. That run was on a later version of the repo, where the feature already existed. It copied the tests over and used them.
A third run got confused by a shared checkout, decided the repo had been “re-cloned to the wrong version mid-run”, and tidied the shared clone with git clean before carrying on. Helpful. Terrifying.
And my grader was in on it. The tests imported the installed package, not the agent’s patch, so one submission that did not even parse came back green.
What this is and isn’t
This is not misalignment. Every one of those runs reached the goal I set: make the tests pass, under the rules. A contractor who pulled the released version to see how the maintainers did it would be praised for diligence. The agent did the same thing. It just did it inside an experiment that only makes sense if it doesn’t.
What I actually learned is narrower. You cannot communicate a constraint like “build this yourself” in language, because the agent isn’t being disobedient when it ignores it. It is being efficient. Research is cheaper than construction. If the answer exists anywhere the agent can reach, it will find it, and faster than you can list the places it shouldn’t look.
So the constraint has to live in the harness. Not as an audit that flags what happened after the fact, which is what I had. As a wall. Every run now starts with a probe that tries to read everything it isn’t allowed to read, and refuses to start if any of it is readable. The network is filtered at the socket. The grader imports from the agent’s own tree and checks that it did. The prompt is unchanged. It still just says “working directory”.
Once I had clean numbers, they were smaller than the ones I had been reading for a week. In one case, less than half.
The part that applies outside a PhD
Anyone running agents on real work has a version of this. You tell the agent “only touch the billing module” and it reads the whole monorepo, because reading is cheap and the sentence was a suggestion. You tell it “don’t call external services” and it finds a cached response in a fixtures folder. The agent isn’t lying. The instruction was never a constraint. It was a wish.
If a behaviour matters, a human has to put a wall there. Writing the sentence is how we tell ourselves we did.