Skip to main content
Glama

Run Code in a Sandbox Session

session

Run a command or code in an open E2B sandbox session (started by use with action create_session, which returns a session_id). Pass session_id plus either command (a shell command) or code (+ optional language: python/javascript/bash). Returns stdout/stderr/exit_code (or the code result). The sandbox stays alive — and billed per second of uptime — until you close it; re-running reuses the SAME box, so filesystem + process state persist between calls. ALWAYS close when done.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "session_id": "<session_id>"
    },
    "name": "session"
  }
}

Input Schema

NameRequiredDescriptionDefault
codeNoCode to execute (alternative to `command`).
commandNoShell command to run in the sandbox.
languageNoLanguage for `code`: python (default), javascript, or bash.
session_idYesThe session_id returned by create_session.

Output Schema

NameRequiredDescriptionDefault
okNoTrue when the call succeeded.
errorNoError code/message when ok=false.
resultNoStructured result, when the runtime returns one.
stderrNoCaptured standard error.
stdoutNoCaptured standard output.
exit_codeNoProcess exit code.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • changedOutput schema / (root)
      Previous value: -nullNew value: +{
      +  "additionalProperties": true,
      +  "properties": {
      +    "error": {
      +      "description": "Error code/message when ok=false.",
      +      "type": "string"
      +    },
      +    "exit_code": {
      +      "description": "Process exit code.",
      +      "type": "number"
      +    },
      +    "ok": {
      +      "description": "True when the call succeeded.",
      +      "type": "boolean"
      +    },
      +    "result": {
      +      "description": "Structured result, when the runtime returns one."
      +    },
      +    "stderr": {
      +      "description": "Captured standard error.",
      +      "type": "string"
      +    },
      +    "stdout": {
      +      "description": "Captured standard output.",
      +      "type": "string"
      +    }
      +  },
      +  "type": "object"
      +}
  2. First observed

TDQS

A4.5/5.0
Behavior5/5

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

It discloses significant behavioral traits beyond the annotations: the sandbox persists and is billed per second, reusing the same box preserves filesystem and process state, and the tool returns stdout/stderr/exit_code. It also warns about the cost and explicitly instructs to close when done. This is valuable context that annotations alone do not provide.

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 dense with useful information in four sentences, with the core purpose front-loaded. It uses bold for 'ALWAYS close when done' to emphasize a critical action. No unnecessary words or repetition.

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

Completeness5/5

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

Given the tool's complexity (running arbitrary code in a sandbox) and the availability of an output schema, the description is complete enough. It covers invocation, parameters, return values, state persistence, billing, and the close requirement, making it self-contained even without the output schema.

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 input schema already describes all four parameters clearly, including the command/code alternative and language values. The description adds no new parameter-level meaning beyond what the schema provides; it simply reiterates the same information. With 100% schema coverage, the baseline of 3 applies.

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

Purpose5/5

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

The description opens with 'Run a command or code in an open E2B sandbox session', providing a clear verb, resource, and context. It explicitly distinguishes from sibling tools like `close` and `use` by referencing the session creation flow and the need to later close the session.

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

Usage Guidelines4/5

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

The description gives clear context for use: pass a session_id plus either `command` or `code`, with optional language. It also explains the lifecycle (stays alive until closed) and emphasizes 'ALWAYS close when done'. However, it does not explicitly state when not to use this tool or compare it with alternatives, so it misses the 'when-not/alternatives' aspect.

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

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.