Uses Docker for container isolation as a security layer when executing tools on behalf of AI systems.
Designed to run on Linux systems with features like AppArmor profiles and Firejail for sandboxing.
Uses Podman as an alternative to Docker for container isolation when executing tools on behalf of AI systems.
Supports testing through pytest for validating server functionality.
Provides sandboxed Python code execution with security controls including memory limits, execution timeouts, and library restrictions.
Uses Ubuntu 24.04 as the base container image for running the MCP server environment.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Container-MCPrun python code to calculate the factorial of 10"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Container-MCP
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.
Related MCP server: MCP Local File Reader
Key Features
Multi-layered Security
Container isolation using Podman/Docker
AppArmor profiles for restricting access
Firejail sandboxing for additional isolation
Resource limits (CPU, memory, execution time)
Path traversal prevention
Allowed extension restrictions
MCP Protocol Implementation
Standardized tool discovery and execution
Resource management
Async execution support
Domain-Specific Managers
BashManager: Secure command executionPythonManager: Sandboxed Python code executionFileManager: Safe file operationsWebManager: Secure web browsing and scrapingKnowledgeBaseManager: Structured document storage with semantic searchListManager: Organized list and collection managementMarketManager: Stock and cryptocurrency data via Yahoo FinanceRssManager: RSS and Atom feed fetching
Configurable Environment
Extensive configuration via environment variables
Custom environment support
Development and production modes
Available Tools
System Operations
system_run_command
Executes bash commands in a secure sandbox environment.
Parameters:
command(string, required): The bash command to executeworking_dir(string, optional): Working directory (ignored in sandbox)
Returns:
stdout(string): Command standard outputstderr(string): Command standard errorexit_code(integer): Command exit codesuccess(boolean): Whether command completed successfully
system_run_python
Executes Python code in a secure sandbox environment.
Parameters:
code(string, required): Python code to executeworking_dir(string, optional): Working directory (ignored in sandbox)
Returns:
output(string): Print output from the codeerror(string): Error output from the coderesult(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 variablesrequested_var(string): Value of the requested variable (if var_name provided)
health_check
Gets server health status and system information.
Parameters: None
Returns:
status(string): Server health statustimestamp(string): Current ISO timestampserver(object): Server details (name, host, port, platform, python_version)system(object): System metrics (cpu_percent, memory_percent, disk_percent)managers(object): Status of each manager (enabled/disabled)
File Operations
fs_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 contentsize(integer): File size in bytesmodified(float): Last modified timestampsuccess(boolean): Whether the read was successful
fs_write
Writes content to a file safely.
Parameters:
path(string, required): Path to the file (relative to sandbox root)content(string, required): Content to writeencoding(string, optional): File encoding (default: "utf-8")
Returns:
success(boolean): Whether the write was successfulpath(string): Path to the written file
fs_list
Lists contents of a directory safely.
Parameters:
path(string, optional): Path to the directory (default: "/")pattern(string, optional): Glob pattern to filter filesrecursive(boolean, optional): Whether to list recursively (default: true)
Returns:
entries(array): List of directory entries with metadatapath(string): The listed directory pathsuccess(boolean): Whether the listing was successful
fs_delete
Deletes a file safely.
Parameters:
path(string, required): Path of the file to delete
Returns:
success(boolean): Whether the deletion was successfulpath(string): Path to the deleted file
fs_move
Moves or renames a file safely.
Parameters:
source_path(string, required): Source file pathdestination_path(string, required): Destination file path
Returns:
success(boolean): Whether the move was successfulsource_path(string): Original file pathdestination_path(string): New file path
fs_apply_diff
Applies a unified diff patch to a file in the sandbox filesystem.
Parameters:
path(string, required): Path to the file to patch (relative to sandbox root)diff(string, required): Unified diff content to apply
Returns:
success(boolean): Whether the patch was applied successfullypath(string): Path to the patched filelines_applied(integer): Number of lines changednew_size(integer): New file size in byteserror(string): Error message if patch failed
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 resultsquery(string): The original query
web_scrape
Scrapes a specific URL and returns the content.
Parameters:
url(string, required): The URL to scrapeselector(string, optional): CSS selector to target specific contentoutput_format(string, optional): Use"markdown"to return Markdown (preserves links). Default is plain text.
Returns:
content(string): Scraped contenturl(string): The URL that was scrapedtitle(string): Page titlesuccess(boolean): Whether the scrape was successfulerror(string): Error message if scrape failed
Markdown output example:
web_browse
Interactively browses a website using Playwright.
Note: web_browse requires Playwright browser binaries. Outside the container, install them with python -m playwright install chromium (or playwright install).
Parameters:
url(string, required): Starting URL for browsing session
Returns:
content(string): Page HTML contenturl(string): The final URL after any redirectstitle(string): Page titlesuccess(boolean): Whether the browsing was successfulerror(string): Error message if browsing failed
Knowledge Base Operations
The knowledge base system provides structured document storage with semantic search capabilities, RDF-style relationships, and metadata management. Documents are organized in a hierarchical namespace structure and support preferences (arbitrary RDF triples) and references (links between documents).
Document URI Format
Knowledge base documents use a structured URI format: kb://namespace/collection[/subcollection]*/name
namespace: Top-level organizational unit (e.g., "projects", "research")
collection: Main category within namespace (e.g., "documentation", "notes")
subcollection: Optional nested categories (e.g., "api", "tutorials")
name: Document identifier (e.g., "getting-started", "user-guide")
Examples:
kb://projects/docs/api-referencekb://research/papers/machine-learning/transformerskb://personal/notes/meeting-2024-01-15
kb_create_document
Creates a new document in the knowledge base with optional metadata and content.
Parameters:
uri(string, required): Document URI in format "kb://namespace/collection[/subcollection]*/name"metadata(object, optional): Document metadata (default: {})content(string, optional): Document content (allows single-step create and write)
Returns:
Complete document index object with creation details
Notes: You can create a document with content in a single step by providing the
contentparameter, or use a two-step process by creating first and then adding content withkb_write_content.
kb_write_content
Writes content to an existing document in the knowledge base.
Parameters:
uri(string, required): Document URIcontent(string, required): Document contentforce(boolean, optional): Whether to overwrite existing content (default: false)
Returns:
Complete updated document index object
Notes: Document must be created first using
kb_create_document.
kb_read
Reads document data from the knowledge base. When called without a uri, lists all documents (replacing the need for a separate list operation).
Parameters:
uri(string, optional): Document URI. If omitted, lists all documents.recursive(boolean, optional): Whether to list recursively (default: true)include_content(boolean, optional): Whether to include document content (default: false)include_index(boolean, optional): Whether to include document metadata (default: false)
Returns:
Document data based on requested components. Operates in three modes:
list mode: When
uriis omitted, returns a list of document URIsbulk_read mode: When
uriis a partial path (namespace or collection), returns multiple documentsread mode: When
uriis a full document path, returns a single document
Reading a single document:
Listing all documents (no uri):
kb_update_triples
Manages RDF triples (preferences, references, and metadata) for documents. This tool also handles metadata updates via triple_type="metadata", replacing the need for a separate metadata update operation.
Parameters:
action(string, required): Action to perform ("add" or "remove")triple_type(string, required): Type of triple ("preference", "reference", or "metadata")uri(string, required): Source document URIpredicate(string, required): Predicate of the tripleobject(string, optional): Object of the triple (for preferences and metadata)ref_uri(string, optional): Referenced document URI (for references only)
Returns:
Operation status and updated counts
Adding a preference (arbitrary RDF triple):
Adding a reference (link to another document):
Updating metadata:
Removing a reference:
kb_search
Searches the knowledge base using text queries and/or graph expansion.
Parameters:
query(string, optional): Text query for semantic search and rerankingseed_uris(array, optional): Starting full URIs (kb://namespace/collection/name) for graph expansionroot_uri(string, optional): Partial URI (kb://namespace or kb://namespace/collection) to scope searchexpand_hops(integer, optional): Number of relationship hops to expand (default: 0)filter_uris(array, optional): URIs to exclude from resultsrelation_predicates(array, optional): Predicates to follow during graph traversal (default: ["references"])top_k_sparse(integer, optional): Number of sparse search results to retrieve (default: 50)top_k_rerank(integer, optional): Number of final results after reranking (default: 10)include_content(boolean, optional): Whether to include document content (default: false)include_index(boolean, optional): Whether to include document metadata (default: false)use_reranker(boolean, optional): Whether to use semantic reranking (default: true)
Returns:
Ranked list of search results
kb_manage
Manages knowledge base operations like moving documents and rebuilding search indices.
Parameters:
action(string, required): Management action to perform"move_document": Move a document"delete": Archive a document"rebuild_search_index": Rebuild search indices
options(object, required): Action-specific optionsFor
"move_document":{"uri": "...", "new_uri": "..."}For
"delete":{"uri": "..."}For
"rebuild_search_index":{"rebuild_all": true}(optional)
Returns:
Operation status and results
Moving a document:
Archiving a document:
List Operations
The list system provides org-mode based list management for tasks, notes, shopping, and general collections. Lists support various item statuses and can be tagged for organization.
Item Statuses
Items in lists can have the following statuses: TODO, DONE, WAITING, CANCELLED, NEXT, SOMEDAY
List Types
Lists can be one of: todo, shopping, notes, checklist, project, reading, ideas
list_create
Creates a new organized list for tasks, notes, shopping, or any collection.
Parameters:
name(string, required): Internal name for the list (used for filename)title(string, optional): Display title for the listlist_type(string, optional): Type of list (default: "todo")description(string, optional): Optional descriptiontags(array, optional): Tags for organizationproperties(object, optional): Custom user-defined properties
Returns:
success(boolean): Whether creation succeededname(string): List namemetadata(object): Title, type, created timestamp, propertiespath(string): File path
list_get
Retrieves and browses lists with flexible filtering options.
Parameters:
name(string, optional): Name of specific list to retrieve. If omitted, lists all available lists.include_items(boolean, optional): Whether to include items in response (default: true)summary_only(boolean, optional): Return only summary statistics without items (default: false)status_filter(string, optional): Filter items by status (TODO, DONE, WAITING, CANCELLED, NEXT, SOMEDAY)tag_filter(array, optional): Filter items by tags (items must have ALL specified tags)
Returns:
When
nameis omitted:lists(array of summaries),countWhen
nameis provided:name,metadata,items,statistics
Listing all lists:
Getting a specific list:
list_modify
Modifies list items by adding, updating, or removing them.
Parameters:
list_name(string, required): Name of the listaction(string, required): Operation to perform ("add", "update", or "remove")item_text(string, optional): Text of item (required for "add", optional for "update")item_index(integer, optional): Index of item (required for "update" and "remove")status(string, optional): Item status (TODO, DONE, WAITING, CANCELLED, NEXT, SOMEDAY)tags(array, optional): Tags for the itemproperties(object, optional): Custom properties
Returns:
success(boolean): Whether the operation succeededaction(string): The action performeditem(object): The affected item details
Adding an item:
Updating an item:
Removing an item:
list_update
Updates list properties and metadata. Properties use merge semantics — only provided keys are updated, existing keys are preserved.
Parameters:
name(string, required): Name of the listtitle(string, optional): New titlelist_type(string, optional): New list typedescription(string, optional): New descriptiontags(array, optional): New tags (replaces existing)author(string, optional): New authorproperties(object, optional): Custom properties (merged with existing)
Returns:
success(boolean): Whether the update succeededname(string): List namemetadata(object): Updated metadata
list_delete
Permanently deletes an entire list and all its items. The list file will be archived for safety but the list will no longer be accessible through normal operations.
Parameters:
name(string, required): Name of the list to delete
Returns:
success(boolean): Whether the deletion succeededname(string): Deleted list nameitems_count(integer): Number of items that were in the listarchived_to(string): Archive file path
list_search
Searches for items across multiple lists by text or tags.
Parameters:
query(string, required): Search query stringlist_names(array, optional): Specific lists to search in (searches all if omitted)search_in(array, optional): Where to search: "text", "tags", or both (default: ["text"])case_sensitive(boolean, optional): Whether search is case-sensitive (default: false)
Returns:
matches(array): List of matching items with list contexttotal_matches(integer): Total number of matcheslists_searched(integer): Number of lists searchedsearch_options(object): Applied search parameters
Market Operations
The market system provides financial data queries using Yahoo Finance for stocks and cryptocurrencies.
market_query
Queries stock or cryptocurrency prices with fundamentals, news, and trend analysis.
Parameters:
symbol(string, required): Stock/crypto symbol (e.g., "AAPL", "BTC-USD", "TSLA")period(string, optional): Historical period for trend metrics (default: "1y")interval(string, optional): Historical data interval (default: "1d")news_count(integer, optional): Number of recent news items to return (default: 5)
Returns:
symbol(string): Queried symbolname(string): Company/asset nameprice(float): Current pricechange(float): Price changechange_percent(float): Percentage changevolume(integer): Trading volumemarket_cap(integer): Market capitalizationcurrency(string): Currency codetimestamp(string): ISO format timestampfundamentals(object): Earnings, PE ratios, dividends, marginsnews(array): Recent news itemstrend(object): Moving averages, RSI, volatility, historical returnssuccess(boolean): Whether the query succeedederror(string): Error message if query failed
RSS Operations
The RSS system fetches and parses RSS and Atom feeds.
rss_fetch
Fetches and parses an RSS or Atom feed, returning structured items.
Parameters:
url(string, required): RSS feed URLlimit(integer, optional): Maximum number of items to return (default: 10)
Returns:
feed_title(string): Title of the feedfeed_link(string): Link to the feed's websiteitems(array): Feed items, each with:title(string): Item titlelink(string): Item URLpublished(string): Publication datesummary(string): Item summary/description
item_count(integer): Number of items returnedsuccess(boolean): Whether the fetch succeedederror(string): Error message if fetch 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_COMMANDSFirejail 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:
Python Version: 3.12
Memory Limit: Configurable memory ceiling (default: 256MB)
Execution Timeout: Configurable time limit (default: 30s, max: 120s)
AppArmor Profile: Restricts access to system resources
Firejail Sandbox: Process isolation
Capabilities: All capabilities dropped
Network: No network access
Available Libraries: Only standard library
Output Capturing: stdout/stderr redirected and sanitized
Resource Controls: CPU and memory limits enforced
File System Environment
The file system environment controls access to files within the sandbox:
Base Directory: All operations restricted to sandbox root
Path Validation: All paths normalized and checked for traversal attempts
Size Limits: Maximum file size enforced (default: 10MB)
Extension Control: Only allowed extensions permitted (default: txt, md, csv, json, py)
Permission Control: Appropriate read/write permissions enforced
Isolation: No access to host file system
Web Environment
The web environment provides controlled access to external resources:
Domain Control: Optional whitelisting of allowed domains
Timeout Control: Configurable timeouts for operations
Browser Control: Headless browser via Playwright for full rendering
Scraping Control: Simple scraping via requests/BeautifulSoup
Content Sanitization: All content parsed and sanitized
Network Isolation: Separate network namespace via container
Knowledge Base Environment
The knowledge base environment provides structured document storage and semantic search:
Hierarchical Organization: Documents organized in namespace/collection/name structure
Metadata Management: Rich metadata support with RDF-style triples
Semantic Search: Full-text search with sparse indexing and semantic reranking
Graph Relationships: Document references with relationship traversal
Path Validation: Strict path validation and normalization
Search Indices: Separate sparse and graph indices for optimal performance
Timeout Control: Configurable timeouts for operations (default: 30s, max: 120s)
Isolation: Knowledge base operations restricted to configured storage path
List Environment
The list environment provides organized collection management:
Org-mode Format: Lists stored as org-mode files for portability
Status Tracking: Items support multiple statuses (TODO, DONE, WAITING, CANCELLED, NEXT, SOMEDAY)
Tagging: Items and lists support tags for flexible organization
Archival: Deleted lists are archived for safety
Search: Cross-list search by text and tags
Isolation: List operations restricted to configured storage path
Market Environment
The market environment provides controlled access to financial data:
Data Source: Yahoo Finance for stocks and cryptocurrencies
Timeout Control: Configurable timeouts (default: 30s, max: 60s)
Data Types: Price quotes, fundamentals, news, and trend analysis
RSS Environment
The RSS environment provides feed fetching capabilities:
Feed Types: Supports both RSS and Atom feeds
Timeout Control: Configurable timeouts (default: 15s, max: 30s)
User Agent: Configurable user agent string
Item Limiting: Configurable maximum items per fetch
Architecture
The project follows a modular architecture:
Each manager follows consistent design patterns:
.from_env()class method for environment-based initializationAsync execution methods for non-blocking operations
Strong input validation and error handling
Security-first approach to all operations
Security Measures
Container-MCP implements multiple layers of security:
Container Isolation: Uses Podman/Docker for container isolation
AppArmor Profiles: Fine-grained access control for bash and Python execution
Firejail Sandboxing: Additional process isolation
Resource Limits: Memory, CPU, and execution time limits
Path Traversal Prevention: Validates and normalizes all file paths
Allowed Extension Restrictions: Controls what file types can be accessed
Network Restrictions: Controls what domains can be accessed
Least Privilege: Components run with minimal necessary permissions
Installation
Prerequisites
Linux system with Podman or Docker
Python 3.12+
Firejail (
apt install firejailordnf install firejail)AppArmor (
apt install apparmor apparmor-utilsordnf install apparmor apparmor-utils)
Quick Start
The quickest way to get started is to use the all-in-one script:
Step-by-Step Installation
You can also perform the installation steps individually:
Initialize the project:
./bin/01-init.shBuild the container:
./bin/02-build-container.shSet up the environment:
./bin/03-setup-environment.shRun the container:
./bin/04-run-container.shRun tests (optional):
./bin/05-run-tests.sh
Usage
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:
Server Configuration
Bash Manager Configuration
Python Manager Configuration
File Manager Configuration
Web Manager Configuration
Knowledge Base Manager Configuration
List Manager Configuration
Market Manager Configuration
RSS Manager Configuration
Development
Setting Up a Development Environment
Create a Python virtual environment:
python3.12 -m venv .venv source .venv/bin/activateInstall dependencies:
pip install -r requirements-dev.txtInstall the package in development mode:
pip install -e .
Running Tests
Development Server
To run the MCP server in development mode:
License
This project is licensed under the Apache License 2.0.
Author
Martin Bukowski