run_python_code_in_sandbox
Execute Python code in a secure sandbox environment, manage dependencies, and retrieve outputs safely using the Modal MCP Toolbox. Ideal for isolated testing and script execution.
Instructions
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
Name | Required | Description | Default |
---|---|---|---|
code | Yes | The python code to run. | |
mount_directory | No | 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. | |
pull_files | No | 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). | |
python_version | No | The python version to use. If not provided defaults to 3.13 | 3.13 |
requirements | No | The 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"
}