sandbox_stop
Terminate and remove a running Node.js sandbox container to clean up resources after script execution or service completion.
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
| Name | Required | Description | Default |
|---|---|---|---|
| container_id | Yes |
Implementation Reference
- src/tools/stop.ts:9-49 (handler)The handler function stopSandbox that terminates and removes the Docker container using 'docker rm -f', updates the activeSandboxContainers registry, handles Docker not running and errors, returning appropriate MCP responses.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}` ), ], }; } }
- src/tools/stop.ts:7-7 (schema)Zod input schema defining the required 'container_id' string argument.export const argSchema = { container_id: z.string() };
- src/server.ts:75-80 (registration)Registration of the 'sandbox_stop' tool on the MCP server, specifying 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 );