[Bug] Confine the autonomous-loop file tools to the agent workspace (#1791) - #1815
Open
ayaangazali wants to merge 1 commit into
Open
[Bug] Confine the autonomous-loop file tools to the agent workspace (#1791)#1815ayaangazali wants to merge 1 commit into
ayaangazali wants to merge 1 commit into
Conversation
|
Hello there, thank you for opening an PR ! 🙏🏻 The team was notified and they will get back to you asap. |
ayaangazali
force-pushed
the
security/confine-file-tools-to-workspace
branch
from
August 6, 2026 17:17
198830a to
528d244
Compare
Contributor
Author
|
Rebased onto current master
On the red checks, for the record, since none of them are caused by this PR. Pulled from this PR's own fresh job logs:
Master itself is red on the same set, so the signal here is "unchanged from base" rather than "passing". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1791
Problem
The built-in file tools in
max_loops="auto"have no path confinement. The model picksfile_pathitself, so any prompt injection reaching the loop, a fetched web page, a file the agent was asked to summarise, a sub-agent's task string, becomes arbitrary local file read, overwrite or deletion under the host process's privileges.Reproduced on master
06413ebcwith a tmp workspace and a secret one level above it:Six tools shared the same two-hole resolver,
read_file_tool,create_file_tool,update_file_tool,list_directory_tool,delete_file_toolandgrep_tool:Fix
One resolver, six call sites, no per-tool guards:
realpathis what makes it hold: it collapses..and follows symlinks before the containment test, so neither can step outside. Each tool's six-line resolve block becomes one line, and theValueErrorlands in theexcept Exceptioneach tool already has, so the model gets the usual error string rather than a traceback. Net +43/-45 in one source file.Absolute paths are still accepted when they point inside the workspace, so the check is containment rather than "relative only" and nothing legitimate is lost:
swarms/tools/computer_use.pyalready has the right primitive in_check_realpath, butcreate_computer_use_toolshas no call sites inswarms/, so the loop never saw it. I kept this fix local toautonomous_loop_utils.pyrather than rewiring the loop onto that module, which is a much larger change.This is also the piece that makes #1751's proposed default policy safe: that issue auto-approves
read_file,grepandlist_directory, which under master means auto-approving arbitrary filesystem reads.Test
New
tests/structs/test_autonomous_loop_file_confinement.py. There is no existing test module forautonomous_loop_utils.py, so this is a new file rather than an addition to one. No agent and no network: the workspace is atmp_pathand the agent is a mock that only answers_get_agent_workspace_dir.Two tests. The first drives all six tools at an escape path, by
..and by absolute path, and also asserts the secret's contents are unchanged aftercreate_fileandupdate_fileare pointed at it. The second pins that ordinary workspace access still works, including absolute paths inside it.On master:
Both pass on this branch.
tests/structs/test_async_subagent.py, the only other suite touching these tools, is unchanged.tests/structs/test_agent.pyis 21 failed / 41 passed / 8 errors both before and after, all pre-existing.black --checkandruff checkclean at line-length 70.I use Claude Code to help me work through these and I reproduce every claim before opening anything. Since this one is a hardening change rather than a crash fix, if you would rather it warn instead of refuse while you assess the blast radius, that is a one-line change and I will send it.
🤖 Generated with Claude Code