Skip to content

guardrails: block destructive commands in exec_command (fix #952) - #953

Open
fwh888 wants to merge 4 commits into
usestrix:mainfrom
fwh888:main
Open

guardrails: block destructive commands in exec_command (fix #952)#953
fwh888 wants to merge 4 commits into
usestrix:mainfrom
fwh888:main

Conversation

@fwh888

@fwh888 fwh888 commented Aug 1, 2026

Copy link
Copy Markdown

Fix #952: Block destructive commands in exec_command

Problem

Agents (especially smaller/uncensored LLMs) can attempt destructive actions
like DROP TABLE users even when explicitly prompted for non-destructive
actions only. This can cause real damage against live targets.

Fix

Add a lightweight, conservative guardrail layer in front of the exec_command
tool:

  • strix/agents/guardrails.pycheck_destructive(cmd) flags unambiguous
    destructive SQL (DROP/TRUNCATE/DELETE/ALTER ... DROP) and shell commands
    (rm -rf /, mkfs, dd of=/dev/, fork bomb, shutdown, git push --force).
  • strix/agents/factory.py_wrap_exec_command calls the check before the
    SDK runs the command and returns a clear guardrail message instead.

The check is intentionally conservative (only blocks unambiguous
destruction) — it is a safety net, not a policy engine.

Tests

tests/test_guardrails.py:

  • 13 destructive commands → blocked
  • 9 safe commands (SELECT, curl, nmap, sqlmap, ...) → allowed
  • integration: wrapped exec_command blocks DROP TABLE without invoking the
    underlying tool; safe commands pass through

This addresses the issue's recommended approach #3 (safety layer) in the least
invasive way — no new config, no prompt changes, no CLI changes.

@greptile-apps

greptile-apps Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds a pre-execution guardrail around exec_command to reject selected destructive SQL and shell commands.

  • Adds regex-based SQL and shell command classification.
  • Wraps command execution with an early rejection path.
  • Adds unit and wrapper integration coverage.

Confidence Score: 4/5

The PR is not yet safe to merge because destructive DELETE and force-push forms still bypass the guardrail, while the documented operator opt-out remains ineffective.

Quoted DELETE targets and common force-push option forms do not match the new patterns and therefore reach the underlying command tool, and the wrapper applies the guardrail without consulting the documented environment override.

Files Needing Attention: strix/agents/guardrails.py and strix/agents/factory.py

Important Files Changed

Filename Overview
strix/agents/factory.py Adds the guardrail check before applying shell defaults and invoking the underlying execution tool; the documented opt-out remains unwired.
strix/agents/guardrails.py Introduces destructive-command patterns, but quoted DELETE targets and common force-push syntax remain reachable bypasses.
tests/test_guardrails.py Covers representative blocked and allowed commands but omits the previously reported bypass forms and environment opt-out behavior.

Reviews (2): Last reviewed commit: "guardrails: fix rm -rf path coverage and..." | Re-trigger Greptile

Comment thread strix/agents/guardrails.py Outdated
Comment thread strix/agents/guardrails.py
Comment thread strix/agents/guardrails.py
@fwh888

fwh888 commented Aug 1, 2026

Copy link
Copy Markdown
Author

🔧 Hardened after internal AI audit (TriForge v3)

Cross-audit found 3 issues in the initial guardrail regexes — now fixed:

  1. HIGHrm pattern only matched /, /*, ~/*; missed rm -rf /home/user etc.
    → now matches any target: rm -rf + \S+ (recursive force delete is destructive anywhere)
  2. MEDIUM — SQL DELETE FROM pattern required line-end $, missing DELETE FROM users WHERE id=1
    → removed the anchor
  3. LOWstr | NoneOptional[str] for Python <3.10 compat

Verified:

  • rm -rf /home/user → blocked ✅
  • DELETE FROM users WHERE id=1 → blocked ✅
  • SELECT * FROM users → allowed ✅

Conservative by design: in a pentest agent, any rm -rf is refused (operator can opt out with STRIX_ALLOW_DESTRUCTIVE=1).

@bearsyankees

Copy link
Copy Markdown
Collaborator

@greptile

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