check_command
Verify shell command safety by detecting dangerous patterns like rm -rf, reverse shells, and fork bombs before execution.
Instructions
Check if a shell command is safe to execute. Detects rm -rf, reverse shells, fork bombs, curl|sh, etc.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | The shell command to check |
Implementation Reference
- src/core/engine.ts:258-282 (handler)The implementation of the checkCommand logic within the ShellWard class. It splits the command into parts and checks each part against dangerous command patterns.
checkCommand(cmd: string, toolName?: string): CheckResult { const enforce = this.config.mode === 'enforce' const parts = splitCommands(cmd) for (const part of parts) { for (const rule of DANGEROUS_COMMANDS) { if (rule.pattern.test(part)) { const desc = this.locale === 'zh' ? rule.description_zh : rule.description_en const reason = this.locale === 'zh' ? `检测到危险命令: ${truncate(part, 80)}\n原因: ${desc}` : `Dangerous command: ${truncate(part, 80)}\nReason: ${desc}` this.log.write({ level: 'CRITICAL', layer: 'L3', action: enforce ? 'block' : 'detect', detail: reason, tool: toolName, pattern: rule.id, }) return { allowed: false, level: 'CRITICAL', reason, ruleId: rule.id } } } } return { allowed: true } }