Skip to main content
Glama

run_code

Execute Python or C++ code snippets in isolated Docker containers with no network access, memory cap, and read-only filesystem. Returns output, status, and duration for safe code testing and verification.

Instructions

Execute a Python or C++ code snippet inside an isolated, network-disabled Docker container and return its output.

Each run happens in a fresh, ephemeral container with no network access, a
256 MB memory cap, a 0.5 CPU cap, and a read-only root filesystem. The
container is destroyed immediately after the run. Use this tool to run
untrusted or exploratory code snippets, verify that code works, or inspect
program output, without touching the host machine.

Returns a dict with:
- status: one of "success", "error", "timeout", or "compile_error" (C++ only)
- exit_code: the process exit code, or null if it never ran
- stdout / stderr: captured output, truncated at 100 KB
- duration_ms: wall-clock execution time in milliseconds
- language: the normalized language that was actually run

Note: this sandbox provides Docker-level isolation suitable for personal/
local use. It is not a hardened multi-tenant sandbox and should not be
used to run code from untrusted third parties in a production setting.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesThe full source code to execute, as a single string. Max size 50 KB. For C++, this must be a complete, compilable program including a main() function and any necessary #include directives. For Python, this is executed directly as a standalone script.
languageYesProgramming language of the snippet. Supported values: 'python' (runs in python:3.12-slim) and 'cpp' (compiled with g++ -std=c++17 -O2 then run in gcc:14). Case-insensitive.
timeout_secondsNoMaximum time in seconds to allow the code to run before it is force-killed. Default 10, hard ceiling 30 (requests above this are rejected). For C++, this timeout applies to the run stage only, not the compile stage.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Behavior5/5

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

With no annotations, the description fully discloses isolation level, resource caps (256 MB, 0.5 CPU), ephemeral nature, return structure, and limitations. No contradictions.

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?

Description is thorough but well-organized; each sentence adds value. Could be slightly shorter, but effective.

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?

Covers purpose, behavior, parameters, return values, and limitations comprehensively. Output schema is described, so no gaps.

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 descriptions are already detailed, but the description adds context like max code size 50KB, case-insensitive language, and timeout ceiling 30s, which are not in schema.

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 clearly states it executes Python or C++ code in an isolated container and returns output. It distinguishes itself from siblings like list_supported_languages and get_execution_history by focusing on execution.

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?

Provides explicit use cases (exploratory code, verification) and a warning about not being a hardened sandbox. Does not explicitly compare to siblings, but context makes it clear.

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/huzayfaSiddique/sandbox_runner'

If you have feedback or need assistance with the MCP directory API, please join our Discord server