Skip to main content
Glama

execute_command

Run security testing commands like nmap, sqlmap, and hydra inside a Kali Linux container for penetration testing and vulnerability assessment.

Instructions

Execute a shell command inside the Kali Linux container. Use this to run security tools like nmap, sqlmap, hydra, nikto, gobuster, john, hashcat, dirb, enum4linux, and any other installed tool.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesShell command to execute inside the Kali container
timeoutNoTimeout in seconds (default: 300)

Implementation Reference

  • The implementation of executeCommand that interacts with the Docker API to run shell commands in the container.
    async executeCommand(
      command: string,
      timeout: number = 300
    ): Promise<{ stdout: string; stderr: string; exitCode: number }> {
      const container = await this.getContainer();
      if (!container) {
        throw new Error(
          "Kali container is not running. Use container_start first."
        );
      }
    
      const info = await container.inspect();
      if (!info.State.Running) {
        throw new Error(
          "Kali container is not running. Use container_start first."
        );
      }
    
      const exec = await container.exec({
        Cmd: ["/bin/bash", "-c", command],
        AttachStdout: true,
        AttachStderr: true,
      });
    
      const stream = await exec.start({ hijack: true, stdin: false });
    
      return new Promise((resolve, reject) => {
        let stdout = "";
        let stderr = "";
    
        const timer = setTimeout(() => {
          stream.destroy();
          resolve({
            stdout,
            stderr: stderr + "\n[Command timed out after " + timeout + "s]",
            exitCode: -1,
          });
        }, timeout * 1000);
    
        // Docker multiplexes stdout/stderr in the stream
        // Each frame: [type(1byte), 0, 0, size(4bytes big-endian), payload]
        let buffer = Buffer.alloc(0);
    
        stream.on("data", (chunk: Buffer) => {
          buffer = Buffer.concat([buffer, chunk]);
    
          while (buffer.length >= 8) {
            const type = buffer[0];
            const size = buffer.readUInt32BE(4);
    
            if (buffer.length < 8 + size) break;
    
            const payload = buffer.subarray(8, 8 + size).toString("utf-8");
            buffer = buffer.subarray(8 + size);
    
            if (type === 1) {
              stdout += payload;
            } else if (type === 2) {
              stderr += payload;
            }
          }
        });
    
        stream.on("end", async () => {
          clearTimeout(timer);
          try {
            const inspectResult = await exec.inspect();
            resolve({
              stdout,
              stderr,
              exitCode: inspectResult.ExitCode ?? 0,
            });
          } catch {
            resolve({ stdout, stderr, exitCode: 0 });
          }
        });
    
        stream.on("error", (err: Error) => {
          clearTimeout(timer);
          reject(err);
        });
      });
    }
  • Registration and handling of the execute_command tool.
    server.tool(
      "execute_command",
      "Execute a shell command inside the Kali Linux container. Use this to run security tools like nmap, sqlmap, hydra, nikto, gobuster, john, hashcat, dirb, enum4linux, and any other installed tool.",
      {
        command: z.string().describe("Shell command to execute inside the Kali container"),
        timeout: z
          .number()
          .optional()
          .describe("Timeout in seconds (default: 300)"),
      },
      async ({ command, timeout }) => {
        try {
          const result = await docker.executeCommand(command, timeout ?? 300);
    
          let output = "";
          if (result.stdout) {
            output += result.stdout;
          }
          if (result.stderr) {
            output += (output ? "\n--- stderr ---\n" : "") + result.stderr;
          }
          if (!output) {
            output = "(no output)";
          }
          output += `\n\n[exit code: ${result.exitCode}]`;
    
          return {
            content: [{ type: "text", text: output }],
            isError: result.exitCode !== 0,
          };
        } catch (err) {
          return {
            content: [
              {
                type: "text",
                text: `Failed to execute command: ${err instanceof Error ? err.message : String(err)}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While it mentions the container context and example tools, it doesn't address critical behavioral aspects like permission requirements, potential destructive effects of commands, rate limits, error handling, or output format. The description provides basic context but lacks important operational details.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly concise with two sentences that each earn their place: the first establishes the core functionality, and the second provides concrete usage examples. It's front-loaded with the essential information and wastes no words on unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (command execution in a security container with no annotations or output schema), the description provides adequate basic context but lacks completeness. It establishes the what and why but misses important operational details like security implications, permission requirements, output expectations, and error scenarios that would be crucial for safe and effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, both parameters are well-documented in the schema itself. The description doesn't add any meaningful parameter semantics beyond what's already in the schema - it mentions 'shell command' generically but doesn't provide additional context about command syntax, security considerations, or timeout implications beyond the schema's documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Execute a shell command') and the target resource ('inside the Kali Linux container'), with explicit examples of security tools that can be run. It distinguishes this tool from sibling container management tools by focusing on command execution rather than container lifecycle operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context about when to use this tool ('to run security tools like nmap, sqlmap, hydra... and any other installed tool'), establishing its purpose for executing security-related commands. However, it doesn't explicitly state when NOT to use it or mention alternatives among the sibling tools for different operations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/Hannes221/kali-mcp'

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