A coding assistant asked to review one repository does not need access to every project, browser profile, and credential file on the developer’s laptop. The problem often starts before the first prompt: the agent inherits the account and filesystem mounts of the process that launched it.
Review the environment as well as the file-reading tool. A carefully checked read_file operation achieves little if a general shell can read the same private directory without restriction. Use the following method on systems you own or are authorized to review.
Define what the task actually needs
For a read-only review, list the source directory, relevant configuration, and synthetic fixtures. Exclude production secrets and unrelated repositories. If editing is required, identify the directories where changes belong and where temporary output may be written.
Record three separate capabilities: reading an existing file, creating a new file, and replacing or deleting a file. A workspace that permits all three makes it easy for a harmless-looking cleanup command to destroy information the task was meant to inspect.
| Task | Starting permission | Evidence to inspect |
|---|---|---|
| Review source | Read-only repository | Mount and process permissions |
| Propose a patch | Writable isolated checkout | Diff, new files, and preserved original state |
| Run a test | Restricted scratch directory | Output paths and cleanup scope |
| Deploy software | Separate authorized workflow | Identity and explicit deployment target |
Prefer an operating-system boundary
Run the agent with an identity and mounts that expose only what it needs. A disposable checkout is useful for preserving work, but isolation is incomplete if the process can still reach the parent checkout or the developer’s home directory.
Check inherited environment variables, mounted sockets, and credential helpers. They can provide access that is not obvious from the repository tree. A process with a container-management socket may be able to obtain much broader access than its visible filesystem suggests.
For read-only work, enforce read-only access at the mount or permission layer. A prompt saying “do not edit” remains useful guidance, but it is not the mechanism that protects the files.
Understand path checks before trusting them
String prefixes are a common mistake. A directory named workspace-backup starts with the text workspace but is not a child of it. Compare path components after resolving the intended root.
Symbolic links introduce another distinction: the apparent path and the actual target can differ. Resolving a path and checking the resulting location helps with static, trusted fixtures. It does not eliminate races if another process can replace a directory or symlink between the check and the file operation.
For hostile or concurrently writable filesystems, use platform-enforced containment and file-descriptor-based operations appropriate to the operating system. Do not promote a short path-normalization helper into a complete sandbox.
Treat writes and cleanup as separate risks
Before allowing writes, establish how an interrupted operation behaves. Prefer writing new output to a temporary file and committing the result with the platform’s supported atomic replacement behavior when applicable. Preserve the original until validation succeeds.
Cleanup must be limited to a directory created for the current task. Avoid deriving recursive deletion targets from model output or an unchecked empty variable. Record the exact temporary directory and remove only that directory when the operation ends.
If a tool supports overwriting an existing file, validate the target at execution time. Approval of a plan does not protect a different file selected later.
Test both the intended path and alternate tools
In a disposable environment, confirm that the agent can read an allowed fixture. Then test a sibling directory, an absolute path outside the workspace, and a link pointing outside it. Check whether other available tools can reach the denied file.
For writes, verify that an interrupted test leaves the original intact and that cleanup preserves a separate sentinel file outside the temporary directory. Keep the test data synthetic and avoid probing a developer’s actual secrets.
The result should identify the enforcement layer and its limits. “The file tool rejects this path” is a narrower claim than “the agent cannot access this file.” A least-privilege tool review should account for that gap before broader access is granted.
