container-use

repository·main·Indexed 26 days ago

https://github.com/dagger/container-use

container-use provides isolated, containerized development environments for coding agents. It enables multiple agents to work in parallel on different git branches using Dagger containers, with operational history stored as Git notes. It supports MCP-compatible agents including Claude Code, Goose, Cursor, OpenAI Codex, and Amazon Q Developer.

Tokens
17.9K
Snippets
68
Records
118
Agent score
85%

What's inside container-use

  1. Overview of Container Use

    main

    Container Use provides sandboxed development environments for coding agents. It leverages Dagger for containerized workflows and Git worktrees for branching.

    Key features include:

    • Sandboxed Environments: Each agent operates in a fresh container within its own Git branch, allowing multiple agents to run in parallel without conflicts.
    • Real-time Visibility: Provides complete command history and logs of agent actions.
    • Direct Intervention: Allows users to drop into an agent's terminal to inspect state or take manual control.
    • Environment Control: Supports standard Git workflows; users can review an agent's work by running git checkout <branch_name>.
  2. Understand the concept of Environments

    main

    An environment is an isolated, containerized development workspace that combines Docker containers with Git branches. It provides agents with safe, persistent workspaces where all changes are automatically tracked and versioned.

    Each environment consists of:

    • Git Branch: A dedicated branch tracking all changes and history.
    • Container: A Dagger container containing your code and dependencies.
    • History: Versioned snapshots of container state changes appended to the branch as Git notes.
    • Configuration: Base image, setup commands, secrets, and instructions that can be checked into the source repository.
  3. Setup container-use with Claude Code

    main

    To use container-use with Claude Code, add it as an MCP server using the stdio transport. You can also optionally add agent rules to your CLAUDE.md to improve agent behavior.

    Note: The container-use command can be shortened to cu.

    # Add Container Use MCP server
    cd /path/to/repository
    claude mcp add container-use -- container-use stdio
    
    # Add agent rules (optional)
    curl https://raw.githubusercontent.com/dagger/container-use/main/rules/agent.md >> CLAUDE.md
  4. Install Container Use

    main

    Before installing, ensure you have Docker and Git installed. You can install Container Use using Homebrew (macOS), a shell script (all platforms), or by building from source.

    # Homebrew (macOS)
    brew install dagger/tap/container-use
    
    # Shell Script (All Platforms)
    curl -fsSL https://raw.githubusercontent.com/dagger/container-use/main/install.sh | bash
    
    # Build from Source
    git clone https://github.com/dagger/container-use.git
    cd container-use
    go build -o container-use ./cmd/container-use
    sudo mv container-use /usr/local/bin/
    
    # Verify installation
    container-use version
  5. Integrate Container Use with OpenCode

    main

    Configure the Container Use MCP server in an opencode.json file and optionally add an AGENTS.md file for best results.

    # Configure opencode.json
    {
      "$schema": "http://opencode.ai/config.json",
      "mcp": {
        "container-use": {
          "type": "local",
          "command": ["container-use", "stdio"],
          "enabled": true
        }
      }
    }
    # Add AGENTS.md (Optional)
    curl https://raw.githubusercontent.com/dagger/container-use/main/rules/agent.md >> AGENTS.md
  6. Integrate Container Use with Sourcegraph Amp

    main

    Add the container-use MCP server configuration to ~/.config/amp/settings.json and optionally add agent rules to your project root.

    # Add to ~/.config/amp/settings.json
    {
        "amp.mcpServers": {
            "container-use": {
                "command": "container-use",
                "args": ["stdio"]
            }
        },
        "amp.permissions": [
          {"tool": "mcp__container-use__*", "action": "allow"}
        ],
        "amp.dangerouslyAllowAll": false,
        "amp.updates.autoUpdate.enabled": true
    }
    # Add Agent Rules
    curl https://raw.githubusercontent.com/dagger/container-use/main/rules/agent.md >> AGENT.md
  7. Integrate Container Use with VSCode / GitHub Copilot

    main

    Configure the MCP server in your VSCode settings and optionally add Copilot instructions to your project.

    # Update VSCode settings
    "mcp": {
      "servers": {
        "container-use": {
          "type": "stdio",
          "command": "container-use",
          "args": ["stdio"]
        }
      }
    }
    # Add Copilot Instructions (Optional)
    curl --create-dirs -o .github/copilot-instructions.md https://raw.githubusercontent.com/dagger/container-use/main/rules/agent.md
  8. Manage and review Container Use environments

    main
    After an agent performs work in an isolated environment, you can use the following commands to inspect, explore, and integrate the changes into your local repository. Replace {id} with your actual environment ID (e.g., fancy-mallard).
  9. View and import agent environment changes

    main

    Agents may modify their environment during work (e.g., installing a new tool). These changes are ephemeral to that specific environment unless you view them or import them into your defaults.

    • Use container-use config show <env> to inspect an agent's modified environment.
    • Use container-use config import <env> to adopt those changes as your new project defaults.
    # View your default configuration
    container-use config show
    
    # View an agent's modified configuration (e.g., environment named 'fancy-mallard')
    container-use config show fancy-mallard
    
    # Output configuration as JSON
    container-use config show --json
    
    # Import agent changes as new defaults
    container-use config import fancy-mallard
  10. Integrate Container Use with Charm Crush

    main

    Configure the Container Use MCP server in a valid location (e.g., ./.crush.json) and optionally add agent rules to your project root.

    # Add to ./.crush.json
    {
      "$schema": "https://charm.land/crush.json",
      "mcp": {
        "container-use": {
          "type": "stdio",
          "command": "container-use",
          "args": ["stdio"],
          "env": {}
        }
      },
      "permissions": {
        "allowed_tools": [
          "mcp_container-use_environment_add_service",
          "mcp_container-use_environment_checkpoint",
          "mcp_container-use_environment_config",
          "mcp_container-use_environment_create",
          "mcp_container-use_environment_file_delete",
          "mcp_container-use_environment_file_edit",
          "mcp_container-use_environment_file_list",
          "mcp_container-use_environment_file_read",
          "mcp_container-use_environment_file_write",
          "mcp_container-use_environment_open",
          "mcp_container-use_environment_run_cmd",
          "mcp_container-use_environment_update_metadata"
        ]
      }
    }
    # Add Agent Rules
    curl https://raw.githubusercontent.com/dagger/container-use/main/rules/agent.md >> CRUSH.md
  11. Use container-use with MCP-compatible agents

    main
    Container Use works with any MCP-compatible agent (such as Cursor, Goose, or VSCode). The core requirement is to add container-use stdio as an MCP server. Once configured, you can prompt your agent to perform tasks (e.g., "Create a hello world app in python using flask"), and the agent will execute the work in an isolated container environment.
  12. Integrate Container Use with Goose

    main

    You can integrate Container Use with Goose using a configuration file, interactive setup, or the Goose Desktop URL.

    # Method 1: Add to ~/.config/goose/config.yaml
    extensions:
      container-use:
        name: container-use
        type: stdio
        enabled: true
        cmd: container-use
        args:
          - stdio
        envs: {}
    # Method 2: Interactive Setup
    goose configure
    # Then add a command line extension with 'container-use stdio' as the command

    Method 3: Goose Desktop

    Paste this URL into your browser:

    goose://extension?cmd=container-use&arg=stdio&id=container-use&name=container%20use&description=use%20containers%20with%20dagger%20and%20git%20for%20isolated%20environments