# ken1ma/ko-agent-sandbox architecture

> Architecture diagram of the GitHub repository ken1ma/ko-agent-sandbox, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ken1ma/ko-agent-sandbox
- Repository: https://github.com/ken1ma/ko-agent-sandbox

## Overview

Ko Agent Sandbox launches AI coding agents in rootless, short-lived containers, mounting a selected workspace and persistent agent configuration while constraining filesystem and network access. The principal workflow is user command → launcher configuration and workspace checks → sandbox execution → policy-enforced egress proxy → permitted Internet destinations. Separate branches cover protected Git metadata, macOS run-on-host commands, image setup, and optional clipboard/audio relays. The map follows README statements and shown source references; unsampled implementation details and their internal connections are omitted where evidence is unavailable.

Main entry points: [`src/main/scala/AgentSandboxLauncher.scala`](https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/AgentSandboxLauncher.scala) (Launcher), [`container/ko-agent-egress-proxy/app/src/main/scala/AgentEgressProxy.scala`](https://github.com/ken1ma/ko-agent-sandbox/blob/main/container/ko-agent-egress-proxy/app/src/main/scala/AgentEgressProxy.scala) (Egress proxy), [`src/main/scala/RunOnHostSandbox.scala`](https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/RunOnHostSandbox.scala) (Run-on-host supervisor), [`fuse/ko-agent-fs/src/fs.rs`](https://github.com/ken1ma/ko-agent-sandbox/blob/main/fuse/ko-agent-fs/src/fs.rs) (Filesystem guard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_launch["Launch and workspace"]
  node_launcher["Launcher"]
  node_cli["Command options<br/>[CommandLine.scala]"]
  node_workspace["Workspace mounts"]
  node_state["Launcher state"]
  node_image["Image lifecycle<br/>[ImageBuilds.scala]"]
end

subgraph group_sandbox["Sandbox enforcement"]
  node_container["Agent container"]
  node_agent["Coding agent"]
  node_fs["Filesystem guard<br/>[fs.rs]"]
  node_policy["Git policy<br/>[policy.rs]"]
  node_file_rules["File protections<br/>[FileRules.scala]"]
end

subgraph group_egress["Network egress"]
  node_proxy["Egress proxy"]
  node_rules["Egress rules"]
  node_http["HTTP handling<br/>[HTTPHelper.scala]"]
  node_audit["Proxy audit log<br/>[LogHelper.scala]"]
end

subgraph group_host["Host integrations"]
  node_runhost["Run-on-host supervisor"]
  node_prereqs["Host prerequisites"]
  node_session["Host command sessions"]
  node_clipboard["Clipboard relay"]
  node_microphone["Microphone relay"]
end

node_user(("User"))
node_internet(("Internet destinations"))

node_user -->|"starts"| node_launcher
node_launcher -->|"parses options"| node_cli
node_launcher -->|"selects workspace"| node_workspace
node_launcher -->|"uses state"| node_state
node_launcher -->|"builds images"| node_image
node_launcher -->|"starts container"| node_container
node_container -->|"runs"| node_agent
node_container -.->|"guards filesystem"| node_fs
node_fs -->|"checks mutations"| node_policy
node_launcher -->|"configures protections"| node_file_rules
node_agent -->|"sends egress"| node_proxy
node_launcher -->|"starts proxy"| node_proxy
node_proxy -->|"resolves rules"| node_rules
node_proxy -->|"handles requests"| node_http
node_proxy -->|"records events"| node_audit
node_proxy -->|"allows destinations"| node_internet
node_launcher -->|"supervises host commands"| node_runhost
node_runhost -->|"checks prerequisites"| node_prereqs
node_runhost -->|"manages sessions"| node_session
node_agent -.->|"uses relay"| node_clipboard
node_agent -.->|"uses relay"| node_microphone

click node_launcher "https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/AgentSandboxLauncher.scala"
click node_cli "https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/CommandLine.scala"
click node_workspace "https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/SandboxWorkspace.scala"
click node_state "https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/LauncherState.scala"
click node_image "https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/ImageBuilds.scala"
click node_fs "https://github.com/ken1ma/ko-agent-sandbox/blob/main/fuse/ko-agent-fs/src/fs.rs"
click node_policy "https://github.com/ken1ma/ko-agent-sandbox/blob/main/fuse/ko-agent-fs/src/policy.rs"
click node_file_rules "https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/FileRules.scala"
click node_proxy "https://github.com/ken1ma/ko-agent-sandbox/blob/main/container/ko-agent-egress-proxy/app/src/main/scala/AgentEgressProxy.scala"
click node_rules "https://github.com/ken1ma/ko-agent-sandbox/blob/main/container/ko-agent-egress-proxy/app/src/main/scala/RulesetHelper.scala"
click node_http "https://github.com/ken1ma/ko-agent-sandbox/blob/main/container/ko-agent-egress-proxy/app/src/main/scala/HTTPHelper.scala"
click node_audit "https://github.com/ken1ma/ko-agent-sandbox/blob/main/container/ko-agent-egress-proxy/app/src/main/scala/LogHelper.scala"
click node_runhost "https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/RunOnHostSandbox.scala"
click node_prereqs "https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/RunOnHostPrereqs.scala"
click node_session "https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/RunOnHostSession.scala"
click node_clipboard "https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/ClipboardRelay.scala"
click node_microphone "https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/MicrophoneRelay.scala"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_launcher,node_cli,node_workspace,node_state,node_image,node_user toneBlue
class node_container,node_agent,node_fs,node_policy,node_file_rules toneAmber
class node_proxy,node_rules,node_http,node_audit toneMint
class node_runhost,node_prereqs,node_session,node_clipboard,node_microphone toneRose
class node_internet toneIndigo
```

## Components

### Launch and workspace

- [Launcher](https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/AgentSandboxLauncher.scala): `src/main/scala/AgentSandboxLauncher.scala`
- [Command options](https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/CommandLine.scala): `src/main/scala/CommandLine.scala`
- [Workspace mounts](https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/SandboxWorkspace.scala): `src/main/scala/SandboxWorkspace.scala`
- [Launcher state](https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/LauncherState.scala): `src/main/scala/LauncherState.scala`
- [Image lifecycle](https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/ImageBuilds.scala): `src/main/scala/ImageBuilds.scala`

### Sandbox enforcement

- **Agent container**
- **Coding agent**
- [Filesystem guard](https://github.com/ken1ma/ko-agent-sandbox/blob/main/fuse/ko-agent-fs/src/fs.rs): `fuse/ko-agent-fs/src/fs.rs`
- [Git policy](https://github.com/ken1ma/ko-agent-sandbox/blob/main/fuse/ko-agent-fs/src/policy.rs): `fuse/ko-agent-fs/src/policy.rs`
- [File protections](https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/FileRules.scala): `src/main/scala/FileRules.scala`

### Network egress

- [Egress proxy](https://github.com/ken1ma/ko-agent-sandbox/blob/main/container/ko-agent-egress-proxy/app/src/main/scala/AgentEgressProxy.scala): `container/ko-agent-egress-proxy/app/src/main/scala/AgentEgressProxy.scala`
- [Egress rules](https://github.com/ken1ma/ko-agent-sandbox/blob/main/container/ko-agent-egress-proxy/app/src/main/scala/RulesetHelper.scala): `container/ko-agent-egress-proxy/app/src/main/scala/RulesetHelper.scala`
- [HTTP handling](https://github.com/ken1ma/ko-agent-sandbox/blob/main/container/ko-agent-egress-proxy/app/src/main/scala/HTTPHelper.scala): `container/ko-agent-egress-proxy/app/src/main/scala/HTTPHelper.scala`
- [Proxy audit log](https://github.com/ken1ma/ko-agent-sandbox/blob/main/container/ko-agent-egress-proxy/app/src/main/scala/LogHelper.scala): `container/ko-agent-egress-proxy/app/src/main/scala/LogHelper.scala`

### Host integrations

- [Run-on-host supervisor](https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/RunOnHostSandbox.scala): `src/main/scala/RunOnHostSandbox.scala`
- [Host prerequisites](https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/RunOnHostPrereqs.scala): `src/main/scala/RunOnHostPrereqs.scala`
- [Host command sessions](https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/RunOnHostSession.scala): `src/main/scala/RunOnHostSession.scala`
- [Clipboard relay](https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/ClipboardRelay.scala): `src/main/scala/ClipboardRelay.scala`
- [Microphone relay](https://github.com/ken1ma/ko-agent-sandbox/blob/main/src/main/scala/MicrophoneRelay.scala): `src/main/scala/MicrophoneRelay.scala`

### Other components

- **User**
- **Internet destinations**

## Connections

- User → Launcher: starts (evidence: `README.md`)
- Launcher → Command options: parses options (evidence: `src/main/scala/AgentSandboxLauncher.scala`)
- Launcher → Workspace mounts: selects workspace (evidence: `src/main/scala/AgentSandboxLauncher.scala`)
- Launcher → Launcher state: uses state (evidence: `src/main/scala/AgentSandboxLauncher.scala`)
- Launcher → Image lifecycle: builds images (evidence: `src/main/scala/AgentSandboxLauncher.scala`)
- Launcher → Agent container: starts container (evidence: `README.md`)
- Agent container → Coding agent: runs (evidence: `README.md`)
- Agent container → Filesystem guard: guards filesystem
- Filesystem guard → Git policy: checks mutations (evidence: `fuse/ko-agent-fs/src/fs.rs`)
- Launcher → File protections: configures protections (evidence: `src/main/scala/AgentSandboxLauncher.scala`)
- Coding agent → Egress proxy: sends egress (evidence: `README.md`)
- Launcher → Egress proxy: starts proxy (evidence: `src/main/scala/AgentSandboxLauncher.scala`)
- Egress proxy → Egress rules: resolves rules (evidence: `container/ko-agent-egress-proxy/app/src/main/scala/AgentEgressProxy.scala`)
- Egress proxy → HTTP handling: handles requests (evidence: `container/ko-agent-egress-proxy/app/src/main/scala/AgentEgressProxy.scala`)
- Egress proxy → Proxy audit log: records events (evidence: `container/ko-agent-egress-proxy/app/src/main/scala/AgentEgressProxy.scala`)
- Egress proxy → Internet destinations: allows destinations (evidence: `README.md`)
- Launcher → Run-on-host supervisor: supervises host commands (evidence: `src/main/scala/AgentSandboxLauncher.scala`)
- Run-on-host supervisor → Host prerequisites: checks prerequisites (evidence: `src/main/scala/RunOnHostSandbox.scala`)
- Run-on-host supervisor → Host command sessions: manages sessions (evidence: `src/main/scala/RunOnHostSandbox.scala`)
- Coding agent → Clipboard relay: uses relay (evidence: `README.md`)
- Coding agent → Microphone relay: uses relay (evidence: `README.md`)
