Skip to main content
Glama
mozicim

Node Code Sandbox MCP

by mozicim

sandbox_initialize

Start an isolated Docker container running Node.js to create a secure sandbox environment for executing multiple JavaScript commands and scripts.

Instructions

Start a new isolated Docker container running Node.js. Used to set up a sandbox session for multiple commands and scripts.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imageNo
portNoIf set, maps this container port to the host

Implementation Reference

  • The handler function that executes the logic for sandbox_initialize: creates a Docker container with labels, mounts a volume, sets resource limits, registers it, and returns the container ID or error.
    export default async function initializeSandbox({
      image = DEFAULT_NODE_IMAGE,
      port,
    }: {
      image?: string;
      port?: number;
    }): Promise<McpResponse> {
      if (!isDockerRunning()) {
        return {
          content: [textContent(DOCKER_NOT_RUNNING_ERROR)],
        };
      }
    
      const containerId = `js-sbx-${randomUUID()}`;
      const creationTimestamp = Date.now();
    
      const portOption = port ? `-p ${port}:${port}` : `--network host`; // prefer --network host if no explicit port mapping
    
      // Construct labels
      const labels = [
        `mcp-sandbox=true`,
        `mcp-server-run-id=${serverRunId}`,
        `mcp-creation-timestamp=${creationTimestamp}`,
      ];
      const labelArgs = labels.map((label) => `--label "${label}"`).join(' ');
      const { memFlag, cpuFlag } = computeResourceLimits(image);
    
      try {
        execSync(
          `docker run -d ${portOption} ${memFlag} ${cpuFlag} ` +
            `--workdir /workspace -v ${getFilesDir()}:/workspace/files ` +
            `${labelArgs} ` + // Add labels here
            `--name ${containerId} ${image} tail -f /dev/null`
        );
    
        // Register the container only after successful creation
        activeSandboxContainers.set(containerId, creationTimestamp);
        logger.info(`Registered container ${containerId}`);
    
        return {
          content: [textContent(containerId)],
        };
      } catch (error) {
        logger.error(`Failed to initialize container ${containerId}`, error);
        // Ensure partial cleanup if execSync fails after container might be created but before registration
        try {
          execSync(`docker rm -f ${containerId}`);
        } catch (cleanupError: unknown) {
          // Ignore cleanup errors - log it just in case
          logger.warning(
            `Ignoring error during cleanup attempt for ${containerId}: ${String(cleanupError)}`
          );
        }
        return {
          content: [
            textContent(
              `Failed to initialize sandbox container: ${error instanceof Error ? error.message : String(error)}`
            ),
          ],
        };
      }
    }
  • Zod schema defining input arguments for the sandbox_initialize tool: optional image and port.
    export const argSchema = {
      image: z.string().optional(),
      port: z
        .number()
        .optional()
        .describe('If set, maps this container port to the host'),
    };
  • src/server.ts:51-56 (registration)
    MCP server tool registration for sandbox_initialize, linking name, description, schema, and handler.
    server.tool(
      'sandbox_initialize',
      'Start a new isolated Docker container running Node.js. Used to set up a sandbox session for multiple commands and scripts.',
      initializeSchema,
      initializeSandbox
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions the tool starts an 'isolated Docker container' and is for 'multiple commands and scripts,' implying persistence and isolation. However, it doesn't disclose critical behavioral traits such as whether this requires Docker permissions, what happens to existing containers, how long the container persists, resource limits, or error handling. For a tool that initializes a Docker container with zero annotation coverage, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences, front-loaded with the core purpose and followed by usage context. Every sentence adds value: the first defines the action, and the second explains the broader use case. There's no redundancy or unnecessary information, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of initializing a Docker container, no annotations, no output schema, and incomplete parameter documentation (50% schema coverage), the description is inadequate. It lacks details on behavioral aspects (e.g., permissions, persistence, error handling), doesn't clarify parameter usage, and provides minimal guidance on integration with sibling tools. For a tool with this level of complexity, it should do more to ensure safe and correct usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 50% (only 'port' has a description). The description doesn't add any parameter-specific information beyond what's in the schema. It doesn't explain the 'image' parameter (e.g., default Node.js version, allowed images) or provide additional context for 'port.' With partial schema coverage, the description doesn't compensate for the undocumented 'image' parameter, resulting in a baseline score.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Start a new isolated Docker container running Node.js.' It specifies the verb ('Start'), resource ('isolated Docker container'), and technology ('Node.js'). However, it doesn't explicitly differentiate from sibling tools like 'sandbox_exec' or 'run_js_ephemeral' beyond mentioning it's 'Used to set up a sandbox session for multiple commands and scripts.'

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides some implied usage context by stating it's 'Used to set up a sandbox session for multiple commands and scripts,' suggesting this is for initializing a reusable environment. However, it doesn't explicitly state when to use this versus alternatives like 'run_js_ephemeral' (for one-off scripts) or 'sandbox_exec' (for commands within an existing sandbox). No exclusions or prerequisites are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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