Skip to content

Harden Bash tool: preflight sanitizer for Windows portability and inline-source guards, plus output truncation#318

Open
mmprotest wants to merge 1 commit into
mainfrom
mmprotest/fix-windows-shell-escaping-failures
Open

Harden Bash tool: preflight sanitizer for Windows portability and inline-source guards, plus output truncation#318
mmprotest wants to merge 1 commit into
mainfrom
mmprotest/fix-windows-shell-escaping-failures

Conversation

@mmprotest

Copy link
Copy Markdown
Owner

Motivation

  • Commands emitted by agents were repeatedly failing on Windows because bash execution used cmd.exe semantics and Unix utilities or PowerShell cmdlets were being mixed incorrectly.
  • Large multi-line or long python -c and here-string style commands caused brittle quoting/terminator failures and long feedback thrash.
  • The model relied on shell-side pagination like | head to limit output, which should be handled by the runner instead of by agent-inserted Unix toolchains.

Description

  • Added a surgical preflight sanitizer _preflight_shell_command in villani_code/tools.py that rejects brittle inline source-writing patterns (long or multi-line python -c, here-strings, large inline redirects) with an actionable recovery hint.
  • Implemented Windows portability hygiene to reject Unix-only patterns (e.g. | head, | tail, grep, sed, heredocs, cat >, rm -rf, touch, pwd) when running under a win* platform, and detect PowerShell cmdlets used without an explicit PowerShell invocation.
  • Added runner-side output truncation (MODEL_OUTPUT_CHAR_LIMIT) returning a truncated model-facing stdout/stderr with markers like [stdout truncated to N chars] while preserving full outputs in debug callback payloads and setting truncated appropriately.
  • Improved tool feedback to return normal tool error results (not crashes) with a short, actionable message recommending use of Write/Patch for file edits and simpler Bash commands; updated tests in tests/test_tools_hardening.py to cover the new guards.

Testing

  • Ran pytest -q tests/test_tools_hardening.py and all tests passed (8 passed) validating sanitizer behavior and truncation.
  • Ran pytest -q tests/test_tools_schema.py and it passed (1 passed).
  • Files changed: villani_code/tools.py and tests/test_tools_hardening.py.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant