remove_path
Remove files or directories from a Modal sandbox 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 handler function that executes the remove_path tool. It retrieves the Modal sandbox by ID, calls the rm method with the given path and recursive flag, logs the action, and returns a success response using 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)The registration of the remove_path tool in the FastMCP app, specifying name and description, bound to the self.remove_path handler.mcp_app.tool( name="remove_path", description=ToolDescriptions.REMOVE_PATH, )(self.remove_path)
- Pydantic schema for the SandboxRemovePathResponse returned by the remove_path handler.class SandboxRemovePathResponse(BaseModel): success: bool message: str path_removed: str
- The tool description string used in the registration of remove_path, 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 """