Skip to main content
Glama

Run code

run_code
Destructive

Save code to a temporary file in the sandbox and run it with python (default), node or bash; returns exit_code, stdout, stderr and duration. Use it for multi-line programs and quick experiments. A single shell line is shorter as a plain shell command, and work longer than a few minutes belongs in a background job, which keeps running without this connection.

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": {
      "code": "<code>"
    },
    "name": "run_code"
  }
}

Input Schema

NameRequiredDescriptionDefault
codeYesSource code
languageNoLanguage (default python)
timeout_sNoTime limit in seconds (default 120)
sandbox_idNoSandbox ID (sb_…). If omitted, the current sandbox of this session is used. A sandbox_id you pass becomes the current sandbox for later calls without sandbox_id.

Output Schema

NameRequiredDescriptionDefault
stderrYesStandard error output.
stdoutYesStandard output (very long output is shortened in the middle).
exit_codeYesExit code of the command (non-zero is a normal result, not a tool error).
shortenedYesstdout or stderr was shortened in the middle for this reply (a marker shows how many characters are missing).
timed_outYesThe time limit was exceeded and the process was killed.
truncatedYesstdout or stderr is incomplete (either of the two reasons below) – redirect large output to a file and read the part you need.
sandbox_idYesSandbox ID.
duration_msYesHow long the command ran, in milliseconds.
output_limit_hitYesThe command produced more than 1 MB of output and the rest was cut off in the sandbox.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • changedInput schema / properties / sandbox_id / description
      Previous value: -"Sandbox ID (sb_…). If omitted, the current sandbox of this session is used."New value: +"Sandbox ID (sb_…). If omitted, the current sandbox of this session is used. A sandbox_id you pass becomes the current sandbox for later calls without sandbox_id."
  2. Changed4 schema fields changed
    • addedOutput schema / properties / output_limit_hit
      Added value: +{
      +  "description": "The command produced more than 1 MB of output and the rest was cut off in the sandbox.",
      +  "type": "boolean"
      +}
    • addedOutput schema / properties / shortened
      Added value: +{
      +  "description": "stdout or stderr was shortened in the middle for this reply (a marker shows how many characters are missing).",
      +  "type": "boolean"
      +}
    • changedOutput schema / properties / truncated / description
      Previous value: -"The output exceeded 1 MB and was cut."New value: +"stdout or stderr is incomplete (either of the two reasons below) – redirect large output to a file and read the part you need."
    • changedOutput schema / required
      Previous value: -[
      -  "sandbox_id",
      -  "exit_code",
      -  "stdout",
      -  "stderr",
      -  "duration_ms",
      -  "timed_out",
      -  "truncated"
      -]New value: +[
      +  "sandbox_id",
      +  "exit_code",
      +  "stdout",
      +  "stderr",
      +  "duration_ms",
      +  "timed_out",
      +  "truncated",
      +  "output_limit_hit",
      +  "shortened"
      +]
  3. First observed

TDQS

A4.4/5.0
Behavior4/5

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

Annotations declare destructiveHint=true and openWorldHint=true, and the description complements them by revealing that code is materialized to a temporary file in the sandbox and that jobs outliving the connection belong elsewhere (implying this call is connection-bound). It does not say what happens on timeout or whether the temp file persists, which leaves part of the mutation/execution profile undisclosed.

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?

Three sentences, front-loaded with the core action and return values, then usage boundaries. No filler and nothing buried behind preamble.

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

Completeness4/5

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

With an output schema present, the definition needn't explain return formatting, and annotations plus schema cover safety and parameters well. Remaining gaps are timeout behavior (does it raise or return a nonzero exit_code?) and whether executed code has network access, both relevant for a destructive open-world executor.

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 coverage is 100%, including an unusually detailed sandbox_id description covering the 'becomes current sandbox' side effect, so the schema already carries parameter meaning. The description only restates the default language and adds no syntax, timeout, or sandbox-selection detail beyond the schema – baseline 3.

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?

States a specific two-step action (save code to a temp file, then execute) plus the supported runtimes (python default, node, bash) and the return payload (exit_code, stdout, stderr, duration). It also differentiates scope from the two obvious siblings: single shell lines and long-running work.

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

Usage Guidelines5/5

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

Gives explicit when-to-use (multi-line programs, quick experiments) and explicit when-not-to-use with the correct redirects: one-liners belong to a plain shell command, and work beyond a few minutes belongs to a background job. This is the rare case where the boundaries are stated rather than implied.

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.

Resources