The MCP server is used to create a secure code sandbox environment, execute code in Docker containers, and provide code execution capabilities for AI applications.
For Chinese version, see 中文 README.
- Supports code execution in multiple programming languages (Python, PHP, Golang)
- Docker container-based isolated environment to ensure secure code execution
- Provides resource limitations (CPU timeout, memory limit, disk limit)
- Provides real-time interaction capabilities through SSE (Server-Sent Events)
- Easy-to-use tool interface for easy integration into AI applications
- Go 1.25.1 or higher
- Docker environment
Pull the required programming language Docker images:
make init-imagesCompile the project to the bin directory based on the target platform:
- Linux (amd64 architecture):
make build-linux- macOS (Apple Silicon chips, arm64 architecture):
make build-darwin- Windows (amd64 architecture):
make build-windowsStart the MCP server:
./bin/code-sandbox-mcp-serverThe server will start on port 4000, providing the following endpoints:
- SSE endpoint:
/sse - Message endpoint:
/message
The server registers a tool named execute_code_in_sandbox for executing code in a sandbox environment.
| Parameter | Type | Required | Description |
|---|---|---|---|
| language | string | Yes | Programming language |
| code | string | Yes | The code to be executed |
| version | string | No | Programming language version |
Call the tool to execute Python code:
{
"tool": "execute_code_in_sandbox",
"parameters": {
"language": "python",
"code": "print('Hello, World!')"
}
}cmd/code-sandbox-mcp/main.go: Server main entry pointsandbox/: Sandbox core functionality implementationsandbox/docker/: Docker sandbox implementationtempfile/: Temporary file management (provides temporary file writing functionality, such asWriteFilemethod)go.mod/go.sum: Go dependency managementMakefile: Build scripts
The project implements configuration management through sandbox/config.go, supporting:
- Loading YAML format configuration files (default paths include
./config.yamland./config/config.yaml) - Monitoring configuration file changes and automatic reloading
- Configuration items include server information, runtime resource limits (CPU timeout, memory, disk), network settings, language-specific configurations (suffix, image, entrypoint, etc.)
Clean up compiled files:
make cleanMain dependencies include:
- Docker SDK for Go: For interacting with Docker
- trpc-mcp-go: Provides MCP server framework (version v0.0.7)
- viper: Configuration management
- fsnotify: File system notifications (for configuration file monitoring)
- golang.org/x/sys: System-related operation support
- golang.org/x/net: Network-related function support
See go.mod and go.sum files for the complete list of dependencies.