Skip to main content
Glama
milkymap

MCP4Modal Sandbox

by milkymap

terminate_sandbox

Stop a running Modal sandbox by its ID to free up resources and manage environment lifecycle.

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 core handler function that terminates a Modal sandbox by ID. It checks status, terminates, waits for completion, and returns a response.
    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 server instance.
    mcp_app.tool( name="terminate_sandbox", description=ToolDescriptions.TERMINATE_SANDBOX, )(self.terminate_sandbox)
  • Pydantic BaseModel defining the output schema for the terminate_sandbox tool response.
    class SandboxTerminateResponse(BaseModel): success: bool message: str
  • Detailed tool description string including parameters and usage, used during registration.
    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 """

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