Skip to main content
Glama

Run code

run_code
Read-only

Run one program in a sandbox and return its output.

Returns output, error, status, exit_code, time (wall-clock seconds), memory and truncated. Limited to 30 seconds (or time_limit) and 512 MB RAM. To check a solution against expected outputs, use run_tests instead.

python-3.14 includes numpy, pandas, scipy, scikit-learn, matplotlib, seaborn, statsmodels, sympy, openpyxl, pillow, duckdb, polars, wordcloud, pgmpy and nltk (with WordNet, VADER and the English POS tagger data) (no network, so nothing else can be installed). Files a program writes to the directory in $OUTPUT_DIR come back in files (png, svg, csv, json and txt; up to 8 files and 2 MB): PNG charts are returned as images, and SVG, CSV, JSON and text files with their text. plt.show() saves each open figure as figure-N.png, so tutorial code returns its chart. Pass files to give the program input data or helper source files.

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

Input Schema

NameRequiredDescriptionDefault
codeYesThe source code to execute
filesNoFiles the program can use, up to 20 and 1,000,000 decoded bytes in total: helper source files (compiled with the program) and input data. Each {'name': 'util.py' or 'pkg/util.py', 'content': text, 'encoding': 'utf8' (default) or 'base64'}. They sit in the program's working directory, so pd.read_csv('data.csv') works.
inputNoStandard input (stdin) to provide to the program
compilerYesCompiler identifier (e.g. 'python-3.14', 'gcc-15'). Use list_compilers to see all options.
time_limitNoSeconds the run may take, above 0 and at most 30. Defaults to 30.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • changedInput schema / properties / files / description
      Previous value: -"Input files, up to 8 and 1,000,000 decoded bytes in total, each {'name': 'data.csv', 'content': text, 'encoding': 'utf8' (default) or 'base64'}. They sit in the program's working directory, so pd.read_csv('data.csv') works."New value: +"Files the program can use, up to 20 and 1,000,000 decoded bytes in total: helper source files (compiled with the program) and input data. Each {'name': 'util.py' or 'pkg/util.py', 'content': text, 'encoding': 'utf8' (default) or 'base64'}. They sit in the program's working directory, so pd.read_csv('data.csv') works."
  2. Changed2 schema fields changed
    • addedInput schema / properties / files
      Added value: +{
      +  "anyOf": [
      +    {
      +      "items": {
      +        "additionalProperties": true,
      +        "type": "object"
      +      },
      +      "type": "array"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "Input files, up to 8 and 1,000,000 decoded bytes in total, each {'name': 'data.csv', 'content': text, 'encoding': 'utf8' (default) or 'base64'}. They sit in the program's working directory, so pd.read_csv('data.csv') works."
      +}
    • changedOutput schema / (root)
      Previous value: -{
      -  "additionalProperties": true,
      -  "type": "object"
      -}New value: +null
  3. Changed1 schema field changed
    • addedInput schema / properties / time_limit
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "number"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "Seconds the run may take, above 0 and at most 30. Defaults to 30."
      +}
  4. First observed

TDQS

A4.7/5.0
Behavior5/5

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

Annotations only declare readOnly/openWorld/destructive hints; the description goes far beyond by disclosing the sandbox limits, the fact that there is no network and therefore no installs, the exact preinstalled package set per compiler, and how written files are captured from $OUTPUT_DIR (≤8 files, ≤2 MB, PNG-as-image, something-out for SVG/CSV/JSON/text). It also documents the plt.show() special case, which is precisely the kind of behavior an agent could not predict.

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

Conciseness4/5

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

Front-loaded with purpose, then limits, then environment, then files — a logical order with no filler sentences. The long package enumeration and environment paragraph is dense but each item is actionable; it is borderline long rather than wasteful.

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 no output schema, the description usefully enumerates return fields (output, error, status, exit_code, time, memory, truncated) and explains the `files` return shape. It stops short of explaining semantics for edge fields such as `truncated` or what `status` values mean, which is the only remaining gap for a tool of this complexity.

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

Parameters4/5

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

Schema coverage is 100%, so the baseline is 3; the description adds value by tying the `files` parameter to the return channel — files go into the working directory for input, and program-written files come back in `files` — and by framing time_limit against the 30 s default. It does not restate per-parameter syntax, which the schema already handles well.

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?

Opens with a specific verb+resource+scope: 'Run one program in a sandbox and return its output.' It explicitly contrasts itself with run_tests ('To check a solution against expected outputs, use run_tests instead'), so an agent can distinguish it from the nearest sibling without reading either schema.

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?

Names the alternative (run_tests) and the exact condition that selects it (checking against expected outputs). It also states the operational envelope (30 s or time_limit, 512 MB RAM, no network) and, via the schema's compiler note, points to list_compilers for valid identifiers — enough for an agent to choose correctly.

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.