Skip to main content
Glama
MCP4Modal Sandbox

MCP4Modal Sandbox

by milkymap

MCP4Modal Sandbox

A powerful Model Context Protocol (MCP) server that provides seamless cloud-based sandbox management using Modal.com. This project enables LLMs and AI assistants to spawn, manage, and interact with isolated compute environments in the cloud with full GPU support.

Features

Core Sandbox Management

  • Launch Sandboxes: Create isolated Python environments with custom configurations

  • Terminate Sandboxes: Clean resource management and controlled shutdown

  • List Sandboxes: Monitor and track active sandbox environments

  • App Namespacing: Organize sandboxes within Modal app namespaces

Advanced Configuration

  • Python Versions: Support for multiple Python versions (default: 3.12)

  • Package Management: Install pip and apt packages during sandbox creation

  • Resource Allocation: Configure CPU cores, memory, and execution timeouts

  • Working Directory: Set custom working directories for sandbox environments

GPU Support

Comprehensive GPU support for machine learning and compute-intensive workloads:

  • T4: Entry-level GPU, ideal for inference workloads

  • L4: Mid-range GPU for general ML tasks

  • A10G: High-performance GPU for training (up to 4 GPUs)

  • A100-40GB/80GB: High-end GPUs for large-scale training

  • L40S: Latest generation GPU for ML workloads

  • H100: Latest generation high-end GPU

  • H200: Latest generation flagship GPU

  • B200: Latest generation enterprise GPU

File Operations

  • Push Files: Upload files from local filesystem to sandboxes

  • Pull Files: Download files from sandboxes to local filesystem

  • Read File Content: View file contents directly without downloading

  • Write File Content: Create and edit files within sandboxes

  • Directory Management: Create, list, and remove directories

Command Execution

  • Remote Execution: Run arbitrary commands in sandbox environments

  • Output Capture: Capture stdout, stderr, and return codes

  • Timeout Control: Configure execution timeouts for long-running tasks

  • Performance Metrics: Track execution time and resource usage

Security & Environment Management

  • Secrets Management: Inject environment variables and secrets

  • Predefined Secrets: Reference existing secrets from Modal dashboard

  • Volume Mounting: Attach persistent storage volumes

  • Isolated Environments: Complete isolation between sandbox instances

Transport Options

  • stdio: Direct command-line interface (default)

  • streamable-http: HTTP-based communication

  • SSE: Server-Sent Events for real-time updates

Related MCP server: MCP Python Interpreter

rerequisites

  • Python 3.12+

  • Modal.com account and API key

  • Environment variables configured (see Configuration section)

Installation

# Clone the repository
git clone https://github.com/milkymap/mcp4modal_sandbox.git
cd mcp4modal_sandbox

# Install dependencies
uv sync

# Install in development mode
uv pip install -e .

Using Docker

Build the Docker Image

# Build the Docker image
docker build -t mcp4modal-sandbox f Dockerfile .

Run with stdio Transport (Default)

# Run --help to find options
docker run -it \
  -e MODAL_TOKEN_ID="your_modal_token_id" \
  -e MODAL_TOKEN_SECRET="your_modal_token_secret" \
  mcp4modal-sandbox --help

Configuration

Environment Variables

Create a .env file in the project root:

# Required: Modal.com API Configuration
MODAL_TOKEN_ID="your_modal_token_id"
MODAL_TOKEN_SECRET="your_modal_token_secret"

# Optional: HTTP Transport Configuration (only needed for streamable-http/sse transports)
MCP_HOST="0.0.0.0"  # Default: 0.0.0.0
MCP_PORT=8000       # Default: 8000

Modal.com Setup

  1. Create an account at Modal.com

  2. Generate API tokens from your Modal dashboard

  3. Configure the tokens in your environment variables

Integration with Claude Desktop

Add to your Claude Desktop configuration:

uvx

{
  "mcpServers": {
    "mcp4modal-sandbox": {
        "command": "uvx",
        "args": [
          "mcp4modal-sandbox",
          "--transport", "stdio",
          "--app_name", "namespace",
          "--preloaded_secrets", "group0", // modal secret
          "--preloaded_secrets", "group1" // modal secret
          ],
        "env": {
          "MODAL_TOKEN_ID": "",
          "MODAL_TOKEN_SECRET": ""
        }
    }
  }
}

docker

{
  "mcpServers": {
    "mcp4modal-sandbox": {
        "command": "docker",
        "args": [
          "run", "--rm", "-i", "--name", "modal_sandbox",
          "-e", "MODAL_TOKEN_ID", "-e", "MODAL_TOKEN_SECRET", 
          "-v", "/path/to/volume", 
          "milkymap/modal_sandbox:0.1", 
          "--transport", "stdio",
          "--app_name", "namespace",
          "--preloaded_secrets", "group0",
          "--preloaded_secrets", "group1"
          ],
        "env": {
          "MODAL_TOKEN_ID": "",
          "MODAL_TOKEN_SECRET": ""
        }
    }
  }
}

Available Tools

The MCP server provides 11 tools for comprehensive sandbox management:

  1. launch_sandbox - Create new Modal sandboxes with custom configuration (Python version, packages, GPU, secrets)

  2. terminate_sandbox - Stop and clean up running sandboxes

  3. list_sandboxes - List all sandboxes in an app namespace with their status

  4. execute_command - Run shell commands in sandboxes and capture output

  5. push_file_to_sandbox - Upload files from local filesystem to sandboxes

  6. pull_file_from_sandbox - Download files from sandboxes to local filesystem

  7. list_directory_contents - List contents of directories within sandboxes

  8. make_directory - Create directories in sandboxes

  9. remove_path - Remove files or directories from sandboxes

  10. read_file_content_from_sandbox - Read file contents directly from sandboxes

  11. write_file_content_to_sandbox - Write content to files within sandboxes

Available Tools

11 tools
execute_commandA
        Executes a command in a specified Modal sandbox environment.
        
        Parameters:
        - sandbox_id: The unique identifier of the sandbox to run the command in
        - command: The shell command to execute (e.g. "python script.py", "ls -la", etc.)
        - working_dir: Optional working directory to execute the command from
        - timeout: Optional timeout in seconds for command execution
        
        Returns a SandboxExecuteResponse containing:
        - stdout: Standard output from the command execution
        - stderr: Standard error output from the command execution  
        - returncode: Exit code of the command (0 typically indicates success)
        - execution_time: Time taken to execute the command in seconds
        
        This tool is useful for:
        - Running arbitrary commands in isolated sandbox environments
        - Testing scripts and programs in clean environments
        - Executing programs with specific dependencies
        - Debugging environment-specific issues
        - Running automated tests in isolation
        
        The tool will:
        1. Verify the sandbox exists and is running
        2. Execute the specified command in that sandbox
        3. Capture all output and timing information
        4. Return detailed execution results
        

Inputs: sandbox_id (required), command (required), timeout_seconds.

launch_sandboxA
        Launches a new Modal sandbox with specified configuration.
        
        Parameters:
        - python_version: Python version to use (default: "3.12")
        - pip_packages: List of pip packages to install
        - apt_packages: List of apt packages to install
        - timeout_seconds: Maximum runtime in seconds (default: 3600)
        - cpu: CPU cores allocated (default: 1.0)
        - memory: Memory in MB allocated (default: 1024)
        - secrets: Dictionary of environment variables to inject (creates new secret)
        - volumes: Dictionary of volumes to mount in sandbox, where the key is the path in the sandbox and the value is the name of the volume
        - workdir: Working directory in sandbox (default: "/")
        - gpu_type: Type of GPU to use (optional). Supported types:
          * T4: Entry-level GPU, good for inference
          * L4: Mid-range GPU, good for general ML tasks
          * A10G: High-performance GPU, good for training
          * A100-40GB: High-end GPU with 40GB memory
          * A100-80GB: High-end GPU with 80GB memory
          * L40S: Latest generation GPU, good for ML workloads
          * H100: Latest generation high-end GPU
          * H200: Latest generation flagship GPU
          * B200: Latest generation enterprise GPU
        - gpu_count: Number of GPUs to use (optional, default: 1)
          * A10G supports up to 4 GPUs
          * Other types support up to 8 GPUs
        
        Returns a SandboxLaunchResponse containing:
        - sandbox_id: Unique identifier for the sandbox
        - status: Current status of the sandbox
        - python_version: Python version installed
        - pip_packages: List of pip packages installed
        - apt_packages: List of apt packages installed
        - preloaded_secrets: List of predefined secrets injected from Modal dashboard
        
        This tool is useful for:
        - Creating isolated Python environments
        - Running code with specific dependencies
        - Testing in clean environments
        - Executing long-running tasks
        - Running GPU-accelerated workloads
        - Training machine learning models
        - Running inference on large models
        
        Secrets Management:
        - Use 'secrets' parameter to create new secrets with key-value pairs
        - Use 'inject_predefined_secrets' to reference existing secrets from Modal dashboard
        - Predefined secrets are applied after custom secrets, so they can override values
        - Access secrets as environment variables in your sandbox code using os.environ
        

Inputs: python_version, pip_packages, apt_packages, timeout_seconds, +7 more.

list_directory_contentsA
        Lists contents of a directory in the sandbox.
        
        Parameters:
        - sandbox_id: The unique identifier of the sandbox
        - path: Directory path to list in the sandbox
        
        Returns a SandboxListDirectoryResponse containing:
        - contents: List of filenames/directories at the specified path
        
        This tool is useful for:
        - Exploring sandbox filesystem structure
        - Verifying file operations
        - Debugging file-related issues
        - Managing sandbox content
        
        The tool will:
        1. Verify sandbox and directory exist
        2. List all contents at specified path
        3. Return directory listing
        

Inputs: sandbox_id (required), path (required).

list_sandboxesA
        Lists all Modal sandboxes for a specific app namespace and their current status.
        
        Parameters:
        - app_name: Name of the Modal app namespace to list sandboxes for
        
        Returns a list of sandboxes containing:
        - sandbox_id: Unique identifier for each sandbox
        - sandbox_status: Current state of the sandbox (running/stopped)
        
        This tool is useful for:
        - Monitoring active Modal sandbox environments within an app namespace
        - Checking which sandboxes are currently running
        - Getting sandbox IDs for further management operations
        

Inputs: no named parameters.

make_directoryA
        Creates a new directory in the sandbox.
        
        Parameters:
        - sandbox_id: The unique identifier of the sandbox
        - path: Directory path to create in the sandbox
        - parents: Whether to create parent directories if they don't exist
        
        Returns a SandboxMakeDirectoryResponse containing:
        - success: Boolean indicating if directory creation was successful
        - message: Descriptive message about the operation
        - path_created: The path that was created
       
        
        This tool is useful for:
        - Setting up directory structures
        - Preparing for file operations
        - Organizing sandbox content
        
        The tool will:
        1. Verify sandbox exists and is running
        2. Create directory at specified path
        3. Return status of the operation
        

Inputs: sandbox_id (required), path (required), parents.

pull_file_from_sandboxA
        Copies a file from a Modal sandbox to the local filesystem.
        
        Parameters:
        - sandbox_id: The unique identifier of the sandbox
        - sandbox_path: Path to the file in the sandbox
        - local_path: Destination path on local filesystem
        
        Returns a PullFileFromSandboxResponse containing:
        - success: Boolean indicating if copy was successful
        - message: Descriptive message about the copy operation
        - sandbox_path: The source path in sandbox
        - local_path: The destination path on local filesystem
        - file_size: Size of the file in bytes
       
        
        This tool is useful for:
        - Retrieving output files from sandbox executions
        - Backing up sandbox data
        - Analyzing sandbox-generated content locally
        - Debugging sandbox operations
        
        The tool will:
        1. Verify sandbox and source file exist
        2. Create local destination directory if needed
        3. Copy file contents from sandbox to local system
        4. Return status of the operation
        

Inputs: sandbox_id (required), sandbox_path (required), local_path (required).

push_file_to_sandboxA
        Copies a file from the local filesystem to a Modal sandbox.
        
        Parameters:
        - sandbox_id: The unique identifier of the sandbox
        - local_path: Path to the source file on local filesystem
        - sandbox_path: Destination path in the sandbox
        - read_file_mode: Optional mode for reading local file (default: "rb")
        - writefile_mode: Optional mode for writing to sandbox (default: "wb")
        
        Returns a PushFileToSandboxResponse containing:
        - success: Boolean indicating if copy was successful
        - message: Descriptive message about the copy operation
        - local_path: The source path on local filesystem
        - sandbox_path: The destination path in sandbox
        - file_size: Size of the file in bytes
        
        This tool is useful for:
        - Uploading input files to sandboxes
        - Transferring configuration files
        - Setting up sandbox environments
        - Deploying code to sandboxes
        
        The tool will:
        1. Verify sandbox is running and local file exists
        2. Read contents from local file
        3. Write contents to sandbox path
        4. Return status of the operation
        

Inputs: sandbox_id (required), local_path (required), sandbox_path (required), read_file_mode, +1 more.

read_file_content_from_sandboxA
        Reads the content of a file in the sandbox.
        
        Parameters:
        - sandbox_id: The unique identifier of the sandbox
        - path: Path to the file to read
        
        Returns a SandboxReadFileContentResponse containing:
        - content: String content of the file
        
        This tool is useful for:
        - Viewing file contents without downloading
        - Debugging sandbox operations
        - Checking operation results
        - Quick file inspection
        
        The tool will:
        1. Verify sandbox and file exist
        2. Read file contents
        3. Return file content as string
        

Inputs: sandbox_id (required), path (required).

remove_pathA
        Removes a file or directory from the sandbox.
        
        Parameters:
        - sandbox_id: The unique identifier of the sandbox
        - path: Path to remove from the sandbox
        - recursive: Whether to remove the path recursively
        
        Returns a SandboxRemovePathResponse containing:
        - success: Boolean indicating if removal was successful
        - message: Descriptive message about the operation
        - path_removed: The path that was removed
       
        
        This tool is useful for:
        - Cleaning up temporary files
        - Removing unwanted content
        - Managing sandbox storage
        
        The tool will:
        1. Verify sandbox exists and is running
        2. Remove specified path (file or directory)
        3. Return status of the operation
        

Inputs: sandbox_id (required), path (required), recursive.

terminate_sandboxA
        Terminates a Modal sandbox by its ID.
        
        Parameters:
        - sandbox_id: The unique identifier of the sandbox to terminate
        
        Returns a SandboxTerminateResponse containing:
        - success: Boolean indicating if termination was successful
        - message: Detailed message about the termination result
        
        This tool is useful for:
        - Stopping running sandboxes that are no longer needed
        - Cleaning up resources
        - Forcefully ending long-running or stuck sandboxes
        - Managing sandbox lifecycle
        
        The tool will:
        1. Check if the sandbox exists and is running
        2. Send termination signal if running
        3. Wait for confirmation of termination
        4. Return status of the operation
        

Inputs: sandbox_id (required).

write_file_content_to_sandboxA
        Writes content to a file in a Modal sandbox.
        This is useful for writing code, text, or any other content to a file in the sandbox.

        Parameters:
        - sandbox_id: ID of the target sandbox where code will be written
        - sandbox_path: Path where the code file should be created/written in the sandbox
        - content: Content to write to the file

        Returns a SandboxWriteCodeResponse containing:
        - success: Boolean indicating if code was written successfully
        - message: Descriptive message about the operation
        - file_path: Path where code was written in sandbox

        This tool is powerful for:
        - Rapid prototyping and code generation
        - Creating boilerplate code
        - Implementing algorithms from descriptions
        - Converting pseudocode to actual code
        - Generating test cases
        - Creating utility functions and helper code

        The tool will:
        1. Verify the sandbox is running
        2. Write content to specified path in sandbox
        3. Handle errors and provide detailed feedback

Inputs: sandbox_id (required), sandbox_path (required), content (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.4/5.0

    Scored across 11 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose with no overlap. For example, execute_command runs commands, launch_sandbox creates sandboxes, list_directory_contents lists files, and push_file_to_sandbox transfers files, all serving unique functions within the sandbox management domain. The descriptions clearly differentiate between creation, execution, file operations, and lifecycle management.

    Naming Consistency4/5

    Most tools follow a consistent verb_noun pattern (e.g., execute_command, launch_sandbox, list_directory_contents). However, there are minor deviations like pull_file_from_sandbox and push_file_to_sandbox using 'from/to' prepositions, and read_file_content_from_sandbox being slightly verbose compared to others. Overall, the naming is highly readable and predictable.

    Tool Count5/5

    With 11 tools, this server is well-scoped for managing Modal sandboxes. The count covers essential operations like sandbox lifecycle (launch, terminate), file management (read, write, push, pull, list, remove), and command execution, without being excessive. Each tool earns its place by addressing a specific need in the domain.

    Completeness5/5

    The tool set provides complete coverage for sandbox management, including CRUD-like operations: create (launch_sandbox), read (list_sandboxes, read_file_content_from_sandbox, list_directory_contents), update (write_file_content_to_sandbox, push_file_to_sandbox), and delete (terminate_sandbox, remove_path). It also supports execution (execute_command) and file transfer (pull_file_from_sandbox), ensuring no dead ends for agents working with sandboxes.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      F
      maintenance
      A Model Context Protocol server that enables AI assistants like Claude to perform Python development tasks through file operations, code analysis, project management, and safe code execution.
      9
      MIT
    • F
      license
      A
      quality
      Not graded
      maintenance
      A Model Context Protocol server that allows LLMs to interact with Python environments, enabling code execution, file operations, package management, and development workflows.
      9
      -
    • A
      license
      B
      quality
      D
      maintenance
      A secure Model Context Protocol server that allows AI assistants and LLM applications to safely execute Python and JavaScript code snippets in containerized environments.
      2
      205
      MIT