#5952: feat(tools): add fs.restrictToWorkspace config option
docs
gateway
agents
Cluster:
Sandbox File System Fixes
## Summary
Adds a new configuration option `tools.fs.restrictToWorkspace` that restricts `read`, `write`, and `edit` tools to the agent's workspace directory **without requiring Docker sandbox**.
## Motivation
Currently, the only way to restrict filesystem access to specific directories is through Docker sandboxing. However, many users:
1. Don't have Docker installed or don't want to run Docker
2. Trust the agent but want guardrails against accidental access to sensitive files
3. Want a lightweight security layer without container overhead
The path validation logic already exists in `sandbox-paths.ts` — this PR exposes it via config.
## Changes
- **`src/config/types.tools.ts`**: Added `FsToolsConfig` type with `restrictToWorkspace` option
- **`src/config/zod-schema.agent-runtime.ts`**: Added `ToolsFsSchema` for validation
- **`src/agents/pi-tools.ts`**: Modified tool creation to use sandboxed tools when `restrictToWorkspace` is enabled
- **`docs/gateway/configuration.md`**: Added documentation
## Usage
```json5
{
tools: {
fs: {
restrictToWorkspace: true
}
}
}
```
When enabled:
- `read`, `write`, and `edit` tools are restricted to the workspace
- Path traversal (`../`) is blocked
- Symlinks pointing outside workspace are blocked
## Notes
- This only restricts filesystem tools — `exec` can still access the full filesystem unless Docker sandbox is also enabled
- The implementation reuses the existing `wrapSandboxPathGuard` / `assertSandboxPath` logic
Closes #5948
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR introduces a new config surface `tools.fs.restrictToWorkspace` (types + runtime zod validation) and wires it into tool construction so `read`/`write`/`edit` can be restricted to a workspace-root path guard even without Docker sandboxing. It also documents the new option in the gateway configuration docs.
Main thing to double-check is how this interacts with sandbox mode and with per-agent config: in `createOpenClawCodingTools` the new flag won’t have any effect for write/edit when `sandboxRoot` is present (those tools are still removed), and `AgentToolsSchema` currently doesn’t accept `tools.fs` so the setting is global-only even though it’s described generically in docs.
<h3>Confidence Score: 3/5</h3>
- This PR looks mostly safe, but has a couple of configuration/behavior mismatches worth fixing before merge.
- Core change is localized and reuses existing path-guard tooling, but there are edge-case behavior differences: the new option currently can’t be set per-agent due to zod `.strict()` in `AgentToolsSchema`, and enabling it alongside sandbox mode doesn’t yield the expected restricted write/edit behavior. These are likely to surprise users and should be clarified or adjusted.
- src/agents/pi-tools.ts and src/config/zod-schema.agent-runtime.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#23486: Tools/FS: default host-mode filesystem access to workspace-only
by bmendonca3 · 2026-02-22
80.0%
#3907: fix(sandbox): use absolute /bin/sh path + add allowedReadPaths config
by pvoo · 2026-01-29
76.7%
#8846: fix(tools): block LLM writes to hooks directories
by yubrew · 2026-02-04
76.5%
#11820: fix(sandbox): remap container paths in sandboxed file tools
by steflsd · 2026-02-08
76.0%
#4022: fix: apply sandbox tools denials in /tools/invoke
by davidbors-snyk · 2026-01-29
75.9%
#19344: fix(sandbox): allow writes when workspaceAccess is 'none'
by mingming099 · 2026-02-17
75.6%
#16043: fix(sandbox): align fs-bridge and fs-paths write checks with tool-g...
by steflsd · 2026-02-14
75.1%
#18022: feat(tools): Structured Config Editor for JSON/YAML/TOML
by stakeswky · 2026-02-16
75.0%
#7851: feat: secure sandbox defaults for new installs
by ichbinlucaskim · 2026-02-03
74.8%
#16509: Fix sandbox path validation rejecting Docker bind mount paths
by Clawborn · 2026-02-14
74.3%