Repository navigation
fix(safety): steps run without a shell; say so, and refuse shell syntax - #27
Conversation
Command steps run without a shell (sandbox: shlex.split, then subprocess.run), but the planner was never told. In the maintainer's retest the model planned `echo 2+2 | bc`, which printed the text "2+2 | bc": echo received "|" and "bc" as arguments. Pipes, redirection, &&, ;, command substitution and globbing all silently do the wrong thing. The planner prompt now says commands run without a shell and what to do instead (one program per step, its own options, file_write to save text); the retry prompt says it in one line. The safety engine refuses a command with an unquoted shell operator or a command substitution, with the reason: "`|` would reach echo as plain text: steps run without a shell. ..." Quoting is honoured as a shell would: grep '<div>', echo "a && b" and awk '$1>5' are ordinary arguments. More specific refusals (find -exec, refused arguments) are checked first, so their reasons win. * src/codebud/safety.py (_OPERATOR_CHARS, _shell_token) (shell_syntax_reason): New. (SafetyEngine._command_refusal): Refuse shell syntax. * src/codebud/planner.py (Planner._render_prompt): Rule 9. (Planner._build_retry_prompt): One line on it. * tests/test_no_shell.py: New file. * docs/chapters/safety-and-sandbox.texi (The Sandbox): Document it. * docs/chapters/development.texi: List the test file. * NEWS: Mention it.
Review summary: correct, after one fix made before pushingOne sweep, locally. Conditions.
Finding, fixed: quoted operators ( Verified:
1827 tests pass. Intended consequence: an unquoted Verdict: correct. I'll merge when CI passes. |
|
Merging. CI is green on all five jobs at CI on the merge is skipped, and why. Measured effect, from |
Command steps run without a shell (the sandbox runs
shlex.splitthensubprocess.run), but the planner was never told. In the maintainer's retest the model plannedecho 2+2 | bc, which printed the text2+2 | bc: echo received|andbcas arguments. The 3B reproduces it in the chat evaluation (#26). Pipes, redirection,&&,;, command substitution and globbing all silently do the wrong thing.Change
grep -c,find -name), andfile_writeto save text. The retry prompt says it in one line.`|` would reach echo as plain text: steps run without a shell. Use one program per step and its own options, or separate steps.Quoting is honoured as a shell would:grep '<div>',echo "a && b"andawk '$1>5'are ordinary arguments.find -exec, the refused arguments.Review (done locally, before pushing)
shlex.splitwords, which drop the quotes, sogrep '<div>' fwas refused as a redirection. Fixed before commit._shell_token) over the raw command line. It tracks single and double quotes and backslash escapes like a shell, and treats each unquoted run of| & ; < >as one operator. It also catches$(and backticks outside single quotes, exactly where a shell would expand them.shlex.shlex(punctuation_chars=True)and showed it can't tell'|'from|.&in a URL is refused, because in shell syntax it is an operator; the model has to quote it.Tests and CI
tests/test_no_shell.pycovers the refused cases (includingecho a|wc -l,ls>out,cat<in,2>&1,$(...), backticks, and operators behindtimeout) and the allowed quoted cases. The full suite passes (1827), and ruff is clean. CI runs once on this head: it changes the safety engine.