Skip to content

The Deska blog

One Container per Agent: Setup Guide

Learn how to implement a one container per agent setup to isolate AI coding environments, improve security, and manage dependencies effectively.

11 min read

The modern development workflow is increasingly reliant on autonomous entities that write, test, and refactor code. Implementing a one container per agent setup ensures that these AI models operate within a predictable, sandbox environment that prevents dependency conflicts and protects the host system. By isolating each agent into its own containerized workspace, developers can grant broad permissions for file manipulation and command execution without risking the integrity of their primary operating environment.

The Architecture of Isolated Agent Workflows

When running multiple AI agents simultaneously, a flat architecture often leads to "environment drift." This happens when one agent installs a specific version of a library that breaks the requirements of another agent. A containerized approach treats each agent as a disposable, reproducible unit of compute.

This setup typically involves a container engine, such as Docker or Podman, and a management layer that orchestrates the lifecycle of these containers. The primary goal is to map a specific project subdirectory to a container volume, allowing the agent to perform its tasks within a restricted scope.

Security and Resource Allocation

Security is the most compelling reason to adopt this model. AI agents, particularly those with autonomous capabilities, might generate and execute shell scripts or modify configuration files. By restricting each agent to its own container, you create a security boundary. You can limit the CPU and memory available to an agent, ensuring that a runaway loop or a heavy compilation task does not freeze your entire machine.

Implementing the Container Per Agent Model

To start, you must define a base image that includes the necessary runtimes for your stack, such as Node.js, Python, or Go. Each agent instance will then be launched from this image with specific environment variables and volume mounts.

  1. Define a Dockerfile that includes the CLI tools the agent requires.
  2. Create a script to spin up a new container whenever a new agent thread begins.
  3. Use volume mounting to sync the specific code folder with the container /workspace directory.
  4. Set up a network bridge if the agent needs to access local databases or API services.

Handling State and Persistence

Containers are ephemeral by nature. If you stop a container, any global packages or system-level changes are lost unless they were committed to an image or stored in a mounted volume. For agent workflows, it is usually best to keep the code in a persistent volume but allow the system environment to reset. This ensures that every time an agent starts, it begins from a "known good" state, reducing the likelihood of hallucinations caused by leftover artifacts from previous sessions.

Integrating Deska into the Workflow

While manual container management works for background scripts, interactive development requires a more visual approach. Deska provides a local-first environment where you can manage these agents side by side. Instead of switching between multiple terminal tabs to monitor different containers, you can use the infinite canvas to organize your work.

Running Agents Side by Side

In Deska, you can open multiple coding-agents as individual panels. Because Deska is a desktop app for Mac, Windows, and Linux, it interacts directly with your local file system and container engine. You can place a panel for Claude Code next to a panel for OpenCode, each potentially targeting a different containerized environment or project folder.

Using Terminals and Code Editors

The terminals in Deska allow you to attach directly to your running agent containers. Since you can place these terminals anywhere on the canvas, you can watch the logs of an agent in real-time while using the built-in Monaco code editor to review the changes the agent is making. This visibility is crucial for debugging the "one container per agent" architecture, as it allows you to verify exactly what is happening inside the isolated shell.

Comparing Isolation Methods

There are several ways to achieve agent isolation, and the best choice depends on your specific needs for speed and security.

MethodIsolation LevelPerformanceSetup Complexity
Virtual EnvironmentsLowHighMinimal
Containers (Docker)MediumMediumModerate
Virtual MachinesHighLowHigh
Remote Dev EnvironmentsHighVariableHigh

While virtual environments are fast, they do not prevent an agent from accessing files outside the project folder. Containers offer the best balance for local development, providing a strong file system boundary without the heavy overhead of a full virtual machine.

Managing Multiple Agent Sessions

As you scale your usage of AI, managing the sheer volume of information becomes a challenge. Deska helps solve this through its canvas interface. You can zoom out to see the entire landscape of your active containers and agents, then zoom in on a specific task when you need to focus.

If you are away from your workstation, the Deska mobile app allows you to monitor these sessions. It uses a secure relay to connect your devices directly without exposing any ports to the internet. This is particularly useful for long-running agent tasks where you need to check if a containerized build has finished.

FAQ

How to limit agent access to specific files?

The most effective way is through volume mounting in your container configuration. Only mount the specific subdirectory the agent needs to modify. In your docker run command, use the -v flag to map only the target folder to the container workspace.

What is the overhead of running many containers?

Modern container engines are efficient. Running five to ten containers simultaneously on a standard development machine typically consumes minimal idle CPU. The primary constraint is usually RAM, which can be managed by setting memory limits on each container instance.

Can I use AI agents without containers?

Yes, you can run agents directly on your host OS. However, this is generally discouraged for autonomous agents that have permission to run commands, as it exposes your entire home directory and system configurations to potential errors or unintended deletions.

Getting Started with Deska

Setting up a robust agent environment is easier when you have the right tools to visualize the process. You can download the Deska desktop app for free to begin building your custom workspace. By combining a "one container per agent" strategy with a flexible, local-first canvas, you create a development environment that is both powerful and secure.