Agent Rule Integration
Relevant source files
The following files were used as context for generating this wiki page:
Agent Rule Integration is a critical component of the Container Use MCP extension for Zed, designed to govern how AI coding agents interact with containerized environments. By implementing specific instruction sets, the system ensures that agents leverage the cu (Container Use) binary to execute tasks within isolated containers rather than the host system, maintaining environment consistency and security.
The integration relies on a combination of project-level configuration files and the Model Context Protocol (MCP) to bridge the gap between the Zed editor's agent capabilities and the Dagger-powered containerized backend.
Sources: README.md:1-5, extension.toml:1-4
Architecture and Rule Enforcement
The system architecture facilitates a connection between the Zed extension and the cu binary via the Model Context Protocol. Rule enforcement is achieved by providing specific behavioral instructions to the agent through a .rules file located in the project root.
The .rules File
The primary mechanism for guiding agent behavior is the project-level .rules file. This file contains Markdown-formatted instructions that the agent parses to understand its operational boundaries.
- Location: The file must be saved as
.rulesin the project root. - Content: It specifically directs agents to use containerized environments for execution.
- Source: The recommended ruleset is fetched from the Dagger
container-userepository.
Sources: configuration/installation_instructions.md:1-3, README.md:31-35
Binary Execution Flow
The extension handles the discovery and execution of the cu binary, which provides the underlying containerized environment defined by the rules.
This diagram illustrates how the presence of the rules file influences the agent's path toward containerized execution.
Sources: src/container_use_mcp.rs:40-75, README.md:31-35
Implementation Details
The integration is implemented in Rust using the zed_extension_api. The extension manages the lifecycle of the MCP server and ensures that the agent has the necessary context to follow defined rules.
Configuration Management
The extension reads settings from Zed's settings.json to locate the cu binary, which is essential for the rules to be actionable.
| Field | Type | Description |
|---|---|---|
cu_path | Option<String> | Custom path to the cu binary. If not provided, the system searches the PATH. |
Sources: src/container_use_mcp.rs:11-14, README.md:16-27
Logic Flow for Server Command
The context_server_command function determines how the MCP server is launched, which is the communication channel through which rules and tools are exposed to the agent.
The sequence above shows the binary resolution logic required to support rule-based containerization.
Sources: src/container_use_mcp.rs:56-85, extension.toml:11-14
Installation and Setup
To activate Agent Rule Integration, users must perform a manual step of downloading the rule definition.
- Binary Availability: Ensure
cuis installed and accessible in the systemPATHor configured viacu_path. - Rule Deployment: Execute the following command in the project root:
curl -o .rules https://raw.githubusercontent.com/dagger/container-use/main/rules/agent.md
Sources: README.md:8-14, README.md:31-35, configuration/installation_instructions.md:1-3
Summary
Agent Rule Integration ensures that coding agents within Zed operate within the safety and reproducibility of containers. By utilizing a .rules file and the cu MCP server, the extension provides a structured way for agents to transition from host-based execution to containerized workflows.
Sources: README.md:1-5, extension.toml:3-4