Skip to main content
Glama
milkymap

MCP4Modal Sandbox

by milkymap

terminate_sandbox

Stop running cloud sandboxes to free resources and manage environment lifecycle by providing the sandbox ID.

Instructions

        Terminates a Modal sandbox by its ID.
        
        Parameters:
        - sandbox_id: The unique identifier of the sandbox to terminate
        
        Returns a SandboxTerminateResponse containing:
        - success: Boolean indicating if termination was successful
        - message: Detailed message about the termination result
        
        This tool is useful for:
        - Stopping running sandboxes that are no longer needed
        - Cleaning up resources
        - Forcefully ending long-running or stuck sandboxes
        - Managing sandbox lifecycle
        
        The tool will:
        1. Check if the sandbox exists and is running
        2. Send termination signal if running
        3. Wait for confirmation of termination
        4. Return status of the operation
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sandbox_idYes

Implementation Reference

  • The handler function that implements the tool logic: fetches the Modal Sandbox by ID, checks if it's running, terminates it if running, waits for termination, and returns a SandboxTerminateResponse.
    async def terminate_sandbox(self, sandbox_id: str) -> SandboxTerminateResponse:
        # Get sandbox from Modal using from_id
        modal_sandbox = await modal.Sandbox.from_id.aio(sandbox_id)
    
        # Check if sandbox is running before terminating
        sandbox_status = await modal_sandbox.poll.aio()
        
        # Terminate the Modal sandbox
        if sandbox_status is not None:
            return SandboxTerminateResponse(
                success=False,
                message=f"Sandbox {sandbox_id} is not running"
            )
        
        await modal_sandbox.terminate.aio()
        
        # Wait for termination
        await modal_sandbox.wait.aio(raise_on_termination=False)
        
        logger.info(f"Terminated sandbox {sandbox_id}")
        
        return SandboxTerminateResponse(
            success=True,
            message=f"Sandbox {sandbox_id} terminated successfully"
        )
  • Registers the terminate_sandbox tool with the FastMCP app, specifying name and description, and binding the handler method.
    mcp_app.tool(
        name="terminate_sandbox", 
        description=ToolDescriptions.TERMINATE_SANDBOX,
    )(self.terminate_sandbox)
  • Pydantic BaseModel defining the response schema for the terminate_sandbox tool.
    class SandboxTerminateResponse(BaseModel):
        success: bool
        message: str
  • Tool description string providing usage instructions, parameters, and return value details for the LLM.
    TERMINATE_SANDBOX = """
            Terminates a Modal sandbox by its ID.
            
            Parameters:
            - sandbox_id: The unique identifier of the sandbox to terminate
            
            Returns a SandboxTerminateResponse containing:
            - success: Boolean indicating if termination was successful
            - message: Detailed message about the termination result
            
            This tool is useful for:
            - Stopping running sandboxes that are no longer needed
            - Cleaning up resources
            - Forcefully ending long-running or stuck sandboxes
            - Managing sandbox lifecycle
            
            The tool will:
            1. Check if the sandbox exists and is running
            2. Send termination signal if running
            3. Wait for confirmation of termination
            4. Return status of the operation
            """
Behavior4/5

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

With no annotations provided, the description carries the full burden and does so effectively by detailing the tool's behavior: it checks if the sandbox exists and is running, sends a termination signal, waits for confirmation, and returns status. It also implies destructive action ('terminates', 'forcefully ending'), which is appropriate for this operation.

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 well-structured with clear sections (purpose, parameters, returns, use cases, behavior steps) and front-loaded key information. Every sentence adds value, such as detailing the return object and step-by-step process, without unnecessary fluff.

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

Completeness5/5

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

Given the tool's complexity (destructive operation with 1 parameter), no annotations, and no output schema, the description is highly complete. It covers purpose, parameters, return values, usage scenarios, and behavioral steps, providing all necessary context for an AI agent to use the tool correctly.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must compensate, and it does by explaining the parameter 'sandbox_id' as 'The unique identifier of the sandbox to terminate', adding essential meaning beyond the schema's basic type information. This is crucial for correct tool invocation.

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 ('terminates') and resource ('Modal sandbox by its ID'), distinguishing it from sibling tools like 'launch_sandbox' or 'list_sandboxes'. It precisely communicates the tool's function without ambiguity.

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

Usage Guidelines5/5

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

The description explicitly lists use cases ('Stopping running sandboxes that are no longer needed', 'Cleaning up resources', 'Forcefully ending long-running or stuck sandboxes', 'Managing sandbox lifecycle'), providing clear guidance on when to use this tool versus alternatives like 'list_sandboxes' or 'launch_sandbox'.

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/milkymap/mcp4modal_sandbox'

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