# devincd/agents architecture

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

- Interactive diagram: https://gitdiagram.com/devincd/agents
- Repository: https://github.com/devincd/agents

## Overview

OpenKruise Agents manages AI-agent sandboxes on Kubernetes, offering Kubernetes CRDs and E2B-compatible APIs. A user requests a sandbox through the E2B API; the manager translates requests into sandbox operations, while Kubernetes controllers reconcile sandbox workloads and related resources. Gateway components handle sandbox routing and authentication. Separate controller capabilities cover claims, sets, autoscaling, updates, checkpoints, and commits. The graph uses README statements and SOURCE INDEX references for documented or visible links; unsampled components are represented by their listed source paths, with uncertain wiring omitted.

Main entry points: [`cmd/sandbox-gateway/main.go`](https://github.com/devincd/agents/blob/master/cmd/sandbox-gateway/main.go) (Sandbox gateway), [`pkg/sandbox-gateway/controller/gateway_controller.go`](https://github.com/devincd/agents/blob/master/pkg/sandbox-gateway/controller/gateway_controller.go) (Route controller), [`pkg/sandbox-gateway/registry/registry.go`](https://github.com/devincd/agents/blob/master/pkg/sandbox-gateway/registry/registry.go) (Route registry), [`pkg/controller/poolautoscaler/poolautoscaler_controller.go`](https://github.com/devincd/agents/blob/master/pkg/controller/poolautoscaler/poolautoscaler_controller.go) (Pool autoscaler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and management"]
  node_e2b["E2B API<br/>[routes.go]"]
  node_manager["Sandbox manager<br/>[main.go]"]
  node_sandboxcr["Sandbox infrastructure<br/>[infra.go]"]
  node_crds["Kubernetes APIs<br/>[sandbox_types.go]"]
end

subgraph group_lifecycle["Sandbox lifecycle"]
  node_sandboxctl["Sandbox controller"]
  node_claimctl["Sandbox claims"]
  node_setctl["Sandbox sets"]
  node_autoscaler["Pool autoscaler"]
  node_updateops["Update operations"]
  node_tokenrefresh["Token refresh"]
  node_webhooks["Admission webhooks<br/>[server.go]"]
end

subgraph group_access["Gateway and routing"]
  node_gateway["Sandbox gateway<br/>[main.go]"]
  node_gatewayctl["Route controller"]
  node_registry[("Route registry<br/>[registry.go]")]
  node_jwtauth["JWT authentication<br/>[manager.go]"]
  node_proxy["Traffic proxy<br/>[server.go]"]
  node_route_refresh["Peer route refresh<br/>[handler.go]"]
end

subgraph group_persistence["Checkpoint and storage"]
  node_checkpoint["Checkpoint operations<br/>[checkpoint.go]"]
  node_commit["Sandbox commits"]
  node_storage["CSI storage mounts"]
  node_storagecli["Storage runtime<br/>[main.go]"]
end

node_user(("Sandbox user"))
node_kube["Kubernetes"]

node_user -->|"requests sandbox"| node_e2b
node_e2b -->|"calls management"| node_manager
node_manager -->|"uses infrastructure"| node_sandboxcr
node_sandboxcr -.->|"manages resources"| node_crds
node_kube -.->|"triggers reconciliation"| node_sandboxctl
node_sandboxctl -->|"reads and patches"| node_kube
node_claimctl -->|"reconciles claims"| node_kube
node_setctl -->|"reconciles sets"| node_kube
node_autoscaler -->|"scales target"| node_setctl
node_autoscaler -->|"reads resources"| node_kube
node_updateops -->|"reconciles updates"| node_kube
node_tokenrefresh -->|"watches resources"| node_kube
node_webhooks -->|"serves admission"| node_kube
node_gateway -->|"starts route feed"| node_gatewayctl
node_gateway -->|"configures authentication"| node_jwtauth
node_gateway -->|"gets registry"| node_registry
node_gatewayctl -->|"updates routes"| node_registry
node_gatewayctl -->|"watches sandboxes"| node_kube
node_proxy -->|"serves refresh"| node_route_refresh
node_proxy -->|"stores routes"| node_registry
node_checkpoint -.->|"coordinates checkpoint"| node_kube
node_commit -->|"reconciles commits"| node_kube
node_storage -->|"reads volumes"| node_kube
node_storage -.->|"selects provider"| node_storagecli

click node_e2b "https://github.com/devincd/agents/blob/master/pkg/servers/e2b/routes.go"
click node_manager "https://github.com/devincd/agents/blob/master/cmd/sandbox-manager/main.go"
click node_sandboxcr "https://github.com/devincd/agents/blob/master/pkg/sandbox-manager/infra/sandboxcr/infra.go"
click node_crds "https://github.com/devincd/agents/blob/master/api/v1alpha1/sandbox_types.go"
click node_sandboxctl "https://github.com/devincd/agents/blob/master/pkg/controller/sandbox/sandbox_controller.go"
click node_claimctl "https://github.com/devincd/agents/blob/master/pkg/controller/sandboxclaim/sandboxclaim_controller.go"
click node_setctl "https://github.com/devincd/agents/blob/master/pkg/controller/sandboxset/sandboxset_controller.go"
click node_autoscaler "https://github.com/devincd/agents/blob/master/pkg/controller/poolautoscaler/poolautoscaler_controller.go"
click node_updateops "https://github.com/devincd/agents/blob/master/pkg/controller/sandboxupdateops/sandboxupdateops_controller.go"
click node_tokenrefresh "https://github.com/devincd/agents/blob/master/pkg/controller/securitytokenrefresh/token_refresh_controller.go"
click node_webhooks "https://github.com/devincd/agents/blob/master/pkg/webhook/server.go"
click node_gateway "https://github.com/devincd/agents/blob/master/cmd/sandbox-gateway/main.go"
click node_gatewayctl "https://github.com/devincd/agents/blob/master/pkg/sandbox-gateway/controller/gateway_controller.go"
click node_registry "https://github.com/devincd/agents/blob/master/pkg/sandbox-gateway/registry/registry.go"
click node_jwtauth "https://github.com/devincd/agents/blob/master/pkg/sandbox-gateway/jwtauth/manager.go"
click node_proxy "https://github.com/devincd/agents/blob/master/pkg/proxy/server.go"
click node_route_refresh "https://github.com/devincd/agents/blob/master/pkg/sandboxroute/refresh/handler.go"
click node_checkpoint "https://github.com/devincd/agents/blob/master/pkg/controller/sandbox/core/checkpoint.go"
click node_commit "https://github.com/devincd/agents/blob/master/pkg/controller/commit/commit_controller.go"
click node_storage "https://github.com/devincd/agents/blob/master/pkg/utils/csiutils/storages_provider.go"
click node_storagecli "https://github.com/devincd/agents/blob/master/pkg/agent-runtime/storage-cli/main.go"

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_e2b,node_manager,node_sandboxcr,node_crds,node_user toneBlue
class node_sandboxctl,node_claimctl,node_setctl,node_autoscaler,node_updateops,node_tokenrefresh,node_webhooks toneAmber
class node_gateway,node_gatewayctl,node_registry,node_jwtauth,node_proxy,node_route_refresh toneMint
class node_checkpoint,node_commit,node_storage,node_storagecli toneRose
class node_kube toneIndigo
```

## Components

### API and management

- [E2B API](https://github.com/devincd/agents/blob/master/pkg/servers/e2b/routes.go): `pkg/servers/e2b/routes.go`
- [Sandbox manager](https://github.com/devincd/agents/blob/master/cmd/sandbox-manager/main.go): `cmd/sandbox-manager/main.go`
- [Sandbox infrastructure](https://github.com/devincd/agents/blob/master/pkg/sandbox-manager/infra/sandboxcr/infra.go): `pkg/sandbox-manager/infra/sandboxcr/infra.go`
- [Kubernetes APIs](https://github.com/devincd/agents/blob/master/api/v1alpha1/sandbox_types.go): `api/v1alpha1/sandbox_types.go`

### Sandbox lifecycle

- [Sandbox controller](https://github.com/devincd/agents/blob/master/pkg/controller/sandbox/sandbox_controller.go): `pkg/controller/sandbox/sandbox_controller.go`
- [Sandbox claims](https://github.com/devincd/agents/blob/master/pkg/controller/sandboxclaim/sandboxclaim_controller.go): `pkg/controller/sandboxclaim/sandboxclaim_controller.go`
- [Sandbox sets](https://github.com/devincd/agents/blob/master/pkg/controller/sandboxset/sandboxset_controller.go): `pkg/controller/sandboxset/sandboxset_controller.go`
- [Pool autoscaler](https://github.com/devincd/agents/blob/master/pkg/controller/poolautoscaler/poolautoscaler_controller.go): `pkg/controller/poolautoscaler/poolautoscaler_controller.go`
- [Update operations](https://github.com/devincd/agents/blob/master/pkg/controller/sandboxupdateops/sandboxupdateops_controller.go): `pkg/controller/sandboxupdateops/sandboxupdateops_controller.go`
- [Token refresh](https://github.com/devincd/agents/blob/master/pkg/controller/securitytokenrefresh/token_refresh_controller.go): `pkg/controller/securitytokenrefresh/token_refresh_controller.go`
- [Admission webhooks](https://github.com/devincd/agents/blob/master/pkg/webhook/server.go): `pkg/webhook/server.go`

### Gateway and routing

- [Sandbox gateway](https://github.com/devincd/agents/blob/master/cmd/sandbox-gateway/main.go): `cmd/sandbox-gateway/main.go`
- [Route controller](https://github.com/devincd/agents/blob/master/pkg/sandbox-gateway/controller/gateway_controller.go): `pkg/sandbox-gateway/controller/gateway_controller.go`
- [Route registry](https://github.com/devincd/agents/blob/master/pkg/sandbox-gateway/registry/registry.go): `pkg/sandbox-gateway/registry/registry.go`
- [JWT authentication](https://github.com/devincd/agents/blob/master/pkg/sandbox-gateway/jwtauth/manager.go): `pkg/sandbox-gateway/jwtauth/manager.go`
- [Traffic proxy](https://github.com/devincd/agents/blob/master/pkg/proxy/server.go): `pkg/proxy/server.go`
- [Peer route refresh](https://github.com/devincd/agents/blob/master/pkg/sandboxroute/refresh/handler.go): `pkg/sandboxroute/refresh/handler.go`

### Checkpoint and storage

- [Checkpoint operations](https://github.com/devincd/agents/blob/master/pkg/controller/sandbox/core/checkpoint.go): `pkg/controller/sandbox/core/checkpoint.go`
- [Sandbox commits](https://github.com/devincd/agents/blob/master/pkg/controller/commit/commit_controller.go): `pkg/controller/commit/commit_controller.go`
- [CSI storage mounts](https://github.com/devincd/agents/blob/master/pkg/utils/csiutils/storages_provider.go): `pkg/utils/csiutils/storages_provider.go`
- [Storage runtime](https://github.com/devincd/agents/blob/master/pkg/agent-runtime/storage-cli/main.go): `pkg/agent-runtime/storage-cli/main.go`

### Other components

- **Sandbox user**
- **Kubernetes**

## Connections

- Sandbox user → E2B API: requests sandbox (evidence: `README.md`)
- E2B API → Sandbox manager: calls management
- Sandbox manager → Sandbox infrastructure: uses infrastructure (evidence: `cmd/sandbox-manager/main.go`)
- Sandbox infrastructure → Kubernetes APIs: manages resources
- Kubernetes → Sandbox controller: triggers reconciliation
- Sandbox controller → Kubernetes: reads and patches (evidence: `pkg/controller/sandbox/sandbox_controller.go`)
- Sandbox claims → Kubernetes: reconciles claims (evidence: `pkg/controller/sandboxclaim/sandboxclaim_controller.go`)
- Sandbox sets → Kubernetes: reconciles sets (evidence: `pkg/controller/sandboxset/sandboxset_controller.go`)
- Pool autoscaler → Sandbox sets: scales target (evidence: `pkg/controller/poolautoscaler/poolautoscaler_controller.go`)
- Pool autoscaler → Kubernetes: reads resources (evidence: `pkg/controller/poolautoscaler/poolautoscaler_controller.go`)
- Update operations → Kubernetes: reconciles updates (evidence: `pkg/controller/sandboxupdateops/sandboxupdateops_controller.go`)
- Token refresh → Kubernetes: watches resources (evidence: `pkg/controller/securitytokenrefresh/token_refresh_controller.go`)
- Admission webhooks → Kubernetes: serves admission (evidence: `pkg/webhook/server.go`)
- Sandbox gateway → Route controller: starts route feed (evidence: `cmd/sandbox-gateway/main.go`)
- Sandbox gateway → JWT authentication: configures authentication (evidence: `cmd/sandbox-gateway/main.go`)
- Sandbox gateway → Route registry: gets registry (evidence: `cmd/sandbox-gateway/main.go`)
- Route controller → Route registry: updates routes (evidence: `pkg/sandbox-gateway/controller/gateway_controller.go`)
- Route controller → Kubernetes: watches sandboxes (evidence: `pkg/sandbox-gateway/controller/gateway_controller.go`)
- Traffic proxy → Peer route refresh: serves refresh (evidence: `pkg/proxy/server.go`)
- Traffic proxy → Route registry: stores routes
- Checkpoint operations → Kubernetes: coordinates checkpoint
- Sandbox commits → Kubernetes: reconciles commits (evidence: `pkg/controller/commit/commit_controller.go`)
- CSI storage mounts → Kubernetes: reads volumes (evidence: `pkg/utils/csiutils/storages_provider.go`)
- CSI storage mounts → Storage runtime: selects provider
