fix(sandbox): make /workspace bind mount read-only when workspaceAcce…#32227
Conversation
…ss is not rw This ensures that when workspaceAccess is set to 'ro' or 'none', the sandbox workspace (/workspace inside the container) is mounted as read-only, matching the documented behavior. Previously, the condition was: workspaceAccess === 'ro' && workspaceDir === agentWorkspaceDir This was always false in 'ro' mode because workspaceDir equals sandboxWorkspaceDir, not agentWorkspaceDir. Now the logic is simplified: - 'rw': /workspace is writable - 'ro': /workspace is read-only - 'none': /workspace is read-only
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5ff002a38c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| args.push("--workdir", cfg.workdir); | ||
| const mainMountSuffix = | ||
| params.workspaceAccess === "ro" && workspaceDir === params.agentWorkspaceDir ? ":ro" : ""; | ||
| const mainMountSuffix = params.workspaceAccess === "rw" ? "" : ":ro"; |
There was a problem hiding this comment.
Force container recreation after mount policy change
This mount-mode change only applies when a new container is created, but ensureSandboxContainer reuses existing containers when computeSandboxConfigHash(...) is unchanged; since the hash inputs are config-only, upgrading to this commit leaves already-created session/agent/shared containers with the old writable /workspace mount and the ro/none hardening is silently skipped until manual sandbox recreate. Please version this behavior change (for example via a security epoch in the hash input) so existing containers are automatically rebuilt.
Useful? React with 👍 / 👎.
Greptile SummaryThis PR correctly fixes a security bug where Key changes:
Critical issue:
Confidence Score: 3/5
Last reviewed commit: 5ff002a |
| args.push("--workdir", cfg.workdir); | ||
| const mainMountSuffix = | ||
| params.workspaceAccess === "ro" && workspaceDir === params.agentWorkspaceDir ? ":ro" : ""; | ||
| const mainMountSuffix = params.workspaceAccess === "rw" ? "" : ":ro"; |
There was a problem hiding this comment.
same bug exists in browser.ts lines 240-243 and needs the same fix
| const mainMountSuffix = params.workspaceAccess === "rw" ? "" : ":ro"; | |
| const mainMountSuffix = params.workspaceAccess === "rw" ? "" : ":ro"; |
The identical buggy logic exists in src/agents/sandbox/browser.ts at lines 240-243. It should also be changed from:
const mainMountSuffix =
params.cfg.workspaceAccess === "ro" && params.workspaceDir === params.agentWorkspaceDir
? ":ro"
: "";to:
const mainMountSuffix = params.cfg.workspaceAccess === "rw" ? "" : ":ro";Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/sandbox/docker.ts
Line: 455
Comment:
same bug exists in `browser.ts` lines 240-243 and needs the same fix
```suggestion
const mainMountSuffix = params.workspaceAccess === "rw" ? "" : ":ro";
```
The identical buggy logic exists in `src/agents/sandbox/browser.ts` at lines 240-243. It should also be changed from:
```typescript
const mainMountSuffix =
params.cfg.workspaceAccess === "ro" && params.workspaceDir === params.agentWorkspaceDir
? ":ro"
: "";
```
to:
```typescript
const mainMountSuffix = params.cfg.workspaceAccess === "rw" ? "" : ":ro";
```
How can I resolve this? If you propose a fix, please make it concise.…ad-only when workspaceAccess is not rw The identical buggy logic from docker.ts also exists in browser.ts. Applying the same fix here.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ed98763bff
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| params.cfg.workspaceAccess === "ro" && params.workspaceDir === params.agentWorkspaceDir | ||
| ? ":ro" | ||
| : ""; | ||
| const mainMountSuffix = params.cfg.workspaceAccess === "rw" ? "" : ":ro"; |
There was a problem hiding this comment.
Bump browser hash epoch for mount-mode change
Changing the browser container mount to :ro here does not force existing sandbox browser containers to be recreated, because reuse is still gated by computeSandboxBrowserConfigHash(...) and SANDBOX_BROWSER_SECURITY_HASH_EPOCH, neither of which changed in this commit. In upgrades where a browser container already exists, the old writable /workspace mount is kept and this hardening silently does not apply until a manual recreate, which leaves the intended security fix ineffective for active installs.
Useful? React with 👍 / 👎.
|
Follow-up landed in #32274 to complete maintainer fixups after this PR merged during update:
This keeps the merged behavior fully covered and changelog-complete. |
Summary
Describe the problem and fix in 2–5 bullets:
Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
When workspaceAccess is 'ro' or 'none', the sandbox workspace (/workspace inside container) is now read-only instead of writable. This matches the documented behavior.
Security Impact (required)
Repro + Verification
Environment
Steps
Expected
Actual (before fix)
Evidence
Attach at least one:
Human Verification (required)
What you personally verified (not just CI), and how:
Compatibility / Migration
Failure Recovery (if this breaks)
Risks and Mitigations
List only real risks for this PR. Add/remove entries as needed. If none, write
None.