guardrails: block destructive commands in exec_command (fixes #952)

This commit is contained in:
fwh888 2026-08-01 21:15:52 +08:00
parent a9deb84260
commit edf5b8d13f

View file

@ -16,6 +16,7 @@ from agents.tool import CustomTool, FunctionTool, Tool
from pydantic import ValidationError
from strix.agents.prompt import render_system_prompt
from strix.agents.guardrails import check_destructive
from strix.config import load_settings
from strix.tools.agents_graph.tools import (
agent_finish,
@ -281,6 +282,10 @@ def _wrap_exec_command(tool: FunctionTool) -> FunctionTool:
parsed = json.loads(raw_input)
except (json.JSONDecodeError, TypeError):
parsed = None
if isinstance(parsed, dict) and "cmd" in parsed:
reason = check_destructive(parsed.get("cmd", ""))
if reason:
return f"[guardrail] blocked destructive command: {reason}"
if isinstance(parsed, dict):
if "shell" not in parsed:
parsed["shell"] = "bash"