Implementation:23blocks OS Ai maestro Create Docker Agent
| Knowledge Sources | |
|---|---|
| Domains | Agent_Orchestration, Containers |
| Last Updated | 2026-10-26 10:00 GMT |
Overview
Concrete tool for creating agents inside Docker containers, provided by AI Maestro's `services/agents-docker-service.ts`.
Description
The createDockerAgent service function provisions an agent that runs in a Docker container instead of a local tmux session. It validates the create request (name against the safe-ids rules, image format, mounts), creates the registry entry, then shells out to the `docker` CLI (via `lib/container-utils.ts`) to run the container with the agent's working directory mounted and extra environment variables injected. The container runs the agent's program (claude/codex/grok/copilot) under tmux inside the container.
Usage
Import this service function (or hit its API route) when an agent must be isolated in a container — e.g. for untrusted workloads, dependency isolation, or reproducible environments.
Code Reference
Source Location
- Repository: ai-maestro
- File: services/agents-docker-service.ts (L1181-1400)
- Supporting: lib/container-utils.ts, lib/safe-ids.ts
Signature
export async function createDockerAgent(
body: DockerCreateRequest
): Promise<ServiceResult<Record<string, unknown>>>
interface DockerCreateRequest {
name: string // container + agent name (validated safe id)
image: string // Docker image, e.g. 'ai-maestro-agent:latest'
mounts?: string[] // bind mounts: '/host/path:/container/path'
extraEnv?: Record<string, string> // environment variables for the container
workingDirectory?: string
permissionMode?: string
program?: string
}
Import
import { createDockerAgent } from '@/services/agents-docker-service'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| body.name | string | Yes | Agent and container name (safe-id validated) |
| body.image | string | Yes | Docker image reference |
| body.mounts | string[] | No | Host:container bind mounts |
| body.extraEnv | Record<string,string> | No | Extra environment variables |
Outputs
| Name | Type | Description |
|---|---|---|
| returns | ServiceResult<Record<string, unknown>> | data carries agent ID and container creation status; error on validation or docker CLI failure |
Usage Examples
Create a containerized agent
import { createDockerAgent } from '@/services/agents-docker-service'
const result = await createDockerAgent({
name: 'sandbox-agent',
image: 'ai-maestro-agent:latest',
mounts: ['/home/user/projects/api:/workspace'],
extraEnv: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY },
permissionMode: 'fullAutonomy',
})
if (result.error) {
console.error('Container agent creation failed:', result.error)
} else {
console.log('Agent created:', result.data)
}