Skip to content

Commit 4c42291

Browse files
committed
feat: enhance code sandbox tools and update dependencies
- Introduce new tools for initializing environments, copying files, and executing commands in Docker containers. - Refactor existing tools to improve functionality and streamline code execution processes. - Update Go module dependencies to the latest versions, including Docker and OpenTelemetry packages. - Remove outdated tools related to running code and projects, consolidating functionality into new tools. - Improve error handling and logging across the code sandbox functionality.
1 parent 5510b9a commit 4c42291

File tree

16 files changed

+917
-1179
lines changed

16 files changed

+917
-1179
lines changed

README.md

Lines changed: 58 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
[![smithery badge](https://smithery.ai/badge/@Automata-Labs-team/code-sandbox-mcp)](https://smithery.ai/server/@Automata-Labs-team/code-sandbox-mcp)
33

44
A secure sandbox environment for executing code within Docker containers. This MCP server provides AI applications with a safe and isolated environment for running code while maintaining security through containerization.
5-
![Screenshot from 2025-01-26 02-37-42](https://github.com/user-attachments/assets/c3fcf202-24a2-488a-818f-ffab6f881849)
5+
66
## 🌟 Features
77

8-
- **Multi-Language Support**: Run Python, Go, and Node.js code in isolated Docker containers
9-
- **TypeScript Support**: Built-in support for TypeScript and JSX/TSX files
10-
- **Dependency Management**: Automatic handling of project dependencies (pip, go mod, npm)
11-
- **Flexible Execution**: Custom entrypoints for both single-file code and full projects
12-
- **Background Mode**: Run long-running services in the background
13-
- **Real-time Output**: Capture and stream container logs in real-time
8+
- **Flexible Container Management**: Create and manage isolated Docker containers for code execution
9+
- **Custom Environment Support**: Use any Docker image as your execution environment
10+
- **File Operations**: Easy file and directory transfer between host and containers
11+
- **Command Execution**: Run any shell commands within the containerized environment
12+
- **Real-time Logging**: Stream container logs and command output in real-time
13+
- **Auto-Updates**: Built-in update checking and automatic binary updates
14+
- **Multi-Platform**: Supports Linux, macOS, and Windows
1415

1516
## 🚀 Installation
1617

@@ -28,16 +29,6 @@ A secure sandbox environment for executing code within Docker containers. This M
2829
curl -fsSL https://raw.githubusercontent.com/Automata-Labs-team/code-sandbox-mcp/main/install.sh | bash
2930
```
3031

31-
Example output:
32-
```
33-
Downloading latest release...
34-
Installing to /home/user/.local/share/code-sandbox-mcp/code-sandbox-mcp...
35-
Adding to Claude Desktop configuration...
36-
Added code-sandbox-mcp to /home/user/.config/Claude/claude_desktop_config.json
37-
Installation complete!
38-
You can now use code-sandbox-mcp with Claude Desktop or other AI applications.
39-
```
40-
4132
#### Windows
4233
```powershell
4334
# Run in PowerShell
@@ -47,61 +38,76 @@ irm https://raw.githubusercontent.com/Automata-Labs-team/code-sandbox-mcp/main/i
4738
The installer will:
4839
1. Check for Docker installation
4940
2. Download the appropriate binary for your system
50-
3. Create Claude Desktop configuration
41+
3. Create necessary configuration files
5142

52-
### Manual Installation (Not necesary if automated installation is used)
43+
### Manual Installation
5344

5445
1. Download the latest release for your platform from the [releases page](https://github.com/Automata-Labs-team/code-sandbox-mcp/releases)
5546
2. Place the binary in a directory in your PATH
5647
3. Make it executable (Unix-like systems only):
5748
```bash
5849
chmod +x code-sandbox-mcp
5950
```
51+
6052
## 🛠️ Available Tools
6153

62-
#### `run_code`
63-
Executes code snippets in an isolated Docker container.
54+
#### `sandbox_initialize`
55+
Initialize a new compute environment for code execution.
56+
Creates a container based on the specified Docker image.
6457

6558
**Parameters:**
66-
- `code` (string, required): The code to run
67-
- `language` (enum, required): Programming language to use
68-
- Supported values: `python`, `go`, `nodejs`
69-
- Note: If your Python code requires external dependencies, it is recommended to use the `run_project` tool instead. Go and Node.js script dependencies are automatically installed.
59+
- `image` (string, optional): Docker image to use as the base environment
60+
- Default: 'python:3.12-slim-bookworm'
7061

7162
**Returns:**
72-
- Container execution output (stdout + stderr)
63+
- `container_id` that can be used with other tools to interact with this environment
7364

74-
**Features:**
75-
- Automatic dependency detection and installation
76-
- Python: Detects imports and installs via pip
77-
- Node.js: Detects require/import statements and installs via npm
78-
- Go: Detects imports and installs via go get
79-
- Automatic language-specific Docker image selection
80-
- TypeScript/JSX support with appropriate flags
81-
- Special handling for Go (code written to temporary file)
82-
- Real-time output streaming
65+
#### `copy_project`
66+
Copy a directory to the sandboxed filesystem.
8367

84-
#### `run_project`
85-
Executes a project directory in a containerized environment.
68+
**Parameters:**
69+
- `container_id` (string, required): ID of the container returned from the initialize call
70+
- `local_src_dir` (string, required): Path to a directory in the local file system
71+
- `dest_dir` (string, optional): Path to save the src directory in the sandbox environment
72+
73+
#### `write_file`
74+
Write a file to the sandboxed filesystem.
8675

8776
**Parameters:**
88-
- `project_dir` (string, required): Directory containing the project to run
89-
- `language` (enum, required): Programming language to use
90-
- Supported values: `python`, `go`, `nodejs`
91-
- `entrypointCmd` (string, required): Command to run the project
92-
- Examples:
93-
- Python: `python main.py`
94-
- Node.js: `node index.js`
95-
- Go: `go run main.go`
77+
- `container_id` (string, required): ID of the container returned from the initialize call
78+
- `file_name` (string, required): Name of the file to create
79+
- `file_contents` (string, required): Contents to write to the file
80+
- `dest_dir` (string, optional): Directory to create the file in (Default: ${WORKDIR})
9681

97-
**Returns:**
98-
- The resource URI of the container logs.
82+
#### `sandbox_exec`
83+
Execute commands in the sandboxed environment.
84+
85+
**Parameters:**
86+
- `container_id` (string, required): ID of the container returned from the initialize call
87+
- `commands` (array, required): List of command(s) to run in the sandboxed environment
88+
- Example: ["apt-get update", "pip install numpy", "python script.py"]
89+
90+
#### `copy_file`
91+
Copy a single file to the sandboxed filesystem.
92+
93+
**Parameters:**
94+
- `container_id` (string, required): ID of the container returned from the initialize call
95+
- `local_src_file` (string, required): Path to a file in the local file system
96+
- `dest_path` (string, optional): Path to save the file in the sandbox environment
97+
98+
#### Container Logs Resource
99+
A dynamic resource that provides access to container logs.
100+
101+
**Resource Path:** `containers://{id}/logs`
102+
**MIME Type:** `text/plain`
103+
**Description:** Returns all container logs from the specified container as a single text resource.
104+
105+
## 🔐 Security Features
106+
107+
- Isolated execution environment using Docker containers
108+
- Resource limitations through Docker container constraints
109+
- Separate stdout and stderr streams
99110

100-
**Features:**
101-
- Automatic dependency detection and installation
102-
- Volume mounting of project directory
103-
- Language-specific configuration handling
104-
- Real-time log streaming
105111

106112
## 🔧 Configuration
107113

@@ -155,57 +161,6 @@ The installer automatically creates the configuration file. If you need to manua
155161

156162
For other AI applications that support MCP servers, configure them to use the `code-sandbox-mcp` binary as their code execution backend.
157163

158-
## 🔧 Technical Details
159-
160-
### Supported Languages
161-
162-
| Language | File Extensions | Docker Image |
163-
|----------|----------------|--------------|
164-
| Python | .py | python:3.12-slim-bookworm |
165-
| Go | .go | golang:1.21-alpine |
166-
| Node.js | .js, .ts, .tsx, .jsx | node:23-slim |
167-
168-
### Dependency Management
169-
170-
The sandbox automatically detects and installs dependencies:
171-
172-
- **Python**:
173-
- Detects imports like `import requests`, `from PIL import Image`
174-
- Handles aliased imports (e.g., `PIL``pillow`)
175-
- Filters out standard library imports
176-
- Supports both direct imports and `__import__()` calls
177-
178-
- **Node.js**:
179-
- Detects `require()` statements and ES6 imports
180-
- Handles scoped packages (e.g., `@org/package`)
181-
- Supports dynamic imports (`import()`)
182-
- Filters out built-in Node.js modules
183-
184-
- **Go**:
185-
- Detects package imports in both single-line and grouped formats
186-
- Handles named and dot imports
187-
- Filters out standard library packages
188-
- Supports external dependencies via `go get`
189-
190-
For project execution, the following files are used:
191-
- **Python**: requirements.txt, pyproject.toml, setup.py
192-
- **Go**: go.mod
193-
- **Node.js**: package.json
194-
195-
### TypeScript Support
196-
197-
Node.js 23+ includes built-in TypeScript support:
198-
- `--experimental-strip-types`: Enabled by default for .ts files
199-
- `--experimental-transform-types`: Used for .tsx files
200-
201-
## 🔐 Security Features
202-
203-
- Isolated execution environment using Docker containers
204-
- Resource limitations through Docker container constraints
205-
- Separate stdout and stderr streams
206-
- Clean container cleanup after execution
207-
- Project files mounted read-only in containers
208-
209164
## 🛠️ Development
210165

211166
If you want to build the project locally or contribute to its development, see [DEVELOPMENT.md](DEVELOPMENT.md).

src/code-sandbox-mcp/go.mod

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@ module github.com/Automata-Labs-team/code-sandbox-mcp
22

33
go 1.24.0
44

5-
require github.com/mark3labs/mcp-go v0.8.3
5+
require (
6+
github.com/docker/docker v28.0.2+incompatible
7+
github.com/mark3labs/mcp-go v0.15.0
8+
)
69

710
require (
811
github.com/containerd/log v0.1.0 // indirect
912
github.com/moby/term v0.5.2 // indirect
1013
github.com/morikuni/aec v1.0.0 // indirect
11-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.34.0 // indirect
12-
go.opentelemetry.io/otel/sdk v1.34.0 // indirect
13-
golang.org/x/time v0.10.0 // indirect
14+
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
15+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0 // indirect
16+
golang.org/x/time v0.11.0 // indirect
1417
gotest.tools/v3 v3.5.2 // indirect
1518
)
1619

1720
require (
1821
github.com/Microsoft/go-winio v0.6.2 // indirect
1922
github.com/distribution/reference v0.6.0 // indirect
20-
github.com/docker/docker v27.5.1+incompatible
2123
github.com/docker/go-connections v0.5.0 // indirect
2224
github.com/docker/go-units v0.5.0 // indirect
2325
github.com/felixge/httpsnoop v1.0.4 // indirect
@@ -26,14 +28,13 @@ require (
2628
github.com/gogo/protobuf v1.3.2 // indirect
2729
github.com/google/uuid v1.6.0 // indirect
2830
github.com/moby/docker-image-spec v1.3.1 // indirect
29-
github.com/moby/moby v27.5.1+incompatible
3031
github.com/opencontainers/go-digest v1.0.0 // indirect
31-
github.com/opencontainers/image-spec v1.1.0 // indirect
32+
github.com/opencontainers/image-spec v1.1.1 // indirect
3233
github.com/pkg/errors v0.9.1 // indirect
3334
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
34-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect
35-
go.opentelemetry.io/otel v1.34.0 // indirect
36-
go.opentelemetry.io/otel/metric v1.34.0 // indirect
37-
go.opentelemetry.io/otel/trace v1.34.0 // indirect
38-
golang.org/x/sys v0.30.0 // indirect
35+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
36+
go.opentelemetry.io/otel v1.35.0 // indirect
37+
go.opentelemetry.io/otel/metric v1.35.0 // indirect
38+
go.opentelemetry.io/otel/trace v1.35.0 // indirect
39+
golang.org/x/sys v0.31.0 // indirect
3940
)

0 commit comments

Comments
 (0)