remove_path
Remove files or directories from a Modal sandbox environment to clean up temporary data, manage storage, and delete unwanted content.
Instructions
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
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sandbox_id | Yes | ||
| path | Yes | ||
| recursive | No |
Implementation Reference
- The core handler function that executes the tool logic: fetches the sandbox, calls modal_sandbox.rm.aio to remove the path (recursively if specified), logs the action, and returns a SandboxRemovePathResponse.async def remove_path(self, sandbox_id: str, path: str, recursive: bool = False) -> SandboxRemovePathResponse: # Get sandbox from Modal using from_id modal_sandbox = await modal.Sandbox.from_id.aio(sandbox_id) await modal_sandbox.rm.aio(path, recursive=recursive) logger.info(f"Removed path {path} in sandbox {sandbox_id}") return SandboxRemovePathResponse( success=True, message=f"Path {path} removed successfully", path_removed=path, )
- src/mcp4modal_sandbox/backend/mcp_server.py:141-144 (registration)Registers the 'remove_path' tool with the FastMCP server, linking it to the handler method and providing the description.mcp_app.tool( name="remove_path", description=ToolDescriptions.REMOVE_PATH, )(self.remove_path)
- Pydantic model defining the structure of the tool's response, used for output validation.class SandboxRemovePathResponse(BaseModel): success: bool message: str path_removed: str
- Tool description string used in registration, detailing parameters, returns, and usage.REMOVE_PATH = """ 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 """