Skip to content
Open
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
46 changes: 46 additions & 0 deletions example/claude-code-agent/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Claude Code AgentRuntime example image.
# Build context: repository root
#
# Build:
# docker build -t claude-code-agent:latest -f example/claude-code-agent/Dockerfile .

FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim

WORKDIR /app

ARG NODE_VERSION=22.11.0
ARG TARGETARCH
ARG APT_MIRROR=https://mirrors.aliyun.com/debian
ARG APT_SECURITY_MIRROR=https://mirrors.aliyun.com/debian-security
ARG NODE_DIST_BASE=https://npmmirror.com/mirrors/node
ARG NPM_REGISTRY=https://registry.npmmirror.com
ARG PYPI_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
Comment thread
googs1025 marked this conversation as resolved.
RUN sed -i "s|http://deb.debian.org/debian-security|${APT_SECURITY_MIRROR}|g; s|http://deb.debian.org/debian|${APT_MIRROR}|g" /etc/apt/sources.list.d/debian.sources \
&& apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates curl git xz-utils \
&& rm -rf /var/lib/apt/lists/* \
&& case "${TARGETARCH}" in \
arm64) node_arch="arm64" ;; \
amd64) node_arch="x64" ;; \
*) echo "Unsupported TARGETARCH: ${TARGETARCH}" >&2; exit 1 ;; \
esac \
Comment on lines +22 to +26
&& curl -fsSL "${NODE_DIST_BASE}/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${node_arch}.tar.xz" \
| tar -xJ --strip-components=1 -C /usr/local \
&& npm config set registry "${NPM_REGISTRY}" \
&& npm install -g @anthropic-ai/claude-code
Comment on lines +18 to +30

COPY example/claude-code-agent/requirements.txt ./
RUN uv pip install --system --no-cache --index-url "${PYPI_INDEX_URL}" -r requirements.txt

COPY example/claude-code-agent/agent.py ./

RUN mkdir -p /workspace

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
WORKSPACE_DIR=/workspace \
PORT=8080

EXPOSE 8080

CMD ["python", "agent.py"]
102 changes: 102 additions & 0 deletions example/claude-code-agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Claude Code AgentRuntime Example

This example runs a Claude Code SDK agent loop inside an AgentCube
`AgentRuntime` sandbox. AgentCube manages per-session sandbox lifecycle through
`x-agentcube-session-id`; the container exposes a small FastAPI service and
calls `claude-agent-sdk`.

## Files

```text
example/claude-code-agent/
├── README.md
├── agent.py
├── invoke_with_sdk.py
├── requirements.txt
├── Dockerfile
└── claude-code-agent.yaml
```

## Build

```bash
docker build -t claude-code-agent:latest \
-f example/claude-code-agent/Dockerfile .
```

The Dockerfile defaults to Aliyun/npmmirror/PyPI mirrors for faster builds in
China. Override build args in the Dockerfile if your environment needs other
mirrors.

For minikube:

```bash
minikube image load claude-code-agent:latest
```

## Deploy

Create the API key secret:

```bash
kubectl create secret generic claude-code-agent-secrets \
--from-literal=anthropic-auth-token=<YOUR_API_KEY>
```

Apply the runtime:

```bash
kubectl apply -f example/claude-code-agent/claude-code-agent.yaml
```

The default manifest uses:

```text
ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
ANTHROPIC_MODEL=deepseek-v4-flash
Comment thread
googs1025 marked this conversation as resolved.
```

## Invoke

Port-forward the AgentCube Router if needed:

```bash
kubectl -n agentcube port-forward deploy/agentcube-router 8081:8080
```

Health check:

```bash
curl -i \
http://localhost:8081/v1/namespaces/default/agent-runtimes/claude-code-agent/invocations/health
```

Agent call:

```bash
curl -sS \
http://localhost:8081/v1/namespaces/default/agent-runtimes/claude-code-agent/invocations/ \
-H "Content-Type: application/json" \
-H "x-agentcube-session-id: <SESSION_ID_FROM_HEALTH_RESPONSE>" \
-d '{"prompt":"Reply with OK only.","max_turns":3}'
```

Pass the same `x-agentcube-session-id` header to reuse the same sandbox.

## Invoke With SDK

Install the AgentCube Python SDK, then run the example client:

```bash
pip install -e sdk-python

ROUTER_URL=http://localhost:8081 \
python example/claude-code-agent/invoke_with_sdk.py
```

Reuse a session:

```bash
AGENTCUBE_SESSION_ID=<SESSION_ID> \
python example/claude-code-agent/invoke_with_sdk.py
```
Loading
Loading