diff --git a/AGENTS.md b/AGENTS.md index 643577df..af3b7c84 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,6 @@ -# This is NOT the Next.js you know +## This is NOT the Next.js you know This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices. diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/actortemplate-retrying.png b/public/images/blog/troubleshoot-agent-substrate-kagent/actortemplate-retrying.png new file mode 100644 index 00000000..495365f0 Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/actortemplate-retrying.png differ diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/conditions-healthy.png b/public/images/blog/troubleshoot-agent-substrate-kagent/conditions-healthy.png new file mode 100644 index 00000000..909871d5 Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/conditions-healthy.png differ diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/conditions-missing-model.png b/public/images/blog/troubleshoot-agent-substrate-kagent/conditions-missing-model.png new file mode 100644 index 00000000..65917e48 Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/conditions-missing-model.png differ diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/conditions-reserved-env.png b/public/images/blog/troubleshoot-agent-substrate-kagent/conditions-reserved-env.png new file mode 100644 index 00000000..201aa47b Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/conditions-reserved-env.png differ diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/conditions-workerpool-not-found.png b/public/images/blog/troubleshoot-agent-substrate-kagent/conditions-workerpool-not-found.png new file mode 100644 index 00000000..cd5dce95 Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/conditions-workerpool-not-found.png differ diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/controller-rpc-errors.png b/public/images/blog/troubleshoot-agent-substrate-kagent/controller-rpc-errors.png new file mode 100644 index 00000000..c7adbd27 Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/controller-rpc-errors.png differ diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/egress-denied-log.png b/public/images/blog/troubleshoot-agent-substrate-kagent/egress-denied-log.png new file mode 100644 index 00000000..b970a41f Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/egress-denied-log.png differ diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/harness-no-status.png b/public/images/blog/troubleshoot-agent-substrate-kagent/harness-no-status.png new file mode 100644 index 00000000..f5532ea8 Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/harness-no-status.png differ diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/image-digest-rejected.png b/public/images/blog/troubleshoot-agent-substrate-kagent/image-digest-rejected.png new file mode 100644 index 00000000..3f481344 Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/image-digest-rejected.png differ diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/sandbox-dns-blocked.png b/public/images/blog/troubleshoot-agent-substrate-kagent/sandbox-dns-blocked.png new file mode 100644 index 00000000..a54079c8 Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/sandbox-dns-blocked.png differ diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/sandbox-no-workers.png b/public/images/blog/troubleshoot-agent-substrate-kagent/sandbox-no-workers.png new file mode 100644 index 00000000..1084afc5 Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/sandbox-no-workers.png differ diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/sandbox-redirect-trap.png b/public/images/blog/troubleshoot-agent-substrate-kagent/sandbox-redirect-trap.png new file mode 100644 index 00000000..d8e46081 Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/sandbox-redirect-trap.png differ diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/sandbox-request-id.png b/public/images/blog/troubleshoot-agent-substrate-kagent/sandbox-request-id.png new file mode 100644 index 00000000..438f0038 Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/sandbox-request-id.png differ diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/sandbox-suspend-resume.png b/public/images/blog/troubleshoot-agent-substrate-kagent/sandbox-suspend-resume.png new file mode 100644 index 00000000..f2d7dea3 Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/sandbox-suspend-resume.png differ diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/sandboxtemplate-ready-egress-missing.png b/public/images/blog/troubleshoot-agent-substrate-kagent/sandboxtemplate-ready-egress-missing.png new file mode 100644 index 00000000..d17e1e4e Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/sandboxtemplate-ready-egress-missing.png differ diff --git a/public/images/blog/troubleshoot-agent-substrate-kagent/workerpools.png b/public/images/blog/troubleshoot-agent-substrate-kagent/workerpools.png new file mode 100644 index 00000000..6951a6c8 Binary files /dev/null and b/public/images/blog/troubleshoot-agent-substrate-kagent/workerpools.png differ diff --git a/src/blogContent/troubleshoot-agent-substrate-kagent.mdx b/src/blogContent/troubleshoot-agent-substrate-kagent.mdx new file mode 100644 index 00000000..d9007132 --- /dev/null +++ b/src/blogContent/troubleshoot-agent-substrate-kagent.mdx @@ -0,0 +1,676 @@ +export const metadata = { + title: "How to Troubleshoot Agent Substrate with kagent: A Field Guide", + publishDate: "2026-12-02T12:00:00Z", + description: + "Troubleshoot Agent Substrate with kagent OSS: fix Harness, SandboxTemplate, Sandbox, WorkerPool, and egress errors with the commands that confirm each cause.", + author: "Sebastian Maniak", + authorIds: ["sebastianmaniak"], +}; + +# How to Troubleshoot Agent Substrate with kagent: A Field Guide + +When you troubleshoot Agent Substrate with kagent, the first problem is usually finding the error at all. In kagent 1.x, every agent runs on [Agent Substrate](https://kagent.dev/docs/kagent/latest/about/architecture/agent-substrate/). Agent Substrate runs each conversation as an Actor inside a gVisor or micro-VM sandbox. It suspends that Actor to object storage between turns, and it blocks all outbound traffic unless a policy allows it. These defaults make agents safe to run, but they also hide failures. Some failures look healthy, and others look like a different problem entirely. + +Here are four failures that confuse people the first time they see them: + +- A Harness with a typo and a Harness that works look the same in `kubectl get`. +- A WorkerPool that is too small produces a `request timed out` error and logs nothing about capacity. +- A sandbox that is blocked from reaching `pypi.org` reports a DNS error, not a `403`. +- An edit to an AgentTemplate does nothing in the conversation you're testing with. + +This field guide explains why each of these happens and how to fix it. It starts with a short refresher on the resources involved. Then it shows where kagent and Agent Substrate report status. The rest of the guide is a list of symptoms, each with its cause and the command that confirms it. If you haven't installed Agent Substrate yet, start with [Install Agent Substrate on Any Kubernetes Cluster](/blog/install-agent-substrate-any-cluster) or [Install Agent Substrate in One Command with the kagent CLI](/blog/install-kagent-with-the-cli). + +## Key takeaways + +- **Check the Agent, not the Harness.** Harnesses and AgentTemplates report no status. Their health shows up only in the conditions of an Agent that references them. +- **Read the first `False` condition that isn't `Blocked`.** Every condition after it is a consequence. +- **A generic `request timed out` is often a full WorkerPool.** Check the pool's `READY` count and its capacity before anything else. +- **A SandboxTemplate needs a guest image.** The chart doesn't set `config.sandboxes.guestImage`, so no template becomes ready until you do. +- **A DNS error inside a sandbox usually means a missing egress policy.** Check `EgressPoliciesApplied` and the `atenet-egress` log before you debug DNS. +- **Sessions and Sandboxes keep their original revision.** To pick up an edit, start a new one. + +## In this guide + +1. [A 60-second refresher](#a-60-second-refresher-what-youre-actually-debugging) +2. [Where status lives](#before-you-debug-where-status-lives) +3. [Troubleshoot kagent Harness and Agent errors](#part-1-troubleshoot-kagent-harness-and-agent-errors) +4. [Troubleshoot WorkerPools, Actors, and timeouts](#part-2-troubleshoot-workerpools-actors-and-timeouts) +5. [Troubleshoot SandboxTemplates](#part-3-troubleshoot-sandboxtemplates) +6. [Troubleshoot kagent Sandboxes](#part-4-troubleshoot-kagent-sandboxes) +7. [Troubleshoot egress policies](#part-5-troubleshoot-egress-policies-the-dns-error-that-isnt-dns) +8. [Collect evidence](#part-6-collect-evidence) +9. [Cheat sheet](#cheat-sheet) and [FAQ](#faq) + + + +## A 60-second refresher: what you're actually debugging + +Two different sets of resources can run code on Agent Substrate. The two sets have different lifecycles and different status surfaces. + +```mermaid +graph LR + subgraph agentpath["Agent path"] + H["Harness
(kagent / claude / codex / byo)"] + AT["AgentTemplate
(prompt, model, tools)"] + A["Agent
(the only one with status)"] + H --> A + AT --> A + A --> S["Session = Actor"] + end + subgraph sbpath["Sandbox path"] + ST["SandboxTemplate
(tools image, pool, egress)"] + ST --> SB["Sandbox = Actor"] + end + S --> WP["WorkerPool
gVisor / micro-VM Workers"] + SB --> WP + WP --> OBJ["Snapshot storage
(S3 / GCS / bundled store)"] + WP --> EG["Egress gateway
default-deny"] +``` + +The agent path uses three resources: + +- **Harness**: Sets what runs the agent loop (`kagent`, `claude`, `codex`, or `byo`), which image it uses, which WorkerPool it runs on, and where its snapshots go. +- **AgentTemplate**: Holds the agent's behavior: the system prompt, the ModelConfig, and the tools and skills. +- **Agent**: Pairs one AgentTemplate with one Harness. **It is the only one of the three that reports a status.** + +The sandbox path uses two resources: + +- **SandboxTemplate**: Holds the tools image (pinned by digest), the WorkerPool, the snapshot location, and any `egressPolicyRefs`. It has its own `Ready` condition. +- **Sandbox**: A scratch environment that a person, an application, or an agent creates from a template through the CLI, gRPC, or the kagent MCP server. It has no harness, no model, and no conversation. It reports a `state` and an `operation` through the API, not through `kubectl`. + +For a deeper look at how these pieces fit together, see [Kagent and Agent Substrate: Running AI Agent Sandboxes on Kubernetes](/blog/kagent-agent-substrate-sandboxes). Both paths need a working WorkerPool, snapshot storage, and the egress gateway. Most of the problems in this post come from those three shared pieces. + +## Before you debug: where status lives + +Before you work on any symptom, know where status is reported. The places to check are: + +| Resource | Where its health is reported | +| -------- | ---------------------------- | +| Harness, AgentTemplate | Nowhere on the resource itself. Read the conditions of every **Agent** that references it. | +| Agent | `status.conditions` (`Accepted`, `ResolvedRefs`, `Compatible`, `Ready`), plus `EgressPoliciesApplied`, `status.warnings`, and the revision fields. | +| SandboxTemplate | `status.conditions`: `Ready` (with reason `Preparing`, `Prepared`, or `ActorTemplateRetrying`) and `EgressPoliciesApplied`. | +| Sandbox | `state` and `operation`, from `kagent sandbox get` or `GetSandbox`. | +| Actors, Workers | The controller's `SystemService` gRPC API (`GetSubstrateSummary`, `ListSubstrateActors`, `ListSubstrateWorkers`). | +| Denied egress | The `agentgateway` container log of `atenet-egress` in `ate-system`. | +| Everything else | `kagent-controller` logs, which include one `rpc completed` line per API call, with its `grpc_code`. | + +Keep this condition dump handy. You'll use it more than any other command in this post: + +```bash +kubectl get agent -n kagent \ + -o jsonpath='{range .status.conditions[*]}{.type}{"="}{.status}{" "}{.reason}{": "}{.message}{"\n"}{end}' +``` + +Most of the deeper checks go through the controller's gRPC API, so start a port-forward in a second terminal. The API needs `config.server.grpcReflection=true` for `grpcurl` to discover its methods. + +```bash +kubectl port-forward -n kagent svc/kagent-controller 8083:8083 +``` + +## Rule #1: read the first `False` that isn't `Blocked` + +The four Agent conditions form a pipeline. Each condition is evaluated only when the one before it is `True`. + +| Condition | What it checks | +| --------- | -------------- | +| `Accepted` | That the Agent selects a template and a Harness. kagent always sets it to `True`. | +| `ResolvedRefs` | That the AgentTemplate, Harness, ModelConfig, tool servers, and the Harness's WorkerPool all exist. | +| `Compatible` | That the Harness accepts the resolved configuration. | +| `Ready` | That the golden snapshot of the generated ActorTemplate exists. | + +When one stage fails, kagent sets **every later stage** to `False` with the reason `Blocked`. Only the first failure describes the real problem: + +```console +Accepted=True Accepted: Agent explicitly selects its template and harness +ResolvedRefs=False ReferenceResolutionFailed: resolve ModelConfig "does-not-exist": not found +Compatible=False Blocked: blocked by ResolvedRefs +Ready=False Blocked: blocked by ResolvedRefs +``` + +In this example, the ModelConfig is the only problem. Don't spend time on the two conditions that follow it. + +Here's what the pipeline looks like on a real cluster. The first capture is a healthy Agent, and the second is an Agent whose AgentTemplate names a ModelConfig that doesn't exist: + +![A healthy kagent Agent with Accepted, EgressPoliciesApplied, ResolvedRefs, Compatible, and Ready all True](/images/blog/troubleshoot-agent-substrate-kagent/conditions-healthy.png) + +![A kagent Agent with ResolvedRefs False because a ModelConfig is missing, and Compatible and Ready Blocked](/images/blog/troubleshoot-agent-substrate-kagent/conditions-missing-model.png) + +--- + +## Part 1: Troubleshoot kagent Harness and Agent errors + +### "My Harness looks fine but nothing works" + +A Harness has no status, so a broken Harness and a working one look the same: + +```console +$ kubectl get harness -n kagent +NAME AGE +claude-harness 5m +``` + +You find out whether a Harness works only by reading the conditions of an Agent that uses it. If no Agent references the Harness, the controller never checks it. The same is true of an AgentTemplate. A template that no Agent references is never prepared, and when you try to use it you get this error: + +```console +ERROR: + Code: FailedPrecondition + Message: Agent does not have a ready prepared revision +``` + +In the following capture, the `bad-env` and `crash` Harnesses are both broken. Only the Agent list shows it. + +![kubectl get harness shows no status column, so the broken bad-env and crash Harnesses look the same as working ones, while kubectl get agents shows READY False](/images/blog/troubleshoot-agent-substrate-kagent/harness-no-status.png) + +**Fix:** List which Agents reference which templates and Harnesses, and create an Agent for any template that has none: + +```bash +kubectl get agents -n kagent \ + -o jsonpath='{range .items[*]}{.metadata.name}{" template="}{.spec.template.ref.name}{" harness="}{.spec.harnessRef.name}{"\n"}{end}' +``` + +### `ResolvedRefs=False` with `WorkerPoolNotFound` + +This is the most common failure on a new Harness. `spec.substrate.workerPoolRef.name` must name a WorkerPool **in the same namespace as the Harness**. If you created a Harness in a new namespace, such as `team-a`, and pointed it at `kagent-default`, the reference fails because `kagent-default` exists only in `kagent`. + +```bash +kubectl get workerpools -A +``` + +![Agent with ResolvedRefs False and reason WorkerPoolNotFound because the Harness is in a namespace that has no WorkerPool](/images/blog/troubleshoot-agent-substrate-kagent/conditions-workerpool-not-found.png) + +**Fix:** Point the Harness at a pool that exists in its own namespace, or create one. If you manage the pool yourself instead of through the chart, it must carry **both** of the placement labels `kagent.dev/worker-pool-name` and `kagent.dev/worker-pool-namespace`, with values that match its own name and namespace. + +### `Compatible=False`: the Harness doesn't support what you asked for + +The `claude`, `codex`, and `byo` harnesses each run their own agent loop, so each one supports less than the built-in `kagent` harness. These are the messages you'll see most often: + +| Message (or symptom) | Cause | Fix | +| -------------------- | ----- | --- | +| `Harness runtime "" does not support structured output` | The AgentTemplate requests structured output on a `claude`, `codex`, or `byo` harness. | Use the `kagent` harness, or remove the structured output setting. | +| `Harness env "" conflicts with Claude-owned runtime configuration` | The Harness `spec.env` sets a variable that the Claude adapter reserves, such as `ANTHROPIC_API_KEY` or `CLAUDE_CONFIG_DIR`. | Remove it. Put credentials in the ModelConfig. | +| `Harness env "" conflicts with Codex's compiled configuration` | The same problem on `codex`, with a variable such as `OPENAI_API_KEY`, `CODEX_HOME`, or one of the `AWS_*` credential variables. | Remove it. | +| `runtime environment "" conflicts with gateway trust` | Any harness sets `SSL_CERT_FILE`, `REQUESTS_CA_BUNDLE`, `NODE_EXTRA_CA_CERTS`, or another certificate-trust variable. | Remove it. The egress gateway intercepts TLS, so kagent sets these variables itself. | +| `runtime revision has environment variables; Substrate supports at most 32` | kagent adds its own variables to every revision, and the total, including yours, is over 32. | Remove some `spec.env` entries. | +| A `codex` agent fails every turn with `Codex execution failed` | The ModelConfig doesn't set `openAI.apiFormat: responses`, or the API key isn't entitled to the model. | Set `apiFormat: responses` and check that the key has access to the model. | +| A `codex` agent is rejected for its MCP server | The RemoteMCPServer uses `SSE`. | Codex supports only `STREAMABLE_HTTP`. | +| A Vertex AI or SAP AI Core ModelConfig is rejected | These providers authenticate with a mounted file or an OAuth exchange, which the egress gateway can't inject. | Use a provider that authenticates with a header. For Bedrock, use an `AWS_BEARER_TOKEN_BEDROCK` Secret, not IAM access keys. | + +Here's the reserved-variable case on a real cluster. Setting `SSL_CERT_FILE` on a `kagent` Harness fails at the `Compatible` stage: + +![Agent with Compatible False and reason ActorTemplateInvalid because the Harness sets the reserved SSL_CERT_FILE variable](/images/blog/troubleshoot-agent-substrate-kagent/conditions-reserved-env.png) + +Also check `status.warnings`. A warning doesn't stop an Agent from becoming ready, but it records a choice kagent made for you. The most common one is that the Claude harness binds **every** tool on an MCP server, because Claude doesn't support selecting only some of them: + +```bash +kubectl get agent -n kagent -o jsonpath='{.status.warnings}' +``` + +### `Ready=False` with `ActorTemplateRetrying` + +The references resolved and the configuration is compatible, but Agent Substrate couldn't build the golden snapshot. kagent retries the build after about 15 seconds, 1 minute, and 4 minutes, and then about every 10 minutes indefinitely. The condition message deliberately leaves out the underlying error, because that error can quote your configuration: + +```console +Ready=False ActorTemplateRetrying: golden build failed (GoldenActorCrashed), retry 1 at 2026-11-18T21:05:03Z +``` + +To see the full error, read the controller log: + +```bash +kubectl logs -n kagent deploy/kagent-controller | grep "golden build failed" +``` + +Here's a real example. The Harness runs a `byo` image (BusyBox running `/bin/false`) that exits right away. The condition says only `GoldenActorCrashed`. The controller log shows the cause: the container never answered its readiness probe. + +![Agent Ready False with ActorTemplateRetrying, and the controller log showing the container never answered its readiness probe](/images/blog/troubleshoot-agent-substrate-kagent/actortemplate-retrying.png) + +The usual causes are: + +- **Image pull failures.** The Workers can't pull `workload.image`. If the image is in a private registry, make sure the WorkerPool's ServiceAccount has the pull secrets. The chart adds `imagePullSecrets` only to a ServiceAccount that it creates. +- **A tag without a digest.** The API server rejects `workload.image` unless it's pinned with `@sha256:`. If you see a schema error when you apply the resource, this is the cause. +- **A `byo` image without `workload.command`.** kagent can't infer the entrypoint of an image it didn't build. +- **An image that crashes on startup.** For `byo`, check that your image implements kagent's A2A contract and doesn't exit right away. + +If a configuration fault causes the failure, kagent keeps retrying until you edit the Agent or the Harness. **Waiting won't fix it.** + +### "I edited the AgentTemplate and nothing changed" + +There are two possible causes, and the Agent shows you which one applies: + +```bash +kubectl get agent -n kagent \ + -o jsonpath='{"desired="}{.status.desiredRevision}{" latestSuccessful="}{.status.latestSuccessfulRevision}{"\n"}' +``` + +- **The values differ.** Your edit produced a new revision that isn't ready yet. Read the conditions to find out why. +- **The values match.** This is expected behavior. **A Session runs the revision it was created from for its entire life.** Start a new Session to pick up your edit. The same rule applies when you change a RemoteMCPServer. + +--- + +## Part 2: Troubleshoot WorkerPools, Actors, and timeouts + +### `actor "..." request timed out` + +```console +ERROR: + Code: Internal + Message: actor "ai-01a087c0-1d72-775a-9a32-566acac7b685" request timed out +``` + +This error doesn't tell you its cause. Check the following possibilities in order. + +**1. Is the WorkerPool healthy and large enough?** An undersized pool produces exactly this error, and no component logs a capacity message. + +```bash +kubectl get workerpools -n kagent +``` + +```console +NAME DESIRED REPLICAS READY SANDBOXCONFIG RESOLVED AGE +kagent-default 1 1 1 gvisor-default True 3h +``` + +![kubectl get workerpools with matching DESIRED, REPLICAS, and READY counts, and GetSubstrateSummary showing one Actor in ACTOR_STATE_CRASHED](/images/blog/troubleshoot-agent-substrate-kagent/workerpools.png) + +To read this output: + +- A gap between `DESIRED` and `REPLICAS` means the controller isn't creating Worker pods. +- A gap between `REPLICAS` and `READY` means the pods exist but aren't starting. Check the Worker image and the sandbox class, which are covered later in this post. +- If all three numbers match, compare them with your load. Size the pool for the number of **turns that run at the same time**, not for the number of Sessions. kagent suspends Actors between turns, so an idle Session uses no Worker capacity. Under mild pressure, a pool still serves most requests and only drops the ones that wait too long, so you see intermittent timeouts when concurrency rises. To confirm, watch Agent Substrate's `at_capacity` Worker state and its `no_capacity` placement outcomes. To scale the pool: + +```bash +kubectl scale workerpool kagent-default -n kagent --replicas=4 +``` + +Sandboxes fail differently. When a pool has no ready Workers at all, `kagent sandbox create` fails immediately with a generic `Unavailable` error instead of waiting and timing out. The error doesn't mention capacity either: + +![A WorkerPool scaled to zero Workers, and kagent sandbox create failing with Unavailable: Sandbox operation failed](/images/blog/troubleshoot-agent-substrate-kagent/sandbox-no-workers.png) + +**2. Is the model provider slow or unreachable?** A turn that waits on the model times out the same way. The agent's own log names the provider error. + +**3. Is the Actor stuck?** An Actor in `ACTOR_STATE_RESUMING` or `ACTOR_STATE_CRASHED` never answers: + +```bash +grpcurl -plaintext -d '{"atespace":"kagent"}' \ + localhost:8083 kagent.api.v1.SystemService/ListSubstrateActors \ + | jq '.actors[] | {name: .metadata.name, state: .status.state}' +``` + +For a quick overview of the whole runtime, run `GetSubstrateSummary`. It counts Actors by state for each pool: + +```bash +grpcurl -plaintext -d '{"namespace":"kagent","atespace":"kagent"}' \ + localhost:8083 kagent.api.v1.SystemService/GetSubstrateSummary \ + | jq '{actorCount, workerCount, actorStatusCounts}' +``` + +### Workers never become ready: sandbox class mismatch + +A pool's `sandboxClass`, its `workerImage`, and the cluster's `SandboxConfig` must all name the same class. Each kind of mismatch fails in a different way: + +| What disagrees | What you see | +| -------------- | ------------ | +| The Worker image was built for another class, for example `ateworker-gvisor` in a `microvm` pool | The Workers never register, so `READY` stays below `REPLICAS`. | +| The SandboxConfig is missing | The pool's `Resolved` condition is `False`, with the reason `SandboxConfigNotFound` or `DefaultConfigNotFound`. A default install creates only `gvisor-default`. | +| The ActorTemplate's class doesn't match the pool | `RevisionInvalid` with `unsupported sandbox class ""`, and placement fails with `WorkerPoolNotFound`. | + +```bash +kubectl get sandboxconfigs +kubectl get workerpools -n kagent -o yaml | grep -A5 sandboxClasses +``` + +Two more things to know about sandbox classes: + +- Snapshots **can't move between classes**. If you change the class of a pool that hosts live Actors, those Actors lose their state. +- gVisor nodes download their runtime files from a public Google Cloud Storage URL that the SandboxConfig names. In an air-gapped or egress-restricted cluster, Workers fail until you allow that URL or host your own copy of the files. + +### Sessions suspend but never resume: snapshot storage + +Agent Substrate writes every suspended Actor to object storage. If that storage is broken, the first turn of a Session works and the second one fails. Snapshot storage is configured in two places that must agree: + +1. In the Agent Substrate Helm values: `atelet.storageBackend` in the `substrate` release, and `objectStore` in the `substrate-atelet` release. +2. In each Harness and SandboxTemplate: `spec.substrate.snapshotPolicy.location`. + +If they don't agree, for example when the backend uses your S3 bucket but a Harness still points at `s3://ate-snapshots/...`, Actors suspend and then can't resume. To check, send a message, then read where the snapshot was written: + +```bash +grpcurl -plaintext -d '{"atespace":"kagent"}' \ + localhost:8083 kagent.api.v1.SystemService/ListSubstrateActors \ + | jq '.actors[] | {name: .metadata.name, state: .status.state, snapshotUri: .status.snapshots[-1].durableSnapshot.object.snapshotUri}' +``` + +If snapshots don't get written at all, check the `objectstore-plugin` sidecar on the `atelet` DaemonSet and the `ate-api-server` Deployment. That sidecar is the only container that reads the storage variables: `ATE_STORAGE_BACKEND`, `AWS_REGION`, `AWS_ENDPOINT_URL`, `AWS_S3_USE_PATH_STYLE`, and the credentials. Two mistakes are common: + +- Setting `ATE_STORAGE_BACKEND` directly on the main container, which stops that container from starting. +- Putting S3-compatible endpoint settings in `atelet.extraEnv` instead of `objectStorePlugin.extraEnv`. The `atelet` container doesn't read storage settings, so the change has no effect. + + + +--- + +## Part 3: Troubleshoot SandboxTemplates + +Sandboxes have their own setup, and it fails in its own ways. For background on why kagent's sandboxes are built this way, read [Not All Agent Sandboxes Are Created Equally](/blog/agent-sandboxes-four-axes). + +### The template is stuck in `Preparing` or `ActorTemplateRetrying` + +```bash +kubectl get sandboxtemplate python -n kagent \ + -o jsonpath='{range .status.conditions[?(@.type=="Ready")]}{.status} {.reason} {.message}{end}' +``` + +The healthy result is `True Prepared Sandbox runtime is prepared`. The first preparation can take about a minute while a Worker pulls the image. If the template stays in `ActorTemplateRetrying`, these are the usual causes, from most to least common: + +1. **No guest image is configured.** This is the most common failure for new users. The chart **doesn't ship a default** `config.sandboxes.guestImage`, so no SandboxTemplate becomes ready until you set one. The guest image supplies kagent's process and file service. Your tools image can't replace it. + + ```yaml + config: + sandboxes: + guestImage: ghcr.io/kagent-dev/kagent/sandbox-guest@sha256: + cpu: "1" + memory: 1Gi + defaultTtl: 3600s + maxTtl: 86400s + ``` + + Check the current value with `helm get values kagent -n kagent --all -o json | jq '.config.sandboxes'`. + +2. **The Workers can't pull the tools image.** This happens when the image is in a private registry and the pool's ServiceAccount doesn't have the pull secrets. + +3. **The image reference has no digest.** The API server rejects it with `spec.workload.image in body should match '^[^[:space:]@]+@sha256:[a-f0-9]{64}$'`. For a multi-architecture image, use the digest of the image index: + + ```bash + docker buildx imagetools inspect python:3.13-slim --format '{{json .Manifest.Digest}}' + ``` + + ![kubectl apply rejects a SandboxTemplate whose image uses a tag without a sha256 digest](/images/blog/troubleshoot-agent-substrate-kagent/image-digest-rejected.png) + +To see the full error, use the same command as for Agents: `kubectl logs -n kagent deploy/kagent-controller | grep "golden build failed"`. + +### The template is `Ready`, but the sandbox can't do anything useful + +These problems come from the tools image, not from kagent: + +| Symptom | Cause | +| ------- | ----- | +| Your image's `ENTRYPOINT` or `CMD` never runs | kagent replaces the entrypoint with its guest program. A SandboxTemplate has no startup command, so start processes with `exec` or `start_sandbox_process`. | +| Files you put under `/data` in the image are missing | kagent mounts a durable volume at `/data`, which hides those files. Install tools under `/opt` or `/usr/local` instead. | +| The Sandbox never becomes ready when the image runs as a non-root user | The guest creates `/data/workspace` and `/data/guest-logs`, so the image's user must be able to write to `/data`. | +| `pip install`, `npm install`, or `git clone` fails | Outbound traffic is blocked by default. See [Part 5](#part-5-troubleshoot-egress-policies-the-dns-error-that-isnt-dns). | +| A credential in `env` is rejected as an unknown field | SandboxTemplate `env` accepts only literal values. Inject credentials at the egress gateway with an EgressPolicy instead. | + +### "I edited the template but my Sandbox didn't change" + +This is the same rule that applies to Sessions. Each Sandbox stays on the revision it was created from. An edit to the template affects only Sandboxes that you create afterward. If the new revision fails to prepare, new Sandboxes keep using the last revision that succeeded, so a broken edit doesn't take anything down. It also isn't applied. Read the `Ready` condition to find out why. + +Deleting a template stops new Sandboxes from being created from it. Existing Sandboxes keep running until you delete them or they expire. + +--- + +## Part 4: Troubleshoot kagent Sandboxes + +### `FailedPrecondition: Sandbox is not ready or has expired` + +```console +Error: start process in sandbox 01a1f073-...: command may have started; do not blindly retry: + rpc error: code = FailedPrecondition desc = Sandbox is not ready or has expired +``` + +A Sandbox accepts process and file operations only when `state` is `RUNTIME_STATE_READY` **and** `operation` is `RUNTIME_OPERATION_NONE`. Check both: + +```bash +kagent sandbox get $SANDBOX_ID +``` + +There are three usual causes: + +- **The Sandbox is suspended.** kagent never resumes a Sandbox automatically. Run `kagent sandbox resume $SANDBOX_ID`. +- **The Sandbox expired.** Every Sandbox has a fixed `expires_at`. Running commands doesn't extend it, and neither does a resume. The default lifetime is one hour and the maximum is 24 hours. Copy your results out before the Sandbox expires. +- **A lifecycle operation is still pending.** Each lifecycle call makes one attempt. If that attempt hits a temporary error, the change stays pending, and only **repeating the same call** continues it. `GetSandbox` and `ListSandboxes` only read state and never move pending work forward. + +### Duplicate Sandboxes, `AlreadyExists`, or `FailedPrecondition` on create + +`CreateSandbox` deduplicates requests by `request_id`: + +| Request | Result | +| ------- | ------ | +| Same `request_id` and same input | Returns the same Sandbox. This is the safe way to retry. | +| Same `request_id` with different input | `AlreadyExists`: `request_id was used for different input`. | +| `request_id` of a Sandbox that was deleted or expired | `FailedPrecondition`. A new display name doesn't help. Generate a new ID. | +| New `request_id` | Creates a new Sandbox. If you generate a new ID on every retry, you get a new Sandbox each time. | + +![kagent sandbox create returning the same Sandbox on retry, AlreadyExists for different input, and FailedPrecondition after the Sandbox is deleted](/images/blog/troubleshoot-agent-substrate-kagent/sandbox-request-id.png) + +Agents cause this problem most often. If the system prompt doesn't tell the model to reuse its `request_id`, the model can create a new Sandbox on every attempt and leave each one running until it expires. Name the template in the prompt, tell the model to retry with the same `request_id`, tell it to always call `delete_sandbox`, and set a short `ttl_seconds` so that any Sandbox the model forgets to delete doesn't run for long. + +### "My files and processes are gone after resume" + +This is expected behavior. A suspend saves only `/data`, using a Data-scope snapshot. + +| What | Kept across suspend and resume? | +| ---- | ------------------------------- | +| Files under `/data`, including the default working directory `/data/workspace` | Yes | +| Files anywhere else, such as `/tmp` | No | +| Running processes and their IDs | No. An old process ID returns `process ... not found`. | + +Here's the whole sequence on a real Sandbox. The file in `/data/workspace` survives, the file in `/tmp` doesn't, and a process ID from before the suspend is gone: + +![A Sandbox suspended and resumed: exec fails with FailedPrecondition while suspended, the /data file survives, the /tmp file and the old process are gone](/images/blog/troubleshoot-agent-substrate-kagent/sandbox-suspend-resume.png) + +A suspend also doesn't wait for running work to finish, so a command or file write can be cut off partway through. Suspend a Sandbox only when you can repeat whatever it was running. + +### `kagent sandbox list` is empty, but the agent created Sandboxes + +Each Sandbox belongs to the identity that created it, and a list returns only the caller's own Sandboxes. An agent creates Sandboxes under the identity of **its MCP connection**, not under the identity of the person it's talking to. In the default `insecure` auth mode, the agent and the CLI share one default identity, so you see the agent's Sandboxes. When authentication is on, you don't. A Session share token never grants access to a Sandbox. + +To have an agent create Sandboxes as the user who invoked it, turn on token propagation: + +```yaml +config: + runtimeDefaults: + tokenPropagation: + enabled: true +``` + +This setting forwards the caller's credentials to **every** MCP server that agents on the `kagent` harness call, not only to `kagent-api`. Turn it on only if you trust all of those servers with your users' tokens. + +### The agent has no sandbox tools + +The chart installs a `RemoteMCPServer` named `kagent-api` in the controller's namespace. An AgentTemplate can reference only an MCP server in its **own** namespace, so an agent in another namespace needs its own `RemoteMCPServer` that points at `http://kagent-controller.kagent.svc.cluster.local:8083/mcp`. + +```bash +kubectl get remotemcpserver kagent-api -n kagent +``` + +If the server is accepted and the tools are still missing, check the agent's runtime log. When an MCP server doesn't answer, kagent drops that server's tools for the current execution and logs a warning instead of failing the turn: + +```bash +kubectl logs -n kagent -l ate.dev/worker-pool=kagent-default --tail=-1 | grep "omitting toolset" +``` + +Also check the binding's `mcp.tools` list. A tool that isn't in the list never reaches the model. + +### Sandbox MCP tool calls fail on large files + +The MCP tools pass data through the model's context, so their limits are much smaller than the CLI's or the gRPC API's: + +| Interface | Limit | +| --------- | ----- | +| `write_sandbox_file`, `read_sandbox_outputs` | 1 MiB per call, base64-encoded. A write replaces the whole file and can't append. | +| `read_sandbox_file` (text) | 2,000 lines or 32 KiB per page | +| `kagent sandbox upload`/`download`, gRPC `FileSystemService` | 64 MiB per file, streamed | + +Two other points about MCP tool calls: + +- A failed MCP tool call can return HTTP 200 with `isError: true`. If your client reads only `structuredContent`, it never sees the error. +- Models often produce invalid base64 for `data_base64`. A good agent recovers by running `python3 -c "..."` directly, so don't treat one failed write as a broken tool. + +### gRPC: `exactly one kagent-sandbox-id metadata value is required` + +The process and file services (`ateenv.v1alpha.ProcessService` and `FileSystemService`) use the Agent Substrate guest protocol unchanged. They select the Sandbox from a metadata header, not from a request field: + +```bash +grpcurl -plaintext -H "kagent-sandbox-id: $SANDBOX_ID" \ + -d '{"command":["python3","--version"]}' \ + localhost:8083 ateenv.v1alpha.ProcessService/StartProcess +``` + +`StartProcess` has no request ID. If a start call times out, the process might still have started, so call `GetProcess` before you start it again. + +--- + +## Part 5: Troubleshoot egress policies: the DNS error that isn't DNS + +Agent Substrate blocks all outbound traffic unless a policy allows it. **Inside a Session or a Sandbox, a host that no policy allows doesn't resolve**, so the failure looks like a DNS problem: + +| Client | What a blocked host looks like | +| ------ | ------------------------------ | +| `curl` | `Could not resolve host`, exit code 6 | +| Python | `Name or service not known` | +| BusyBox `wget` | `bad address` | +| Plain HTTP to an IP address | `403 Forbidden` | +| HTTPS to an IP address | TLS handshake failure | + +![Inside a Sandbox, a request to pypi.org fails with Name or service not known, and a plain HTTP request to an IP address gets 403 Forbidden](/images/blog/troubleshoot-agent-substrate-kagent/sandbox-dns-blocked.png) + +Don't start by debugging CoreDNS. Check the policy first. If you prefer the UI to YAML, [the Policies page walkthrough](/blog/kagent-policies-ui-egress-policy-walkthrough) shows how to create and attach an EgressPolicy from the browser. For a worked example of one agent with one narrow policy, see [Build a CVE Agent with kagent and Agent Substrate in a Secure Sandbox](/blog/kagent-cve-agent-substrate-secure-sandbox). + +**Step 1: Did kagent admit the grant?** The `EgressPoliciesApplied` condition is separate from `Ready`. An Agent or SandboxTemplate with a missing policy still reports `Ready=True`, and the UI doesn't show it as failed. + +```bash +kubectl get sandboxtemplate python -n kagent \ + -o jsonpath='{range .status.conditions[?(@.type=="EgressPoliciesApplied")]}{.status} {.reason} {.message}{end}' +``` + +![A SandboxTemplate reporting Ready True while EgressPoliciesApplied is False because the allow-pypi EgressPolicy does not exist yet](/images/blog/troubleshoot-agent-substrate-kagent/sandboxtemplate-ready-egress-missing.png) + +| Reason | Meaning | +| ------ | ------- | +| `EgressPolicyNotFound` | The policy doesn't exist in the **template's or Agent's namespace**, or it's being deleted. | +| `InvalidEgressPolicy` | A policy, a Secret reference, or the `egressPolicyRefs` list is invalid. One invalid name in the list, such as `Node-Deps`, revokes **every** grant in that list. | +| `EgressGrantConflict` | Two policies set different credentials for the same origin and header, a grant adds a credential to an origin that a model or tool already sets one for, or the compiled policy is over 256 rules. | + +**Step 2: What did the gateway actually see?** The gateway logs every request, allowed or denied: + +```bash +kubectl logs -n ate-system deploy/atenet-egress -c agentgateway --tail=100 +``` + +![atenet-egress log showing a 403 with reason Authorization for a request to an IP address, and an allowed 200 request to files.pythonhosted.org](/images/blog/troubleshoot-agent-substrate-kagent/egress-denied-log.png) + + +`reason=Authorization` means a policy denied the request. `http.host` is the host the Actor tried to reach. A `503` is different: it means the gateway couldn't reach its control plane or a credential provider. That's an installation problem, not a denied request. + +**Step 3: Check the problems that catch most people:** + +- **Redirects.** Package registries often serve downloads from a different host. For example, `pypi.org` sends downloads to `files.pythonhosted.org`. Allow both. The following capture shows `pip install` failing with only `pypi.org` allowed, then succeeding after the second origin is added to the same policy, without recreating the Sandbox: + + ![pip install failing to resolve files.pythonhosted.org when only pypi.org is allowed, then succeeding after the origin is added](/images/blog/troubleshoot-agent-substrate-kagent/sandbox-redirect-trap.png) +- **Wildcards.** `https://*.example.com` matches `api.example.com`, but not `example.com` or `a.b.example.com`. A wildcard origin can't carry a credential. +- **Origins.** An origin is a scheme, a host, and a port only. The API server rejects paths, queries, and IP addresses. +- **Credentials.** `EgressPoliciesApplied=True` means the Secret and key exist, not that the value is valid. An empty Secret value produces a `503` from the gateway. A request that doesn't send the placeholder header is forwarded **without** the credential instead of being denied. +- **When changes apply.** Policy changes apply to running and suspended Sandboxes without recreating them. For agents, starting a new Session is still the most reliable way to confirm a change. + +--- + +## Part 6: Collect evidence + +If none of the previous checks explains the problem, collect evidence in this order. + +**Find the failing call in the controller log.** Every API call is logged with its gRPC code: + +```bash +kubectl logs -n kagent deployment/kagent-controller | grep '"rpc completed"' | grep -v '"grpc_code":"OK"' +``` + +![kagent controller log lines for rpc completed calls with grpc_code NotFound, AlreadyExists, and Unavailable](/images/blog/troubleshoot-agent-substrate-kagent/controller-rpc-errors.png) + +To get more detail, raise the log level with `config.logging.level: debug` in your Helm values. + +**After an upgrade, read the previous container.** A failed database migration crash-loops the controller, so the current container's log never shows the error: + +```bash +kubectl logs -n kagent deployment/kagent-controller --previous | grep -i migration +``` + +**Check that Agent Substrate itself is healthy.** If Agent Substrate isn't ready when kagent starts, the kagent controller can crash-loop. Fix `ate-system` first: + +```bash +kubectl get pods -n ate-system +``` + +**Collect a bug report.** A bug report covers kagent's own resources but not the Agent Substrate resources underneath them, so add those yourself: + +```bash +kagent bug-report -n kagent +kubectl get workerpools,sandboxconfigs -n kagent -o yaml > substrate-resources.yaml +``` + + + +## Cheat sheet + +| Symptom | First thing to check | +| ------- | -------------------- | +| Harness or AgentTemplate looks fine but doesn't work | The conditions of an Agent that references it | +| `Agent does not have a ready prepared revision` | No Agent references the template, or `Ready=False` | +| `WorkerPoolNotFound` | The pool must be in the Harness's namespace | +| `Compatible=False` | Reserved env variables, provider support, or structured output on a non-`kagent` harness | +| `ActorTemplateRetrying` | `kubectl logs deploy/kagent-controller \| grep "golden build failed"` | +| Edit has no effect | `desiredRevision` vs. `latestSuccessfulRevision`, then start a new Session or Sandbox | +| `request timed out` | WorkerPool `READY` and capacity, then the model provider, then the Actor state | +| Second turn fails | Snapshot backend vs. `snapshotPolicy.location` | +| SandboxTemplate never ready | `config.sandboxes.guestImage` is set | +| `Sandbox is not ready or has expired` | Suspended (resume it), expired, or a pending operation (repeat the call) | +| Files gone after resume | Only `/data` is kept | +| Can't see the agent's Sandboxes | Identity of the MCP connection, or turn on token propagation | +| `Could not resolve host` inside a sandbox | `EgressPoliciesApplied`, then the `atenet-egress` log | + +## FAQ + +### Why does my kagent Harness show no status? + +A Harness and an AgentTemplate have no `status` field. kagent checks them only when an Agent references them, and it reports the result in that Agent's conditions. Run `kubectl get agent -n kagent -o yaml` and read `status.conditions`. + +### Why does my kagent agent time out with `request timed out`? + +The most common cause is a WorkerPool without enough ready Workers. Agent Substrate doesn't log a capacity error, so the turn waits and then times out. Check `kubectl get workerpools -n kagent`, then check the model provider and the Actor state. + +### Why is my SandboxTemplate never ready? + +Usually because `config.sandboxes.guestImage` isn't set in the kagent Helm values. The chart ships no default guest image. Other causes are a tools image that isn't pinned by digest and an image that the Workers can't pull. + +### Why can't my sandbox reach the internet? + +Agent Substrate blocks all outbound traffic by default, and a blocked host fails to resolve, so it looks like a DNS error. Attach an EgressPolicy that allows the host to the SandboxTemplate's `egressPolicyRefs`, then check the `EgressPoliciesApplied` condition. + +### Which files survive when a kagent Sandbox is suspended? + +Only files under `/data`, which includes the default working directory `/data/workspace`. Files elsewhere and running processes are lost. + +## Wrapping up + +When you troubleshoot Agent Substrate, check the place that reports status instead of the resource you suspect: + +- **Agents:** the Agent's conditions, read from the first `False` that isn't `Blocked`. +- **Sandboxes:** the template's `Ready` condition, and the Sandbox's `state` and `operation`. +- **Network:** the `atenet-egress` gateway log. +- **Capacity:** the WorkerPool counts and the `SystemService` API. + +Learn where those signals live, and you can trace almost any failure to its cause. **Your next step:** bookmark the [cheat sheet](#cheat-sheet), and the next time an agent misbehaves, run the condition dump from [Where status lives](#before-you-debug-where-status-lives) before you change anything. + +For more detail, see these kagent docs: + +- [Debug](https://kagent.dev/docs/kagent/latest/operations/debug/) +- [Tune Agent Substrate](https://kagent.dev/docs/kagent/latest/operations/tune-agent-substrate/) +- [Agent harness](https://kagent.dev/docs/kagent/latest/agents/agent-harness/) +- [Set up sandbox templates](https://kagent.dev/docs/kagent/latest/sandboxes/templates/) +- [About sandboxes](https://kagent.dev/docs/kagent/latest/sandboxes/about/) +- [Egress policies](https://kagent.dev/docs/kagent/latest/agents/egress-policies/) + +Which Agent Substrate failure cost you the most time? Tell us in the [kagent Discord](https://discord.gg/Fu3k65f2k3) or open an issue on [GitHub](https://github.com/kagent-dev/kagent), and we'll add it to this guide. diff --git a/src/mdx-components.tsx b/src/mdx-components.tsx index 2d897d51..2165f568 100644 --- a/src/mdx-components.tsx +++ b/src/mdx-components.tsx @@ -173,7 +173,7 @@ export function useMDXComponents(components: MDXComponents): MDXComponents { ), img: ({ ...props }) => (
- {props.title} + {props.alt {props.title &&
{props.title}
}
),