Validates a bash command against the permitted prefixes.
(command: str, policy: BashToolPolicy)
| 55 | |
| 56 | |
| 57 | def _validate_command(command: str, policy: BashToolPolicy) -> Optional[str]: |
| 58 | """Validates a bash command against the permitted prefixes.""" |
| 59 | stripped = command.strip() |
| 60 | if not stripped: |
| 61 | return "Command is required." |
| 62 | |
| 63 | for op in policy.blocked_operators: |
| 64 | if op in command: |
| 65 | return f"Command contains blocked operator: {op}" |
| 66 | |
| 67 | if "*" in policy.allowed_command_prefixes: |
| 68 | return None |
| 69 | |
| 70 | for prefix in policy.allowed_command_prefixes: |
| 71 | if stripped.startswith(prefix): |
| 72 | return None |
| 73 | |
| 74 | allowed = ", ".join(policy.allowed_command_prefixes) |
| 75 | return f"Command blocked. Permitted prefixes are: {allowed}" |
| 76 | |
| 77 | |
| 78 | def _set_resource_limits(policy: BashToolPolicy) -> None: |