Skip to main content
Glama
mozicim

Node Code Sandbox MCP

by mozicim

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
NameRequiredDescriptionDefault
container_idYes
commandsYes

Implementation Reference

  • 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'))] };
    }
  • 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
    );
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the prerequisite of an initialized sandbox, which is useful context. However, it lacks details on critical behaviors such as whether commands run sequentially or in parallel, what happens on command failure, output format, security implications, or resource limits. For a tool that executes shell commands in a container, this is a significant gap in transparency.

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 extremely concise with just two sentences that are front-loaded and waste no words. The first sentence states the core action and resource, and the second adds a crucial prerequisite, making every sentence earn its place efficiently.

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 executing shell commands in a container, no annotations, no output schema, and 0% schema description coverage, the description is incomplete. It misses details on behavioral traits, parameter usage, and output handling, which are essential for safe and effective tool invocation. The prerequisite note helps, but overall, it's inadequate for a tool with this level of potential impact.

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?

The schema description coverage is 0%, so the description must compensate for undocumented parameters. It implies the need for a 'container_id' and 'commands' by referencing a sandbox container and shell commands, but doesn't explain what a container_id is, how to obtain it, or the format/syntax for commands. Since there are only 2 parameters, the baseline is higher, but the description adds minimal semantic value beyond what's inferred from the tool name and context.

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 action ('Execute shell commands') and resource ('inside a running sandbox container'), making the purpose specific and understandable. It distinguishes from sibling tools like 'sandbox_initialize' and 'sandbox_stop' by focusing on command execution rather than container lifecycle management. However, it doesn't explicitly differentiate from 'run_js' or 'run_js_ephemeral' which might also execute code in some environment.

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 usage context by stating 'Requires a sandbox initialized beforehand,' which implies a prerequisite and suggests when to use this tool (after initialization). However, it doesn't explicitly state when NOT to use it or mention alternatives like 'run_js' for JavaScript execution versus shell commands, leaving the guidance incomplete.

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