Skip to main content
Glama
ssdeanx

Node.js Sandbox MCP Server

sandbox_exec

Execute shell commands within an isolated Node.js sandbox container to run code or manage dependencies securely with controlled resource limits.

Instructions

Execute one or more shell commands inside a running sandbox container. Requires a sandbox initialized beforehand.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandsYes
container_idYes

Implementation Reference

  • The handler function that executes one or more shell commands inside a running sandbox Docker container using docker exec.
    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'))] };
    }
  • Zod schema for input validation: container_id (string) and commands (array of non-empty strings).
    export const argSchema = {
      container_id: z.string(),
      commands: z.array(z.string().min(1)),
    };
  • src/server.ts:58-63 (registration)
    Registers the sandbox_exec tool with the MCP server, providing name, description, schema (execSchema), and handler (execInSandbox).
    server.tool(
      'sandbox_exec',
      'Execute one or more shell commands inside a running sandbox container. Requires a sandbox initialized beforehand.',
      execSchema,
      execInSandbox
    );

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

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