sandbox_exec
Execute shell commands in a secure Node.js sandbox container to run JavaScript code, install NPM packages, and retrieve execution results safely.
Instructions
Execute one or more shell commands inside a running sandbox container. Requires a sandbox initialized beforehand.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| container_id | Yes | ||
| commands | Yes |
Implementation Reference
- src/tools/exec.ts:11-36 (handler)The main handler function for the sandbox_exec tool. It checks if Docker is running, then executes each shell command in the specified container using docker exec, collects outputs, and returns them as text content.export default async function execInSandbox({ container_id, commands, }: { container_id: string; commands: string[]; }): Promise<McpResponse> { if (!isDockerRunning()) { return { content: [textContent(DOCKER_NOT_RUNNING_ERROR)], }; } const output: string[] = []; for (const cmd of commands) { output.push( execSync( `docker exec ${container_id} /bin/sh -c ${JSON.stringify(cmd)}`, { encoding: 'utf8', } ) ); } return { content: [textContent(output.join('\n'))] }; }
- src/tools/exec.ts:6-9 (schema)Zod schema defining the input parameters for the sandbox_exec tool: container_id (string) and commands (array of non-empty strings). Used for validation during tool calls.export const argSchema = { container_id: z.string(), commands: z.array(z.string().min(1)), };
- src/server.ts:58-63 (registration)Registration of the sandbox_exec tool on the MCP server, specifying name, description, input schema (execSchema), and handler function (execInSandbox).server.tool( 'sandbox_exec', 'Execute one or more shell commands inside a running sandbox container. Requires a sandbox initialized beforehand.', execSchema, execInSandbox );