Skip to main content
Glama

Exec in container

exec_container

Execute commands inside containers to run applications, perform maintenance tasks, or troubleshoot running processes within your containerized environment.

Instructions

Execute a command inside a container.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
containerYes
commandYesCommand to execute

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main handler implementation for exec_container tool. Parses args, runs 'podman exec <container> <command>' using run_podman helper, returns stdout or error message.
    async def exec_container(self, args: Dict[str, Any]) -> Dict[str, Any]:
        container = args.get("container")
        command = args.get("command", [])
        cmd_args = ["exec", container] + command
        result = run_podman(cmd_args)
        return {"output": result["stdout"] if result["success"] else f"Error: {result['stderr']}"}
  • Input schema and registration in the tools list for the exec_container tool.
    Tool(
        name="exec_container",
        description="Execute a command inside a container",
        inputSchema={
            "type": "object",
            "properties": {
                "container": {
                    "type": "string",
                    "description": "Container name or ID"
                },
                "command": {
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "Command to execute"
                }
            },
            "required": ["container", "command"]
        }
    ),
  • main_b.py:459-472 (registration)
    Mapping of tool name 'exec_container' to its handler method in the dispatch dictionary used by handle_tools_call.
    tool_handlers = {
        "list_containers": self.list_containers,
        "container_info": self.container_info,
        "start_container": self.start_container,
        "stop_container": self.stop_container,
        "restart_container": self.restart_container,
        "container_logs": self.container_logs,
        "run_container": self.run_container,
        "remove_container": self.remove_container,
        "exec_container": self.exec_container,
        "list_images": self.list_images,
        "pull_image": self.pull_image,
        "container_stats": self.container_stats,
    }
  • main.py:239-246 (handler)
    Alternative handler implementation using FastMCP decorator @mcp.tool, which also defines input schema via Pydantic Field. Executes podman exec similarly.
    @mcp.tool(title="Exec in container", description="Execute a command inside a container.")
    def exec_container(
        container: str = Field(...),
        command: List[str] = Field(..., description="Command to execute"),
    ) -> str:
        args = ["exec", container] + command
        result = run_podman(args)
        return result["stdout"] if result["success"] else f"Error: {result['stderr']}"
  • Shared helper function used by exec_container (and other tools) to run podman subprocess commands and parse results.
    def run_podman(args: List[str]) -> Dict[str, Any]:
        """Run a podman command and capture output"""
        try:
            cmd = ["podman"] + args
            result = subprocess.run(
                cmd,
                capture_output=True,
                text=True,
                timeout=30
            )
            return {
                "success": result.returncode == 0,
                "stdout": result.stdout.strip(),
                "stderr": result.stderr.strip(),
                "returncode": result.returncode,
            }
        except subprocess.TimeoutExpired:
            return {"success": False, "stdout": "", "stderr": "Command timed out", "returncode": -1}
        except Exception as e:
            return {"success": False, "stdout": "", "stderr": str(e), "returncode": -1}
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states the action but lacks behavioral details such as permissions required, whether it's interactive or batch, error handling, or output format. This is inadequate for a mutation tool with zero annotation coverage.

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 a single, efficient sentence with zero waste, clearly front-loaded with the core action. It's appropriately sized for the tool's complexity.

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 has an output schema (which handles return values) and moderate complexity, the description is minimally complete but lacks context like usage scenarios or behavioral traits. It's adequate but with clear gaps in guidance and transparency.

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?

Schema description coverage is 50% (only 'command' has a description). The description implies parameters ('container', 'command') but adds no meaning beyond the schema, such as format examples or constraints. With partial schema coverage, it doesn't fully compensate, meeting the baseline for moderate coverage.

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

Purpose4/5

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

The description clearly states the action ('Execute a command') and target ('inside a container'), which is specific and unambiguous. However, it doesn't differentiate from sibling tools like 'run_container' or 'restart_container', which also involve container operations, so it misses full sibling differentiation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'run_container' (likely for starting containers) and 'container_logs' (for viewing logs), there's no indication of context, prerequisites, or exclusions for 'exec_container'.

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/kunwarmahen/podman-mcp-server'

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