#4467: fix: DEFAULT_SANDBOX_WORKSPACE_ROOT respects STATE_DIR
agents
Cluster:
Workspace Path Fixes
## Summary
Fixes #4368
`DEFAULT_SANDBOX_WORKSPACE_ROOT` was hardcoded to `~/.openclaw/sandboxes`, ignoring the `MOLTBOT_STATE_DIR` environment variable. This caused `~/.clawdbot/sandboxes/` to be recreated even when `MOLTBOT_STATE_DIR=~/.moltbot` was set.
## Changes
- Moved the `resolvedStateDir` variable to the top of the file (before `DEFAULT_SANDBOX_WORKSPACE_ROOT`)
- Updated `DEFAULT_SANDBOX_WORKSPACE_ROOT` to use `resolvedStateDir` instead of hardcoded path
- Removed the duplicate `resolvedSandboxStateDir` variable (now reuses `resolvedStateDir`)
## Testing
- Lint: ✅ passed
- Build: ✅ passed
- Awaiting CI for full test suite
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates sandbox path constants so the default workspace root now derives from the resolved global state directory (`STATE_DIR`) rather than always using `~/.openclaw`. It also removes a duplicate “resolved sandbox state dir” variable and reuses the shared resolved state dir for both `DEFAULT_SANDBOX_WORKSPACE_ROOT` and `SANDBOX_STATE_DIR`, aligning sandbox storage with the configured state directory behavior in the rest of the codebase.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- The change is a small refactor in a single constants file: it switches the default sandbox workspace root to be derived from the already-established `STATE_DIR` resolution logic and removes a redundant variable. The new behavior is consistent with how state directory overrides are resolved elsewhere (`src/config/paths.ts`), and there are no new control flows or I/O introduced.
- src/agents/sandbox/constants.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#23085: fix(workspace): respect OPENCLAW_STATE_DIR for workspace paths, fix...
by charojo · 2026-02-22
81.7%
#3967: fix(sandbox): correct workspace prompt path
by sweepies · 2026-01-29
80.7%
#17916: [ fix ] : correct config directory path during onboarding
by Dijo-404 · 2026-02-16
80.5%
#4226: Fix/sandbox containerworkdir rw access
by ozgur-polat · 2026-01-29
79.4%
#5638: fix: rewrite sessionFile paths during state dir migration
by lailoo · 2026-01-31
78.0%
#12368: fix(cron): respect OPENCLAW_STATE_DIR for cron store path
by ComBba · 2026-02-09
77.9%
#7851: feat: secure sandbox defaults for new installs
by ichbinlucaskim · 2026-02-03
77.5%
#20991: fix(sandbox): fall back to gateway UID:GID when no user is configur...
by cluster2600 · 2026-02-19
77.4%
#14810: fix:sandbox file path Inconsistency
by luckylhb90 · 2026-02-12
77.3%
#16922: fix: remove incorrect sandbox file tool guidance
by carrotRakko · 2026-02-15
77.0%