The Localhost Cloud: Inside Coasts

How a Rust daemon uses Git worktrees and socket proxies to build the isolated sandboxes necessary for parallel AI coding agents.

7 min read • View on GitHub • More from coast-guard

A tangled mess of mechanical shipping cranes trying to drop containers on the exact same loading dock. This illustrates the port collision problem when multiple local branches run simultaneously.
When multiple AI agents check out different branches locally, they inevitably collide over shared infrastructure.

Worktrees create a git-linked copy of your code so multiple agents can work in isolation. The problem is that AGENTS NEED RUNTIMES.

Daniel Hyman, Co-founder at Coasts · DEV Community
Key Takeaways

The Localhost Traffic Jam

Autonomous coding agents are breaking local development. Tools like Claude Code and Cursor are designed to handle multiple tasks in parallel. To do this safely, they check out different Git branches into isolated directories using Git worktrees. This keeps the source code separate. However, the underlying runtime infrastructure remains completely shared.

When two agents attempt to boot a web application simultaneously, they crash into each other. They fight over port 8080. They corrupt shared local database states. They overwrite environment variables in the single running Docker Compose network.

Daniel Hyman, Co-founder at Coasts.

The Worktree as the Infrastructure Boundary

Coasts introduces a fundamental shift in the local development mental model. It reads the output of the native Git command and automatically provisions an entirely isolated environment for every branch. The project introduces the Coastfile as the blueprint for these parallel worlds.

By tying isolated Docker runtimes directly to Git worktrees, developers and agents can spin up five versions of a complex application simultaneously without conflicts.

FeatureGit WorktreesDocker ComposeCoasts
Primary RoleCode IsolationService OrchestrationFull Stack Isolation
Port ManagementManualManual (YAML)Automatic Dynamic/Canonical
Database StateSharedShared (usually)Isolated Logical Databases
Multi-Agent SafeNoNoYes

The Millisecond Port Swap

The most technically impressive feature of Coasts is its switching speed. Tearing down and rebuilding Docker networks every time a developer switches branches takes minutes. Coasts bypasses this entirely using socat.

The system maintains a Canonical Port (like 8080) bound to the host. When a user switches branches, Coasts instantly kills and respawns a lightweight socat process to route traffic to the specific container's internal IP. The containers themselves are long-running and never stop spinning.

Coasts achieves millisecond context switching by hot-swapping socat proxies instead of restarting heavy Docker containers.

The Rust Orchestration Engine

Under the hood, a long-running background process called coastd manages the complexity. Written in Rust, it leverages the tokio runtime for asynchronous operations and communicates with the CLI via Unix Domain Sockets.

To handle crash recovery gracefully, the daemon uses Rust's Drop trait. By utilizing an UpdateOperationGuard, Coasts ensures that if a build process is interrupted or fails, the state is automatically cleaned up and rolled back.

impl Drop for UpdateOperationGuard {
    fn drop(&mut self) {
        if let Some(state) = self.state.take() {
            // Automatically clean up orphaned containers
            // and reset proxy routes if the operation panics.
            cleanup_failed_coast_state(state);
        }
    }
}

Sandboxing the Agentic Era

To save resources while maintaining strict boundaries, Coasts distinguishes between instance services (the application code) and shared services (heavy databases like Postgres). It maps isolated logical databases within a single shared container.

Ultimately, the project embraces a Docker-in-Docker approach. It provides a sandbox within a sandbox. As AI coding agents become more autonomous, they require environments where they can execute arbitrary code, run test suites, and fail repeatedly without destroying the host machine. Coasts provides exactly that.

A pristine miniature clockwork factory operating inside a sealed glass bottle, surrounded by a messy workbench. This illustrates the absolute isolation of Docker-in-Docker environments.
Docker-in-Docker isolation ensures that autonomous agents can execute arbitrary code without polluting the host environment.