Skip to main content
Glama
lu-zhengda

mcp-python-exec-sandbox

execute_python

Run Python code with automatic dependency resolution. Scripts can declare dependencies via inline metadata or parameters, executed in an isolated sandbox to avoid system pollution.

Instructions

Execute a Python script with automatic dependency management.

The script can include PEP 723 inline metadata (# /// script blocks) for declaring dependencies. Additional dependencies can also be passed via the dependencies parameter and will be merged.

Args: script: Python source code to execute. May include PEP 723 metadata. dependencies: Extra PEP 508 dependency specifiers to make available. timeout_seconds: Maximum execution time (1-300, default 30).

Returns: Formatted output with stdout, stderr, exit code, and duration.

Example - simple script:

execute_python(script="print('hello')")

Example - with dependencies parameter:

execute_python(
    script="import requests; print(requests.get('https://example.com').status_code)",
    dependencies=["requests>=2.32"]
)

Example - with inline dependency metadata (preferred for multiple deps):

execute_python(script='''
# /// script
# dependencies = ["pandas>=2.2", "numpy>=1.26"]
# ///

import pandas as pd
import numpy as np
print(pd.DataFrame({"a": np.arange(5)}).describe())
''')

Always pin dependency versions (e.g. "pandas>=2.2" instead of "pandas") for reproducible results.

The inline metadata block (# /// script ... # ///) is the recommended way to declare dependencies directly in the script (see PEP 723: https://peps.python.org/pep-0723/). The dependencies parameter is a simpler alternative when you just need to add a few packages. Both accept standard pip-style version specifiers like "requests>=2.28" or "pandas" (see PEP 508: https://peps.python.org/pep-0508/).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYes
dependenciesNo
timeout_secondsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior3/5

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

No annotations provided, so description carries full burden. It discloses timeout, return format, and dependency merging, but does not warn about potential side effects like network access or security risks, which are inherent to arbitrary Python execution.

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?

Well-structured with summary, args, returns, examples, and notes. Front-loaded with key information. Slightly verbose but each section adds value.

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 (3 params, output schema), the description covers all aspects: parameters, return format, best practices, and references to PEP standards. No gaps remain.

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

Parameters5/5

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

Schema description coverage is 0%, but the description fully explains all three parameters: script (source code with PEP 723), dependencies (PEP 508 specifiers), and timeout_seconds (range and default). Examples clarify usage.

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 the tool executes Python scripts with automatic dependency management. It distinguishes itself from sibling tools (check_environment, validate_script) by focusing on execution and dependency resolution.

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 detailed guidance on how to use dependencies via inline metadata or parameter, and recommends pinning versions. Lacks explicit when-not-to-use or comparison to alternatives, but covers main usage patterns.

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/lu-zhengda/mcp-python-exec-sandbox'

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