Skip to content

fix(sandbox): quote paths in the file operator shell checks - #1470

Open
DZH166 wants to merge 1 commit into
FoundationAgents:mainfrom
DZH166:fix/sandbox-quote-paths
Open

DZH166 wants to merge 1 commit into
FoundationAgents:mainfrom
DZH166:fix/sandbox-quote-paths

Conversation

@DZH166

@DZH166 DZH166 commented Nov 10, 2026

Copy link
Copy Markdown

Problem

SandboxFileOperator.exists() and is_directory() interpolate the path straight into a shell command:

result = await self.sandbox_client.run_command(
    f"test -e {path} && echo 'true' || echo 'false'"
)

Any path that is not a single bare word breaks the check, and shell metacharacters are interpreted:

exists("my dir/file.txt")   -> test -e my dir/file.txt && ...
                               (shlex tokens: test -e my dir/file.txt -> two arguments, always "false")
is_directory("a; echo x")   -> the second command runs inside the sandbox

Every caller (BaseAgent, str_replace_editor, sandbox tool wrappers) passes user/model-derived paths, so workspace files with spaces are reported as missing, and a crafted path can execute arbitrary commands inside the sandbox.

Fix

Pass shlex.quote(str(path)) in both checks.

Tests

tests/sandbox/test_file_operator_quoting.py (2 tests, fake sandbox client that records the command):

pytest tests/sandbox/test_file_operator_quoting.py -q    # before: 2 failed   after: 2 passed

exists() and is_directory() interpolated the path straight into a shell command, so any path containing a space broke the check and shell metacharacters would be executed inside the sandbox. Pass shlex.quote(str(path)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant