A secure, container-based implementation of the Model Context Protocol (MCP) for executing tools on behalf of large language models.
Overview
Container-MCP provides a sandboxed environment for safely executing code, running commands, accessing files, and performing web operations requested by large language models. It implements the MCP protocol to expose these capabilities as tools that can be discovered and called by AI systems in a secure manner.
The architecture uses a domain-specific manager pattern with multi-layered security to ensure tools execute in isolated environments with appropriate restrictions, protecting the host system from potentially harmful operations.
Executes Python code in a secure sandbox environment.
**Parameters**:
- `code` (string, required): Python code to execute
- `working_dir` (string, optional): Working directory (ignored in sandbox)
**Returns**:
- `output` (string): Print output from the code
- `error` (string): Error output from the code
- `result` (any): Optional return value (available if code sets `_` variable)
- `success` (boolean): Whether code executed successfully
`system_env_var`
Gets environment variable values.
**Parameters**:
- `var_name` (string, optional): Specific variable to retrieve
**Returns**:
- `variables` (object): Dictionary of environment variables
- `requested_var` (string): Value of the requested variable (if var_name provided)
File Operations
`file_read`
Reads file contents safely.
**Parameters**:
- `path` (string, required): Path to the file (relative to sandbox root)
- `encoding` (string, optional): File encoding (default: "utf-8")
**Returns**:
- `content` (string): File content
- `size` (integer): File size in bytes
- `modified` (float): Last modified timestamp
- `success` (boolean): Whether the read was successful
`file_write`
Writes content to a file safely.
**Parameters**:
- `path` (string, required): Path to the file (relative to sandbox root)
- `content` (string, required): Content to write
- `encoding` (string, optional): File encoding (default: "utf-8")
**Returns**:
- `success` (boolean): Whether the write was successful
- `path` (string): Path to the written file
`file_list`
Lists contents of a directory safely.
**Parameters**:
- `path` (string, optional): Path to the directory (default: "/")
- `pattern` (string, optional): Glob pattern to filter files
**Returns**:
- `entries` (array): List of directory entries with metadata
- `path` (string): The listed directory path
- `success` (boolean): Whether the listing was successful
`file_delete`
Deletes a file safely.
**Parameters**:
- `path` (string, required): Path of the file to delete
**Returns**:
- `success` (boolean): Whether the deletion was successful
- `path` (string): Path to the deleted file
**Returns**:
- `success` (boolean): Whether the move was successful
- `source` (string): Original file path
- `destination` (string): New file path
Web Operations
`web_search`
Uses a search engine to find information on the web.
**Parameters**:
- `query` (string, required): The query to search for
**Returns**:
- `results` (array): List of search results
- `query` (string): The original query
`web_scrape`
Scrapes a specific URL and returns the content.
**Parameters**:
- `url` (string, required): The URL to scrape
- `selector` (string, optional): CSS selector to target specific content
**Returns**:
- `content` (string): Scraped content
- `url` (string): The URL that was scraped
- `title` (string): Page title
- `success` (boolean): Whether the scrape was successful
- `error` (string): Error message if scrape failed
`web_browse`
Interactively browses a website using Playwright.
**Parameters**:
- `url` (string, required): Starting URL for browsing session
**Returns**:
- `content` (string): Page HTML content
- `url` (string): The final URL after any redirects
- `title` (string): Page title
- `success` (boolean): Whether the browsing was successful
- `error` (string): Error message if browsing failed
Execution Environment
Container-MCP provides isolated execution environments for different types of operations, each with its own security measures and resource constraints.
Container Environment
The main Container-MCP service runs inside a container (using Podman or Docker) providing the first layer of isolation:
**Base Image**: Ubuntu 24.04
**User**: Non-root ubuntu user
**Python**: 3.12
**Network**: Limited to localhost binding only
**Filesystem**: Volume mounts for configuration, data, and logs
**Security**: AppArmor, Seccomp, and capability restrictions
Bash Execution Environment
The Bash execution environment is configured with multiple isolation layers:
**Allowed Commands**: Restricted to safe commands configured in `BASH_ALLOWED_COMMANDS`
**Firejail Sandbox**: Process isolation with restricted filesystem access
**AppArmor Profile**: Fine-grained access control
**Resource Limits**:
- Execution timeout (default: 30s, max: 120s)
- Limited directory access to sandbox only
**Network**: No network access
**File System**: Read-only access to data, read-write to sandbox
Example allowed commands:
Python Execution Environment
The Python execution environment is designed for secure code execution:
Once the container is running, you can connect to it using any MCP client implementation. The server will be available at `http://localhost:8000` or the port specified in your configuration.
**Important:** When configuring your MCP client, you must set the endpoint URL to `http://127.0.0.1:<port>/sse` (where `<port>` is 8000 by default or the port you've configured). The `/sse` path is required for proper server-sent events communication.
Example Python Client
Configuration
Container-MCP can be configured through environment variables, which can be set in `volume/config/custom.env`: