Skip to main content
Glama

execute_code

Execute Python code in a secure sandbox environment for real-time lab scenarios and testing. Run and evaluate code remotely via the Model Context Protocol.

Instructions

Execute code in a secure sandbox environment.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
payloadNo
filepathNo
latest_generatedNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • app.py:385-410 (handler)
    The entry point for the 'execute_code' MCP tool, which orchestrates code preparation and calls the execution handler.
    @mcp.tool(name="execute_code", description="Execute code in a secure sandbox environment.")
    async def execute_code(
        payload: Optional[str] = None,
        filepath: Optional[str] = None,
        latest_generated: Optional[str] = None
    ) -> str:
        """
        Executes code in a secure sandbox.
        Accepts:
        - payload: code directly
        - filepath: path to code file
        - latest_generated: fallback prompt-generated code
        """
        host_id=""
        sample_code = read_code_input(payload, filepath, latest_generated)
        
        user_access = await handle_code_execution(sample_code)
    
        if "error" in user_access:
            return f"Error: {user_access['error']}"
        
        user_access_list = json.loads(user_access['userAccess'])
    
        # # Extract the ServerIP
        server_ip = next(item['value'] for item in user_access_list if item['key'] == 'ServerIP')
  • app.py:317-321 (handler)
    The handler function 'handle_code_execution' that initializes the lab session and language detection for code execution.
    async def handle_code_execution(payload: str) -> str:
        username = create_lab_sessionInfo()
        detected_lang = detect_language(payload)
        user_access = await _create_lab(username, detected_lang)
        return user_access
  • app.py:325-340 (handler)
    The core logic 'run_code_in_sandbox' that performs the actual code execution by sending a request to the sandbox server.
    async def run_code_in_sandbox(host_id: str, code: str) -> dict:
        url = f"http://{host_id}:8000/run_code"
        headers = {"Content-Type": "application/json"}
        payload = {"code": code}
    
        try:
            async with httpx.AsyncClient() as client:
                response = await client.post(url, headers=headers, json=payload)
                response.raise_for_status()
                result = response.json()
            
            return json.dumps({
                "status": "success",
                "message": "Code executed successfully.",
                "result": result
            })
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions a 'secure sandbox environment', which hints at isolation and safety, but lacks details on permissions, rate limits, output handling, or error behavior. This is a significant gap for a code execution tool with no structured safety hints.

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 a single, efficient sentence with zero waste, clearly stating the core function. It is appropriately sized and front-loaded, making it easy to parse without unnecessary elaboration.

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

Completeness3/5

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

Given the complexity of code execution, no annotations, 0% schema coverage, but an output schema exists, the description is incomplete. It covers the basic purpose but misses critical details like behavioral traits, parameter meanings, and execution constraints. The output schema may help with return values, but overall, it's minimally adequate with clear gaps.

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

Parameters2/5

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

The schema description coverage is 0%, so the description must compensate for three undocumented parameters. It adds no meaning beyond the tool name, failing to explain parameters like 'payload', 'filepath', or 'latest_generated'. This leaves the agent guessing about input semantics, resulting in poor parameter guidance.

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

Purpose3/5

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

The description states the tool's purpose as executing code in a secure sandbox environment, which is clear but vague. It specifies the action (execute code) and context (secure sandbox), but lacks details on what type of code, languages supported, or execution scope, making it moderately informative but not specific.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool, such as scenarios for execution, prerequisites, or alternatives. With no sibling tools, it doesn't need to differentiate, but it fails to offer any usage context, leaving the agent without direction on appropriate application.

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/Nuvepro-Technologies-Pvt-Ltd/genai-sandbox-nuvepro'

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