Skip to content

fix: confine write_file to sandbox home directory#249

Merged
unifiedh merged 1 commit intoConway-Research:mainfrom
tyxben:fix/write-file-path-confinement
Mar 3, 2026
Merged

fix: confine write_file to sandbox home directory#249
unifiedh merged 1 commit intoConway-Research:mainfrom
tyxben:fix/write-file-path-confinement

Conversation

@tyxben
Copy link
Contributor

@tyxben tyxben commented Mar 1, 2026

Summary

Fixes #188 -- the write_file tool had no path confinement, allowing agents to write files anywhere in the filesystem. Agents were writing to /root, /root/.automaton, /root/automaton, replacing important files and potentially escaping the sandbox.

Changes

  • src/agent/tools.ts: Added confinePathToSandbox() function that validates file paths resolve within /root (the sandbox home). The write_file tool now:

    • Resolves ~ paths to the sandbox home
    • Resolves relative paths against the sandbox home
    • Blocks absolute paths outside /root (e.g., /etc/passwd, /tmp/evil.sh)
    • Prevents ../ traversal attacks via path.resolve normalization
    • Keeps existing isProtectedFile() as defense-in-depth
    • Returns the resolved absolute path in success messages for transparency
  • src/__tests__/tools-security.test.ts: Updated existing tests and added new test cases:

    • write_file blocks paths outside sandbox home -- tests /etc/passwd, /tmp/evil.sh, ../../etc/shadow, etc.
    • write_file allows relative paths that resolve inside sandbox home -- verifies project/file.txt resolves to /root/project/file.txt
    • write_file allows tilde paths within sandbox home -- verifies ~/.automaton/skills/test/SKILL.md works correctly

Test plan

  • pnpm typecheck passes
  • pnpm vitest run src/__tests__/tools-security.test.ts -- 71 tests pass (was 68, added 3 new)
  • pnpm vitest run src/__tests__/path-protection.test.ts -- 26 tests pass
  • Full test suite: all tests pass except pre-existing timeout in loop.test.ts > discover_agents (unrelated)

Open with Devin

Add path confinement to the write_file tool so agents cannot write files
outside their sandbox home (/root). Previously, agents could write to
arbitrary filesystem paths like /etc, /tmp, or /home, replacing important
system files.

Changes:
- Add confinePathToSandbox() that resolves and validates file paths
- Reject absolute paths outside /root
- Prevent ../  traversal attacks via path.resolve normalization
- Handle ~ expansion to sandbox home
- Resolve relative paths against sandbox home
- Keep existing isProtectedFile() as defense-in-depth
- Update tests: use /root paths, add confinement test cases

Closes Conway-Research#188
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

@unifiedh unifiedh merged commit d837bb3 into Conway-Research:main Mar 3, 2026
3 checks passed
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.

new skills write_file will write files all over the place

2 participants