Posted on

Running multiple AI coding agents on the same codebase is a recipe for chaos. When one agent is refactoring your API while another is adding features, they step on each other's toes. Git stash and worktrees help with version control, but they don't stop agents from installing conflicting dependencies or leaving processes running on your machine.

hooded

So you're telling me I can't just run 5 Claude instances and hope for the best?

Well, you could, but you'll spend more time cleaning up messes than getting work done.

What Container Isolation Solves

Container Use gives each agent its own isolated environment by combining two things:

  1. Containers (via Dagger) - Filesystem isolation, terminal access, and service tunneling
  2. Git worktrees - Parallel git branches that don't interfere with each other

When you start an agent task, Container Use spins up a new environment with a random name. The container has its own filesystem, so dependencies installed by one agent won't conflict with another. The git worktree gives the agent its own branch to work on.

How It Works

Here's what's happening under the hood:

Loading diagram...

Each agent gets its own container and worktree, but they all share the same underlying git repository. This means you can:

  • Run container-use list to see all active environments
  • Run container-use watch to monitor progress
  • Run container-use log <env> to check what an agent is doing
  • Run container-use diff <env> to see what changed
  • Run container-use terminal <env> to drop into an interactive shell

Real Usage Examples

Testing new dependencies: Want to try Redis but don't want to mess up your main environment? Container Use creates an isolated branch and container. If it doesn't work out, just exit. No cleanup needed.

Risky refactors: Restructuring a codebase is scary. With Container Use, you can make sweeping changes in isolation, test thoroughly, and either merge or delete the branch. Your main codebase stays untouched.

Parallel experiments: Want to test REST vs GraphQL approaches? Spin up two agents in separate containers. One works on REST, the other on GraphQL. Compare results and merge the winner.

Learning new tech: Try a new framework in a pre-configured container without installing anything on your host system. No version conflicts, no "why is this breaking my other projects?"

hooded

So I can finally try that new JavaScript framework without breaking my entire setup? Nice.

Zed Integration

Zed recently added Container Use support through MCP (Model Context Protocol). The setup is straightforward:

  1. Install the Container Use extension
  2. Create two agent profiles:
    • Foreground: All built-in Zed tools active for interactive editing
    • Background: Only Container Use tools active for agent tasks

Switch to the background profile to kick off parallel experiments, then switch back to foreground for your own work. Zed notifies you when background tasks finish.

Security Benefits

Running AI-generated code in containers gives you:

  • Filesystem isolation: Agents can't access files outside their container
  • Network restrictions: Containers can have limited network access
  • Resource limits: Prevent runaway CPU/memory usage
  • Easy cleanup: Destroy the container, no traces left
  • Audit trail: All operations are logged

It's not perfect (containers share the host kernel), but it's way better than running untrusted code directly on your dev machine.

When This Makes Sense

Container Use is worth it when:

  • You're running multiple agents in parallel on the same codebase
  • You need to experiment without risking your main environment
  • You want clean, reproducible environments per task
  • You're in a team where agents might conflict

It's especially useful in monorepos where multiple projects share dependencies.

References

Table of Contents