Skip to main content
Glama
mozicim

Node Code Sandbox MCP

by mozicim

sandbox_stop

Terminate and remove a running Node.js sandbox container to clean up resources after completing code execution tasks.

Instructions

Terminate and remove a running sandbox container. Should be called after finishing work in a sandbox initialized with sandbox_initialize.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
container_idYes

Implementation Reference

  • The main handler function `stopSandbox` that executes the tool logic: checks if Docker is running, stops and removes the container using `docker rm -f`, updates the active containers set, and returns appropriate success or error messages.
    export default async function stopSandbox({
      container_id,
    }: {
      container_id: string;
    }): Promise<McpResponse> {
      if (!isDockerRunning()) {
        return {
          content: [textContent(DOCKER_NOT_RUNNING_ERROR)],
        };
      }
    
      try {
        // Directly use execSync for removing the container as expected by the test
        execSync(`docker rm -f ${container_id}`);
        activeSandboxContainers.delete(container_id);
        // console.log(
        //   `[stopSandbox] Removed container ${container_id} from registry.`
        // );
    
        return {
          content: [textContent(`Container ${container_id} removed.`)],
        };
      } catch (error) {
        // Handle any errors that occur during container removal
        const errorMessage = error instanceof Error ? error.message : String(error);
        console.error(
          `[stopSandbox] Error removing container ${container_id}: ${errorMessage}`
        );
    
        // Still remove from our registry even if Docker command failed
        activeSandboxContainers.delete(container_id);
    
        return {
          content: [
            textContent(
              `Error removing container ${container_id}: ${errorMessage}`
            ),
          ],
        };
      }
    }
  • Zod input schema defining the required `container_id` string argument.
    export const argSchema = { container_id: z.string() };
  • src/server.ts:75-80 (registration)
    MCP server tool registration for 'sandbox_stop', linking the name, description, input schema (`stopSchema`), and handler (`stopSandbox`).
    server.tool(
      'sandbox_stop',
      'Terminate and remove a running sandbox container. Should be called after finishing work in a sandbox initialized with sandbox_initialize.',
      stopSchema,
      stopSandbox
    );
  • src/server.ts:15-15 (registration)
    Import of the handler function and schema for sandbox_stop from the tools module.
    import stopSandbox, { argSchema as stopSchema } from './tools/stop.ts';

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/mozicim/node-code-sandbox-mcp'

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