容器沙箱 MCP 服务器

通过 MCP 协议提供安全的远程容器沙箱环境,支持在隔离环境中运行任意代码、执行 Shell 命令以及管理文件。

  • by cloudflare
  • TypeScript
  • 混合部署
  • 4429 星标
  • 更新于
在 GitHub 查看 cloudflare/mcp-server-cloudflare

使用说明

Cloudflare Container Sandbox MCP Server

This is a Model Context Protocol (MCP) server that supports remote MCP connections, with Cloudflare OAuth built-in.

It integrates tools for running a sandbox container with your MCP client. With this server you can allow your LLM to run arbitrary code, such as Node or Python, in a secure, sandboxed environment.

The /mcp URL uses a stateless SDK v2 handler that creates a fresh server for every request. The retired /sse URL returns 410 Gone pointing at /mcp. UserContainer and ContainerManager remain application Durable Objects for per-user container lifecycle and capacity management; there is no MCP protocol session or protocol Durable Object.

Each user's sandbox is a Container controlled by their UserContainer Durable Object through the native ctx.container API, with the durable_object scheduling policy. Every tool runs as a process with ctx.container.exec(); the container itself runs no server.

Sandboxes start from a snapshot of the Cloudflare-managed cloudflare/debian-trixie image with Python, pip, git, build tools and pnpm installed. One UserContainer instance, __sandbox-template__, builds that snapshot the first time a sandbox starts and keeps the handle (server/sandboxTemplate.ts). Every restore refreshes the snapshot's 30-day lifetime; if a restore fails, for example because the snapshot expired, the template is rebuilt.

Tools

Category Tool Description
Container Lifecycle container_initialize (Re)start a container. Containers are intended to be ephemeral and don't save any state. Containers are only guaranteed to last ~10m.
container_ping Ping a container for connectivity
Filesystem container_file_write Write to a file
container_files_list List all files in the work directory
container_file_read Read the contents of a single file or directory
container_file_delete Delete a single file or directory
Execution container_exec Run a command in the shell

This MCP server is still a work in progress, and we plan to add more tools in the future.

Prompt Examples

  • Create a visualization using matplotlib. Run it in the container that you can start
  • Clone and explore this github repo: [repo link]. Setup and run the tests in your development environment
  • Analyze this data using Python

Connect to the MCP server

Connect your MCP client directly to https://containers.mcp.cloudflare.com/mcp. If prompted, complete the Cloudflare OAuth flow in your browser. The tools become available after authorization.

Interested in contributing, and running this server locally? See CONTRIBUTING.md to get started.