Skip to content

sandbox: stop banning cd/pushd in unrestricted mode - #84

Merged
FMXExpress merged 1 commit into
mainfrom
claude/sandbox-cd-gating
May 30, 2026
Merged

FMXExpress merged 1 commit into
mainfrom
claude/sandbox-cd-gating

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

The bug

The shell denylist short-circuited cd / chdir / pushd / popd unconditionally whenever shell_deny_enabled was True, regardless of whether restrict_to_workspace was on. That broke legitimate compile-and-build flows like the Delphi/Windows one:

cmd /c "C:\…\rsvars.bat && cd C:\proj && dcc32.exe probe.dpr"

For users whose config.json had no sandbox section at all — because TConfig defaults to restrict_to_workspace=false + shell_deny_enabled=true, which silently combined to ban cd in unrestricted mode for no actual security benefit. The cd-family only matters when a workspace cwd pin exists; without a pin to defeat, banning them is pure friction.

The fix

Split ForbiddenTokens into two arrays:

Array Size Gated by Examples
ForbiddenTokens 24 (was 28) shell_deny_enabled alone sudo, rm, chmod, chown, kill family, mkfs, diskpart, del, format, …
WorkspaceEscapeTokens 4 (new) restrict_to_workspace AND shell_deny_enabled cd, chdir, pushd, popd

The new check lives in the existing RestrictToWorkspace branch in ShellAllowed, right next to the absolute-path scanner and the traversal-token check. Refusal message names the actual reason ("workspace-escape token … restrict_to_workspace=true pins shell cwd to …") so the model can rewrite with absolute paths inside the workspace instead of bouncing off a generic "forbidden token" error and getting stuck — which is what was happening in the transcript that surfaced this regression.

Verification

Standalone smoke covering all four policy combinations × 11 commands. All 11 assertions pass:

Policy Outcome
unrestricted + deny on (the user's default) cd / chdir / pushd allowed (regression fix); sudo / rm / curl | sh still blocked
restricted + deny on cd / pushd blocked with the new clearer message; sudo still blocked
restricted + deny off cd (relative path) allowed — new gate requires both flags
unrestricted + deny off full passthrough (existing behaviour)

Behaviour preserved verbatim for every non-cd-family entry in the original list. The restrict_to_workspace=true operator loses nothing: the workspace cwd pin, the absolute-path scanner, and the traversal-token check all still fire as before, and the new WorkspaceEscape check joins them inside the same branch.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon


Generated by Claude Code

The shell denylist used to short-circuit cd / chdir / pushd / popd
unconditionally when shell_deny_enabled was True, regardless of
whether restrict_to_workspace was on. That broke legitimate
compile-and-build flows like the Delphi/Windows one
  cmd /c "C:\…\rsvars.bat && cd C:\proj && dcc32.exe probe.dpr"
for users whose config.json had no sandbox section at all —
because TConfig defaults are restrict_to_workspace=false +
shell_deny_enabled=true, which silently combined to ban cd in
unrestricted mode for no actual security benefit. The cd-family
only matters when the workspace cwd pin exists; without a pin to
defeat, banning them is pure friction.

Split ForbiddenTokens into two arrays:

  ForbiddenTokens          (24 entries, was 28) — sudo, rm,
                            chmod, chown, kill family, mkfs,
                            diskpart, del, format, etc. Always
                            checked when shell_deny_enabled.
                            Behaviour preserved verbatim for
                            every non-cd-family entry.

  WorkspaceEscapeTokens    (4 entries, NEW) — cd, chdir, pushd,
                            popd. Checked only when BOTH
                            restrict_to_workspace=True AND
                            shell_deny_enabled=True. Lives in
                            the existing restriction branch in
                            ShellAllowed, right next to the
                            absolute-path scanner and the
                            traversal-token check.

Refusal message for the new check names the actual reason
("workspace-escape token … restrict_to_workspace=true pins shell
cwd to …") so the model can rewrite with absolute paths inside
the workspace instead of bouncing off the generic "forbidden
token" error and getting stuck.

Verified locally:
  make builds clean under FPC 3.2.2.
  Standalone smoke (4 policy combinations × 11 commands):
    - unrestricted + deny on: cd / chdir / pushd ALLOWED (the
      regression fix); sudo / rm / curl|sh STILL BLOCKED
    - restricted + deny on: cd / pushd BLOCKED (intent preserved,
      new clearer message); sudo STILL BLOCKED
    - restricted + deny off: cd (relative) allowed — gate
      requires both flags
    - unrestricted + deny off: full passthrough (existing behaviour)
  All 11 assertions pass.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
@FMXExpress
FMXExpress merged commit fdf5099 into main May 30, 2026
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.

2 participants