Skip to main content
Glama

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
NameRequiredDescriptionDefault
commandYesThe shell command to check

Implementation Reference

  • 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 }
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jnMetaCode/shellward'

If you have feedback or need assistance with the MCP directory API, please join our Discord server