Daytona MCP解释器
一种模型上下文协议服务器,允许在Daytona工作区中执行Python代码,为执行和管理Python脚本提供安全且隔离的环境。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"daytona-interpreter": {
"args": [
"--directory",
"/Users/USER/dev/daytona-mcp-interpreter",
"run",
"src/daytona_mcp_interpreter/server.py"
],
"command": "/Users/USER/.local/bin/uv",
"env": {
"MCP_DAYTONA_API_KEY": "api_key",
"MCP_DAYTONA_SERVER_URL": "api_server_url",
"MCP_DAYTONA_TIMEOUT": "30.0",
"MCP_VERIFY_SSL": "false",
"PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
"PYTHONUNBUFFERED": "1"
}
}
}
}
该服务需要配置环境变量:MCP_DAYTONA_API_KEY、MCP_DAYTONA_API_URL、MCP_DAYTONA_TIMEOUT、MCP_VERIFY_SSL、PATH、PYTHONUNBUFFERED
可用工具 (1 个)
该服务在 MCP 协议中暴露的工具,AI 可按需调用
python_interpreter 1 个参数 需填 1 项
Execute Python code in a Daytona workspace
必填参数:code
服务介绍
Daytona MCP 解释器
一个提供在临时Daytona沙箱环境中执行Python代码能力的模型上下文协议服务器。

概述
Daytona MCP 解释器使像 Claude 这样的 AI 助手能够在安全、隔离的环境中执行 Python 代码和 shell 命令。它实现了模型上下文协议(MCP)标准,提供了以下工具:
- 在沙箱环境中执行 Python 代码
- 执行 shell 命令
- 文件管理(上传/下载)
- 克隆 Git 仓库
- 为正在运行的服务器生成网页预览
所有执行都在临时的 Daytona 工作空间中进行,使用后会自动清理。
安装
- 如果你还没有安装 uv,请先安装:
curl -LsSf https://astral.sh/uv/install.sh | sh
- 创建并激活虚拟环境。
如果你有现有的环境,请先停用并删除它:
deactivate
rm -rf .venv
创建并激活一个新的虚拟环境:
uv venv
source .venv/bin/activate
(在 Windows 上:.venv\Scripts\activate)
- 安装依赖项:
uv add "mcp[cli]" pydantic python-dotenv "daytona-sdk>=0.10.5"
注意:此项目需要 daytona-sdk 版本 0.10.5 或更高版本。早期版本的 FileSystem API 不兼容。
环境变量
配置这些环境变量以确保正常运行:
MCP_DAYTONA_API_KEY:Daytona 认证所需的 API 密钥MCP_DAYTONA_SERVER_URL:服务器 URL(默认值:https://app.daytona.io/api)MCP_DAYTONA_TIMEOUT:请求超时时间(秒)(默认值:180.0)MCP_DAYTONA_TARGET:目标区域(默认值:eu)MCP_VERIFY_SSL:启用 SSL 验证(默认值:false)
开发
直接运行服务器:
uv run src/daytona_mcp_interpreter/server.py
或者如果 uv 不在你的路径中:
/Users/USER/.local/bin/uv run ~LOCATION/daytona-mcp-interpreter/src/daytona_mcp_interpreter/server.py
使用 MCP 检查器测试服务器:
npx @modelcontextprotocol/inspector \
uv \
--directory . \
run \
src/daytona_mcp_interpreter/server.py
查看日志:
tail -f /tmp/daytona-interpreter.log
与 Claude 桌面集成
- 在 Claude 桌面(或其他支持 MCP 的客户端)中配置:
在 MacOS 上,编辑:~/Library/Application Support/Claude/claude_desktop_config.json
在 Windows 上,编辑:%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"daytona-interpreter": {
"command": "/Users/USER/.local/bin/uv",
"args": [
"--directory",
"/Users/USER/dev/daytona-mcp-interpreter",
"run",
"src/daytona_mcp_interpreter/server.py"
],
"env": {
"PYTHONUNBUFFERED": "1",
"MCP_DAYTONA_API_KEY": "api_key",
"MCP_DAYTONA_SERVER_URL": "api_server_url",
"MCP_DAYTONA_TIMEOUT": "30.0",
"MCP_VERIFY_SSL": "false",
"PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
}
}
}
}
- 重启 Claude 桌面
- Daytona Python 解释器工具将在 Claude 中可用
可用工具
Shell Exec
在 Daytona 工作空间中执行 shell 命令。
# Example: List files
ls -la
# Example: Install a package
pip install pandas
文件下载
从 Daytona 工作空间下载文件,智能处理大文件。
基本用法:
file_download(file_path="/path/to/file.txt")
高级用法:
# Set custom file size limit
file_download(file_path="/path/to/large_file.csv", max_size_mb=10.0)
# Download partial content for large files
file_download(file_path="/path/to/large_file.csv", download_option="download_partial", chunk_size_kb=200)
# Convert large file to text
file_download(file_path="/path/to/large_file.pdf", download_option="convert_to_text")
# Compress file before downloading
file_download(file_path="/path/to/large_file.bin", download_option="compress_file")
# Force download despite size
file_download(file_path="/path/to/large_file.zip", download_option="force_download")
文件上传
将文件上传到 Daytona 工作空间。支持文本和二进制文件。
基本用法:
# Upload a text file
file_upload(file_path="/workspace/example.txt", content="Hello, World!")
高级用法:
# Upload a text file with specific path
file_upload(
file_path="/workspace/data/config.json",
content='{"setting": "value", "enabled": true}'
)
# Upload a binary file using base64 encoding
import base64
with open("local_image.png", "rb") as f:
base64_content = base64.b64encode(f.read()).decode('utf-8')
file_upload(
file_path="/workspace/images/uploaded.png",
content=base64_content,
encoding="base64"
)
# Upload without overwriting existing files
file_upload(
file_path="/workspace/important.txt",
content="New content",
overwrite=False
)
Git 克隆
将 Git 仓库克隆到 Daytona 工作空间中进行分析和代码执行。
基本用法:
git_clone(repo_url="https://github.com/username/repository.git")
高级用法:
# Clone a specific branch
git_clone(
repo_url="https://github.com/username/repository.git",
branch="develop"
)
# Clone to a specific directory with full history
git_clone(
repo_url="https://github.com/username/repository.git",
target_path="my_project",
depth=0 # 0 means full history
)
# Clone with Git LFS support for repositories with large files
git_clone(
repo_url="https://github.com/username/large-files-repo.git",
lfs=True
)
网页预览
为在 Daytona 工作空间内运行的 Web 服务器生成预览 URL。
基本用法:
# Generate a preview link for a web server running on port 3000
web_preview(port=3000)
高级用法:
# Generate a preview link with a descriptive name
web_preview(
port=8080,
description="React Development Server"
)
# Generate a link without checking if server is running
web_preview(
port=5000,
check_server=False
)
示例:
# First run a simple web server using Python via the shell
shell_exec(command="python -m http.server 8000 &")
# Then generate a preview link for the server
web_preview(port=8000, description="Python HTTP Server")
