Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,33 @@ Follow these steps to build, update, and redeploy the worker stack:
First, cleanup:

```bash
kubectl delete deployments,statefulsets,workerpools,actortemplates,services,secrets --all -n ate-ant
kubectl delete deployments,statefulsets,workerpools,services,secrets --all -n ate-ant
```

## 2. Build and Push Container Image
The `ActorTemplate` lives in the Substrate control plane, not in Kubernetes;
delete it with `kubectl-ate delete actor-template ate-ant-actor-template --atespace=ate-ant`.

Build the container image with the updated binaries and push to Google Container Registry (GCR):
## 2. Build and Push Container Images

Build the `ate-ant` image and the Agent Substrate gVisor worker image
(`ateworker-gvisor`, built with `ko` from the `go.ate.dev/substrate` version
pinned in `go.mod`), push them to Google Container Registry (GCR), and update
the digests in `benchmarks/install.sh` and `README.md`:

```bash
export GOOGLE_CLOUD_PROJECT="your-gcp-project"
make push
./benchmarks/build-images.sh
```

Note the image digest emitted by `make push` (e.g. `gcr.io/$GOOGLE_CLOUD_PROJECT/ate-ant@sha256:...`).
To rebuild only `ate-ant`, run `make push` (or
`BUILD_SUBSTRATE_IMAGES=false ./benchmarks/build-images.sh`) and note the
digest it emits (e.g. `gcr.io/$GOOGLE_CLOUD_PROJECT/ate-ant@sha256:...`).

## 3. Update README

Update the `--worker-image` flag in [`README.md`](file:///Users/jbd/substrate-anthropic-worker/README.md) with the new digest-pinned image tag from step 2.
`build-images.sh` updates the `--worker-image` and `--ateom-image` flags in
[`README.md`](file:///Users/jbd/claude-managed-agents/README.md); if you used
`make push`, update `--worker-image` with the new digest-pinned image by hand.

## 4. Generate and Apply Manifests

Expand All @@ -34,17 +44,23 @@ Generate the Kubernetes manifests using `ate-ant manifest` and apply them to the
```bash
go run ./cmd/ate-ant manifest \
--worker-image gcr.io/$GOOGLE_CLOUD_PROJECT/ate-ant@sha256:... \
--ateom-image gcr.io/$GOOGLE_CLOUD_PROJECT/ate-images/ateom-gvisor@sha256:e3ccd735b31a0f448070bfeefded7b79c91013c40c128eecc84ae90e6b6b44f7 | kubectl apply -f -
--ateom-image gcr.io/$GOOGLE_CLOUD_PROJECT/ate-images/ateworker-gvisor@sha256:... | kubectl apply -f -
```

Register the `ActorTemplate` in Substrate control plane using `ate-ant manifest template`:
Register the `ActorTemplate` in Substrate control plane using `ate-ant manifest template`.
Use a `kubectl-ate` built from the same Substrate version as the cluster
(`go install ./cmd/kubectl-ate` in the Substrate checkout); `--preview` is
required while the `PerTemplateSnapshotLocation` preview gate is enabled:

```bash
go run ./cmd/ate-ant manifest template \
--worker-image gcr.io/$GOOGLE_CLOUD_PROJECT/ate-ant@sha256:... \
--snapshots-bucket gs://$GOOGLE_CLOUD_PROJECT/ate-ant/ | kubectl-ate create actor-template -f -
--snapshots-bucket gs://$GOOGLE_CLOUD_PROJECT/ate-ant/ | kubectl-ate create actor-template --preview -f -
```

For the benchmark cluster, `INSTALL_SUBSTRATE=false ./benchmarks/install.sh`
performs steps 4 and 5 using the digests pinned in the script.

## 5. Verify Pods

Check that all worker pool and controller pods are running:
Expand All @@ -71,6 +87,7 @@ kubectl exec -n ate-ant valkey-0 -- valkey-cli xinfo groups stream:events
| --- | --- | --- |
| `ate-ant` | `Namespace` | Target Kubernetes namespace |
| `ate-ant-creds` | `Secret` | Stores Anthropic credentials and Valkey connection string |
| `k8s-credential-provider-namespace-policy` | `ConfigMap` (in `ate-system`) | Grants the `ate-ant` atespace the labeled `ate-ant-creds` Secret for egress environment key injection (restart `k8s-credential-provider` after applying) |
| `ate-ant-creds-reader` | `Role` / `RoleBinding` | RBAC allowing `ate-api-server` to resolve credentials for actor resumption |
| `valkey` | `Service` & `StatefulSet` | Single-replica Valkey instance backing the session lifecycle event queue |
| `ate-ant-workerpool` | `WorkerPool` (`ate.dev/v1alpha1`) | Pool of gVisor/microVM runners for sandbox actors (10 replicas) |
Expand Down
108 changes: 50 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,102 @@
# Claude Managed Agents on Agent Substrate

Deploy [Anthropic Managed Agents Self-Hosted Sandbox](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes) workers on [Agent Substrate](https://github.com/agent-substrate/substrate).

This project runs Claude Managed Agents work (e.g. tool calls like bash, file operations, skills) inside isolated Agent Substrate gVisor/microVM actors with durable orchestration.
Run [Claude Managed Agents self-hosted sandbox](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes) work (tool calls such as bash, file operations, and skills) inside isolated [Agent Substrate](https://github.com/agent-substrate/substrate) gVisor/microVM actors.

## Overview

```
┌────────────────────────┐ Poll work items
│ Claude Managed Agents │ ◄─────────────────────────────────────────────┐
└────────────────────────┘ │
▼
┌───────────────────────────────────────┐
│ Controller (`ate-ant controller`) │
│ │
│ ┌─────────────────────────────────┐ │
│ │ Poller loop │ │
│ └────────────────┬────────────────┘ │
└───────────────────┼───────────────────┘
Enqueue (resume) │
▼
┌────────────────────────┐ Consume event ┌───┬───┬───┬────────────┐
│ Controller (`ate-ant │ ◄──────────────────────── │ │ │ │ Event Queue│
│ controller`) │ └───┴───┴───┴────────────┘
└───────────┬────────────┘
│
├── Notify (POST /work) ───────► ┌────────────────────────┐
│ │ Actor (`ate-ant run`) │
└── GC & Suspend (idle > 30s) ─► └────────────────────────┘
┌───────────────────────┐ poll & ack ┌──────────────────────┐ enqueue/consume ┌──────────────┐
│ Claude Managed Agents │ ◄──────────────── │ Controller │ ◄──────────────► │ Valkey queue │
└───────────────────────┘ │ (ate-ant controller) │ └──────────────┘
▲ └──────────┬───────────┘
│ │ resume, POST /work,
│ │ suspend when idle
│ tool results, heartbeats ▼
│ ┌──────────────────────┐
└────────────────────────────── │ Actor (ate-ant run) │
└──────────────────────┘
```

### Components

- **Controller**: A horizontally scalable daemon running `ate-ant controller`. Each replica runs an Anthropic poller loop and an event reconcile loop. Poller loops claim and acknowledge work items from the Anthropic API and enqueue them into Valkey. Controller loops consume lifecycle events from the queue (distributed among replicas via consumer groups), manage Substrate actor lifecycles (creating, resuming, suspending), and notify actors of work payloads via `atenet-router`.
- **Queue**: An in-cluster Valkey/Redis instance buffering session lifecycle events, providing durable work distribution and decoupling ingestion from execution.
- **Actors**: Dedicated, isolated environments assigned to each agent session running `ate-ant run`. They execute tools (bash commands, file operations, skills) with the Anthropic SDK's environment worker in-process and preserve session state across turns via snapshot persistence.
- **Controller** (`ate-ant controller`): horizontally scalable. Each replica polls the Anthropic API for work and enqueues it in Valkey, then consumes lifecycle events from the queue (shared across replicas through a consumer group), creates, resumes, and suspends Substrate actors, and delivers work to actors through `atenet-router`.
- **Queue**: an in-cluster Valkey instance that buffers session lifecycle events, decoupling ingestion from execution.
- **Actors** (`ate-ant run`): one isolated sandbox per agent session. Each runs the Anthropic SDK's environment worker in-process to execute tools, and keeps session state across turns through snapshots.
- **Environment key injection**: actors never hold the Anthropic environment key. They send a placeholder bearer token, and the Substrate egress gateway replaces it with `ANTHROPIC_ENVIRONMENT_KEY` from the `ate-ant-creds` Secret on requests to the Anthropic API.

See [DESIGN.md](DESIGN.md) for detailed architecture, event queuing, and actor lifecycle workflows.
See [DESIGN.md](DESIGN.md) for the detailed architecture, event queuing, and actor lifecycle.

## Quickstart

### Prerequisites

1. An [Agent Substrate](https://github.com/agent-substrate/substrate) cluster.
2. Anthropic credentials: `ANTHROPIC_API_KEY`, `ANTHROPIC_ENVIRONMENT_ID`, and optional `ANTHROPIC_ENVIRONMENT_KEY` (see [Creating a Self-Hosted Environment](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes#create-an-environment)). To use a custom Anthropic API URL instead of the public API, also set `ANTHROPIC_BASE_URL` (or pass `--anthropic-base-url`).
3. Google Cloud project (`GOOGLE_CLOUD_PROJECT`) and GCS bucket for snapshots (`gs://$GOOGLE_CLOUD_PROJECT/ate-ant/`).
4. Podman (or Docker) for building container images.
2. Anthropic credentials: `ANTHROPIC_API_KEY`, `ANTHROPIC_ENVIRONMENT_ID`, and `ANTHROPIC_ENVIRONMENT_KEY` (see [Creating a Self-Hosted Environment](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes#create-an-environment)). To use a custom Anthropic API URL, also set `ANTHROPIC_BASE_URL` (or pass `--anthropic-base-url`).
3. A Google Cloud project (`GOOGLE_CLOUD_PROJECT`) and a GCS bucket for snapshots (`gs://$GOOGLE_CLOUD_PROJECT/ate-ant/`).
4. Podman (or Docker) to build the container image.

### Push Container Image
### 1. Build and Push the Image

```bash
export GOOGLE_CLOUD_PROJECT="your-gcp-project"
make push
```

### 1. Apply Kubernetes Manifests
`make push` prints the digest-pinned image. Use it as `--worker-image` in the steps below in place of the pinned digest.

Update the container images before applying the manifests.
### 2. Apply the Kubernetes Manifests

> **Note:** Building your own images is temporary; pre-built images will be distributed in an upcoming release.
`--worker-image` is the `ate-ant` image from step 1, used by the controller and the actors. `--ateom-image` is the Agent Substrate gVisor worker that the WorkerPool runs.

```bash
go run ./cmd/ate-ant manifest \
--worker-image gcr.io/$GOOGLE_CLOUD_PROJECT/ate-ant@sha256:e6d05802b220e9c0976d7a0c2639e54cf263f4e1d4d376ce0f70b520664f9a40 \
--ateom-image gcr.io/$GOOGLE_CLOUD_PROJECT/ate-images/ateom-gvisor@sha256:7d8878129e707c2842691cdef1f919450985df3f223dbb65361baca79c789e58 | kubectl apply -f -
--worker-image gcr.io/$GOOGLE_CLOUD_PROJECT/ate-ant@sha256:2f5b931584f80ccbd72851058a597af39e706eeaa20dfd86a7bc2fcd7410b416 \
--ateom-image gcr.io/$GOOGLE_CLOUD_PROJECT/ate-images/ateworker-gvisor@sha256:c97cf56ec19ef37895a0e7cc5c6dada677cb3824c5e93fcf7f142053cfe19a85 | kubectl apply -f -
```

### 2. Register the ActorTemplate in Substrate
### 3. Restart the Credential Provider

Substrate manages ActorTemplates directly in its control plane rather than Kubernetes CRDs. Use `ate-ant manifest template` to generate the Substrate ActorTemplate manifest:
The manifests include the Kubernetes Secrets credential provider's policy, which grants the `ate-ant` atespace access to the `ate-ant-creds` Secret only. The provider reads its policy at startup:

```bash
go run ./cmd/ate-ant manifest template \
--worker-image gcr.io/$GOOGLE_CLOUD_PROJECT/ate-ant@sha256:e6d05802b220e9c0976d7a0c2639e54cf263f4e1d4d376ce0f70b520664f9a40 \
--snapshots-bucket gs://$GOOGLE_CLOUD_PROJECT/ate-ant/ | kubectl-ate create actor-template -f -
kubectl -n ate-system rollout restart deployment/k8s-credential-provider
```

### Verify Deployment
### 4. Grant the Controller Access to Substrate

Check that all worker pool, Valkey, and controller pods are running:
Agent Substrate authorizes every API call. Create the atespace and give the controller's `router-client` ServiceAccount the `editor` role, which lets it create, resume, and suspend actors:

```bash
kubectl get pods -n ate-ant
kubectl-ate create atespace ate-ant
kubectl-ate create access-policy -a ate-ant -f - <<EOF
bindings:
- role: editor
members:
- user:system:serviceaccount:ate-ant:router-client
EOF
```

Stream logs from the controller daemon:
### 5. Register the ActorTemplate

ActorTemplates live in the Substrate control plane, not in Kubernetes:

```bash
go run ./cmd/ate-ant manifest template \
--worker-image gcr.io/$GOOGLE_CLOUD_PROJECT/ate-ant@sha256:2f5b931584f80ccbd72851058a597af39e706eeaa20dfd86a7bc2fcd7410b416 \
--snapshots-bucket gs://$GOOGLE_CLOUD_PROJECT/ate-ant/ | kubectl-ate create actor-template --preview -f -
```

### 6. Verify

```bash
kubectl get pods -n ate-ant
kubectl logs -n ate-ant -l app=ate-ant-controller -f
```

## Example Agent

```bash
# 1. Set environment variables
export ANTHROPIC_API_KEY="sk-ant-api..."
export ANTHROPIC_ENVIRONMENT_ID="env_..."

# 2. Run example with an initial prompt
go run ./examples/agent --prompt "Run 'uname -a' in bash and show the output."
```

Expand All @@ -113,11 +112,4 @@ podman run -it --rm \
gcr.io/$GOOGLE_CLOUD_PROJECT/ate-ant:latest
```

Inside the container:
- **Run worker manually**: `ant beta:worker run --work-id "<work-id>" --session-id "<session-id>"`

## Roadmap

- [ ] **Distribute prebuilt images** so deploying is one `kubectl apply` with no build step.
- [x] **Durable session orchestration** with distributed locking, retries, crash recovery, and auto-ACKing.
- [x] **Enable garbage collection** to automatically suspend idle actors.
Inside the container, run a worker manually with `ant beta:worker run --work-id "<work-id>" --session-id "<session-id>"`.
4 changes: 2 additions & 2 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export ZONE="us-west1-a"

## 2. Rebuild Images & Install Stack

To rebuild both the `ate-ant` image and Agent Substrate images (`ateapi`, `atecontroller`, `atelet`, `atenet`, `podcertcontroller`, `ateom-gvisor`) and automatically update [`install.sh`](install.sh) and [`../README.md`](../README.md) with the new `@sha256:...` digests, run [`build-images.sh`](build-images.sh):
To rebuild both the `ate-ant` image and the Agent Substrate gVisor worker image (`ateworker-gvisor`, built with `ko` from the `go.ate.dev/substrate` version pinned in `go.mod`) and automatically update [`install.sh`](install.sh) and [`../README.md`](../README.md) with the new `@sha256:...` digests, run [`build-images.sh`](build-images.sh):

```bash
export GOOGLE_CLOUD_PROJECT="kubecon-na-26-keynote-demo"

# Rebuild ate-ant + Agent Substrate images and update install.sh with the new sha256 digests
./benchmarks/build-images.sh

# Or skip rebuilding Agent Substrate images and only rebuild ate-ant
# Or skip rebuilding the Agent Substrate worker image and only rebuild ate-ant
BUILD_SUBSTRATE_IMAGES=false ./benchmarks/build-images.sh
```

Expand Down
47 changes: 47 additions & 0 deletions benchmarks/access-policy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Creates or replaces the ate-api access policy of the ate-ant atespace.
# ate-api enforces authorization on every call, so each in-cluster client needs
# a role:
# - router-client (controller, loadgen): editor, to create, resume, and
# suspend session actors.
# - ate-ant-dashboard (dashboard): viewer, to list actors.
#
# Usage: NAMESPACE=ate-ant ./benchmarks/access-policy.sh

set -o errexit -o nounset -o pipefail

NAMESPACE="${NAMESPACE:-ate-ant}"
KUBECTL_ATE_BIN="${KUBECTL_ATE_BIN:-$(command -v kubectl-ate || echo "${HOME}/go/bin/kubectl-ate")}"

ACCESS_POLICY="$(cat <<EOF
bindings:
- role: editor
members:
- user:system:serviceaccount:${NAMESPACE}:router-client
- role: viewer
members:
- user:system:serviceaccount:${NAMESPACE}:ate-ant-dashboard
EOF
)"

if ! echo "${ACCESS_POLICY}" | "${KUBECTL_ATE_BIN}" create access-policy -a "${NAMESPACE}" -f - 2>/dev/null; then
# Updates must carry the existing policy's metadata.uid/version preconditions.
{ echo "${ACCESS_POLICY}"
"${KUBECTL_ATE_BIN}" get access-policy -a "${NAMESPACE}" -o yaml 2>/dev/null | sed -n '/^metadata:/,/^[^ ]/{/^metadata:/p;/^ /p;}'
} | "${KUBECTL_ATE_BIN}" update access-policy -a "${NAMESPACE}" -f -
fi
Loading
Loading