Modal MCP Toolbox

run_python_code_in_sandbox

Runs python code in a safe environment and returns the output. Usage: run_python_code_in_sandbox("print('Hello, world!')") run_python_code_in_sandbox("import requests

print(requests.get('https://icanhazip.com').text)", requirements=["requests"])

Input Schema

NameRequiredDescriptionDefault
codeYesThe python code to run.
mount_directoryNoAllows you to make a local directory available at `/mounted-dir` for the code in `code`. Needs to be an absolute path. Writes to this directory will NOT be reflected in the local directory.
pull_filesNoList of tuples (absolut_path_sandbox_file, absolute_path_local_file). When provided downloads the file(s) from the sandbox to the local file(s).
python_versionNoThe python version to use. If not provided defaults to 3.133.13
requirementsNoThe requirements to install.

Input Schema (JSON Schema)

{ "properties": { "code": { "description": "The python code to run.", "title": "Code", "type": "string" }, "mount_directory": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Allows you to make a local directory available at `/mounted-dir` for the code in `code`. Needs to be an absolute path. Writes to this directory will NOT be reflected in the local directory.", "title": "Mount Directory" }, "pull_files": { "anyOf": [ { "items": { "maxItems": 2, "minItems": 2, "prefixItems": [ { "type": "string" }, { "type": "string" } ], "type": "array" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "List of tuples (absolut_path_sandbox_file, absolute_path_local_file). When provided downloads the file(s) from the sandbox to the local file(s).", "title": "Pull Files" }, "python_version": { "default": "3.13", "description": "The python version to use. If not provided defaults to 3.13", "title": "Python Version", "type": "string" }, "requirements": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "The requirements to install.", "title": "Requirements" } }, "required": [ "code" ], "title": "run_python_code_in_sandboxArguments", "type": "object" }