Containerized Environments
Relevant source files
The following files were used as context for generating this wiki page:
The Containerized Environments feature in the Zed editor is implemented via the Model Context Protocol (MCP) server integration for "Container Use". This system enables AI coding agents to operate within isolated, containerized environments, providing a secure and consistent workspace for code execution and manipulation. The integration is facilitated by a Rust-based extension that bridges the Zed editor with the cu (Container Use) binary.
Sources: README.md:1-5, extension.toml:1-4
Architecture and Integration
The extension acts as a lifecycle manager for the Container Use MCP server. It handles binary discovery, configuration loading, and process execution. The core logic is encapsulated in the ContainerUseMcpExtension struct, which implements the zed::Extension trait to interact with the Zed Extension API.
Extension Components
| Component | Description |
|---|---|
cu Binary | The external command-line tool that provides the actual containerized environment capabilities. |
ContainerUseMcpExtension | The main Rust struct managing the MCP server lifecycle. |
ContextServerConfiguration | Object containing installation instructions and default settings provided to Zed. |
ContainerUseMcpSettings | Deserialized configuration object for user-defined paths. |
Sources: src/container_use_mcp.rs:16-18, src/container_use_mcp.rs:80-95, extension.toml:13-14
Process Discovery Flow
The extension employs a hierarchical search strategy to locate the cu binary required to launch the containerized environment.
The diagram shows how the extension prioritizes cached or configured paths before falling back to system-wide binary discovery using the which command.
Sources: src/container_use_mcp.rs:24-52, extension.toml:9-11
Configuration and Setup
Containerized environments can be customized through Zed's global settings or local project rules.
Settings Schema
The extension allows users to specify a custom binary path if cu is not available in the standard system PATH. This is managed through the settings.json file in Zed.
#[derive(Debug, Deserialize, JsonSchema)]
struct ContainerUseMcpSettings {
/// Path to the cu binary (optional - will download if not provided)
cu_path: Option<String>,
}
Sources: src/container_use_mcp.rs:11-15
Agent Rules
To enforce the use of containerized environments by AI agents, a specific rules file (.rules) must be present in the project root. This file directs the agent to utilize the cu tool for its operations.
| Requirement | Value / Command |
|---|---|
| Rule File | .rules |
| Source URL | https://raw.githubusercontent.com/dagger/container-use/main/rules/agent.md |
| Setup Command | curl -o .rules [URL] |
Sources: configuration/installation_instructions.md:1-3, README.md:27-33
Technical Implementation Details
The extension is compiled as a dynamic library (cdylib) and uses the zed_extension_api (version 0.5.0).
Initialization Sequence
When Zed initializes the extension, the following sequence occurs to establish the MCP connection:
The sequence illustrates the communication between the Zed editor and the extension to resolve the command necessary to start the containerized environment server.
Sources: src/container_use_mcp.rs:60-78, Cargo.toml:7-13
MCP Server Execution
The containerized environment server is started with specific arguments to facilitate communication over standard input/output.
- Command: Path to
cubinary. - Arguments:
["stdio"]. - Environment: Inherited from the editor context (empty vector passed by default).
Sources: src/container_use_mcp.rs:74-78
Summary
The "Containerized Environments" system provides a robust integration between Zed and Dagger's Container Use tool. By managing binary discovery and providing a standardized MCP interface, the extension ensures that coding agents can execute tasks within controlled, reproducible environments. Key configuration is handled via .rules files and Zed's internal settings, allowing for flexible deployment across different development setups.