Skip to main content
Glama
milkymap

MCP4Modal Sandbox

by milkymap

pull_file_from_sandbox

Copy files from Modal sandbox environments to your local filesystem for analysis, backup, or debugging purposes.

Instructions

        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
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sandbox_idYes
sandbox_pathYes
local_pathYes

Implementation Reference

  • The core handler function that implements the pull_file_from_sandbox tool. It retrieves the sandbox, checks if it's running, reads the file content from the sandbox using a thread executor, writes it to the local path, and returns a response.
    async def pull_file_from_sandbox(
        self, 
        sandbox_id: str, 
        sandbox_path: str, 
        local_path: str
    ) -> PullFileFromSandboxResponse:
        # Get sandbox from Modal using from_id
        modal_sandbox = await modal.Sandbox.from_id.aio(sandbox_id)
    
        # Check if sandbox is running before copying file from sandbox
        sandbox_status = await modal_sandbox.poll.aio()
        if sandbox_status is not None:
            raise ToolError(f"Sandbox {sandbox_id} is not running")
        
        # Read from sandbox using thread executor
        content = await self._read_sandbox_file_in_thread(modal_sandbox, sandbox_path, 'rb')
        
        file_size = len(content)
        
        # Write to local file asynchronously
        makedirs(path.dirname(local_path), exist_ok=True)
        async with aiofiles.open(local_path, 'wb') as file_pointer:
            await file_pointer.write(content)
        
        logger.info(f"Copied file from {sandbox_path} to {local_path} from sandbox {sandbox_id}")
        
        return PullFileFromSandboxResponse(
            success=True,
            message=f"File copied successfully to {local_path}",
            file_size=file_size,
            sandbox_path=sandbox_path,
            local_path=local_path,
        )
  • The registration of the pull_file_from_sandbox tool in the FastMCP app, linking the name, description, and handler function.
        name="pull_file_from_sandbox",
        description=ToolDescriptions.PULL_FILE_FROM_SANDBOX,
    )(self.pull_file_from_sandbox)
  • Pydantic model defining the output schema/response structure for the pull_file_from_sandbox tool.
    class PullFileFromSandboxResponse(BaseModel):
        success: bool
        message: str
        sandbox_path: str
        local_path: str
        file_size: int
  • Tool description string used in registration, detailing parameters, returns, and usage of pull_file_from_sandbox.
    PULL_FILE_FROM_SANDBOX = """
            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
            """
  • Helper method to read file content from sandbox in a synchronous context via thread pool executor, used by the pull_file_from_sandbox handler.
    async def _read_sandbox_file_in_thread(self, modal_sandbox, file_path: str, mode: str = 'rb'):
        def _sync_read():
            with modal_sandbox.open(file_path, mode) as f:
                return f.read()
        
        loop = asyncio.get_event_loop()
        return await loop.run_in_executor(self.thread_pool_executor, _sync_read)
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing the multi-step behavior (verification, directory creation, copying, status return). It doesn't mention potential failure modes, permissions, or rate limits, but provides substantial operational transparency beyond basic function.

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 clear sections (purpose, parameters, returns, use cases, behavior). Some redundancy exists (parameters listed twice in different sections), but overall efficient with every sentence adding value. Could be slightly more front-loaded.

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

Completeness4/5

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

For a 3-parameter tool with no annotations and no output schema, the description provides comprehensive coverage: clear purpose, parameter meanings, return value structure, use cases, and operational steps. The main gap is lack of explicit error handling or constraints documentation.

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

Parameters4/5

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

Schema description coverage is 0%, but the description provides clear parameter documentation with meaningful explanations of each parameter's role. The description compensates well for the schema's lack of descriptions, though it doesn't specify format requirements (e.g., path syntax, sandbox ID format).

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 specific action ('Copies a file from a Modal sandbox to the local filesystem') with precise verb+resource combination. It distinguishes from siblings like 'push_file_to_sandbox' (reverse direction) and 'read_file_content_from_sandbox' (reads content without copying).

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?

The 'This tool is useful for' section provides clear context about when to use this tool (retrieving output files, backing up data, analyzing content, debugging). However, it doesn't explicitly state when NOT to use it or mention specific alternatives like 'read_file_content_from_sandbox' for content-only access.

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/milkymap/mcp4modal_sandbox'

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