Skip to main content
Glama
milkymap

MCP4Modal Sandbox

by milkymap

push_file_to_sandbox

Copy files from your local system to a Modal sandbox environment for uploading inputs, transferring configurations, or deploying code to isolated cloud-based Python environments.

Instructions

        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
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sandbox_idYes
local_pathYes
sandbox_pathYes
read_file_modeNorb
writefile_modeNowb

Implementation Reference

  • The handler function that implements the push_file_to_sandbox tool logic: reads local file content and writes it to the sandbox using a thread executor.
    async def push_file_to_sandbox(
        self, 
        sandbox_id: str, 
        local_path: str, 
        sandbox_path: str,
        read_file_mode: str = "rb",
        writefile_mode: str = "wb"
    ) -> PushFileToSandboxResponse:
        # 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
        sandbox_status = await modal_sandbox.poll.aio()
        if sandbox_status is not None:
            raise ToolError(f"Sandbox {sandbox_id} is not running")
        
        if not path.exists(local_path):
            raise ToolError(f"Local file {local_path} does not exist")
        
        # Get file size
        file_size = os.path.getsize(local_path)
        
        # Read local file asynchronously
        async with aiofiles.open(local_path, read_file_mode) as file_pointer:
            content = await file_pointer.read()
        
        # Write to sandbox using thread executor
        await self._write_sandbox_file_in_thread(modal_sandbox, sandbox_path, content, writefile_mode)
        
        logger.info(f"Copied file from {local_path} to {sandbox_path} in sandbox {sandbox_id}")
        
        return PushFileToSandboxResponse(
            success=True,
            message=f"File copied successfully to {sandbox_path}",
            local_path=local_path,
            sandbox_path=sandbox_path,
            file_size=file_size,
        )
  • Pydantic model defining the response schema for the push_file_to_sandbox tool.
    class PushFileToSandboxResponse(BaseModel):
        success: bool
        message: str
        local_path: str
        sandbox_path: str
        file_size: int
  • Registration of the push_file_to_sandbox tool with the FastMCP server.
    mcp_app.tool(
        name="push_file_to_sandbox",
        description=ToolDescriptions.PUSH_FILE_TO_SANDBOX,
    )(self.push_file_to_sandbox)
  • Helper function used by the handler to write file content to the sandbox in a synchronous manner via thread pool executor.
    async def _write_sandbox_file_in_thread(self, modal_sandbox, file_path: str, content, mode: str = 'wb'):
        def _sync_write():
            with modal_sandbox.open(file_path, mode) as f:
                f.write(content)
        
        loop = asyncio.get_event_loop()
        return await loop.run_in_executor(self.thread_pool_executor, _sync_write)
Behavior5/5

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

With no annotations provided, the description carries full burden and delivers comprehensive behavioral disclosure. It describes the multi-step process (verification, reading, writing, returning status), mentions preconditions (sandbox must be running, local file must exist), and details the response structure including success indicators and file metadata. This goes well beyond basic functionality description.

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?

The description is well-structured with clear sections (purpose, parameters, returns, use cases, process) and every sentence adds value. However, it could be slightly more front-loaded by moving the 'useful for' section after the core description rather than after the return values. The length is appropriate for a 5-parameter tool with no annotations.

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

Completeness5/5

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

For a file transfer tool with 5 parameters, no annotations, and no output schema, the description provides excellent completeness. It covers purpose, all parameters with semantics, return value structure, use cases, and operational behavior. The agent has everything needed to understand when and how to use this tool effectively without needing additional structured data.

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

Parameters5/5

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

Despite 0% schema description coverage, the description provides complete parameter documentation with clear explanations for all 5 parameters, including optional parameters with their defaults. It adds meaningful context about what each parameter represents (e.g., 'unique identifier of the sandbox', 'path to source file on local filesystem', 'destination path in sandbox') that the schema titles alone don't convey.

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') and resources involved ('from the local filesystem to a Modal sandbox'), distinguishing it from sibling tools like pull_file_from_sandbox (reverse direction) and write_file_content_to_sandbox (creates content rather than copying files). The verb+resource combination is precise and unambiguous.

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 description provides clear context about when to use this tool ('useful for uploading input files, transferring configuration files, setting up sandbox environments, deploying code'), but doesn't explicitly state when NOT to use it or mention specific alternatives like write_file_content_to_sandbox for creating new files from content rather than copying existing files. The guidance is helpful but lacks exclusion criteria.

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