Skip to content
AI Teardown
Go back

Run Amp Coding Agents on Agent Substrate with agentgateway

10 min read

You’ve probably done it: send a prompt to a cloud coding agent, close the laptop, read the diff in the morning. Convenient. Also a black box: the vendor runs the sandbox and decides what it can reach. If your code has to stay on infrastructure you control, or someone in security is going to ask “what did that agent talk to?”, that box is the problem.

Amp’s self-hosted orbs open the box. Amp hands your orb provider spawn, pause and delete jobs, and you decide what an orb actually is.

Agent Substrate is a natural fit. It’s built for agents that are long-lived, bursty, and idle most of the time, like a coding agent waiting for a human to read its diff. Substrate snapshots the idle agent, frees its compute, and brings it back in under a second. And every connection an actor makes leaves through Substrate’s egress gateway, built on agentgateway, so you get a policy point and an audit log for everything each orb reaches.

In this blog post, you’ll learn how to run Amp orbs as Substrate actors on a local kind cluster, pause and resume them from snapshots, and lock down what they can reach. You decide where the agent runs, and you decide what it can reach.

What You’ll Build

Amp orbs on Agent Substrate, with agentgateway on every connection

There are four moving parts:

  • The provider is Amp’s own amp orb provider. It only dials out, to poll ampcode.com for jobs, so nothing in the cluster is exposed. A short dispatch script maps each job onto Substrate.
  • Each orb is a Substrate actor: a gVisor sandbox on a warm worker pod. Pausing snapshots its disk, memory and processes and frees the worker; resuming restores it onto any free worker.
  • orbd, a small supervisor in the orb image, receives Amp’s bootstrap token over HTTP through Substrate’s router and starts amp orb bootstrap with it.
  • atenet-egress is Substrate’s egress gateway, an agentgateway build that identifies each orb by its certificate and applies its egress policy.

Prerequisites

To follow along, you’ll need:

  • Docker with about 15 GB of free disk for the kind node, since snapshots live there.
  • git, curl, kind, kubectl and Go 1.27 or later, which runs Substrate’s installer.
  • An Amp workspace where you can add a Custom Orb Provider, with self-hosted orb providers enabled for the workspace. Without that, Amp says “The selected orb provider is not available”.

If you don’t have self-hosted orbs enabled yet, you can still read along: every output below is from a real run.

Set the versions used throughout:

export SUBSTRATE_VERSION=v0.7.0-alpha1
export ORB_IMAGE=ghcr.io/paurosello/amporbs/orb:main
export PROVIDER_IMAGE=ghcr.io/paurosello/amporbs/provider:main-substrate-$SUBSTRATE_VERSION

Step 1: Install Agent Substrate on Kind

Everything in this post runs on Substrate, so it comes first, starting with its CLI, the kubectl ate plugin:

OS=$(uname -s | tr A-Z a-z); ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
curl -fsSLo kubectl-ate \
  https://github.com/kagent-dev/substrate/releases/download/$SUBSTRATE_VERSION/kubectl-ate-$OS-$ARCH
chmod +x kubectl-ate && sudo mv kubectl-ate /usr/local/bin/

Make sure the plugin comes from the same release as the cluster. An older client fails with unknown service ateapi.Control.

Substrate’s repository has the tooling for a local install. One script creates a kind cluster with the Kubernetes feature gates Substrate needs (pod certificates and cluster trust bundles), and one command installs Substrate on it from the published images:

git clone -q --depth 1 -b $SUBSTRATE_VERSION https://github.com/kagent-dev/substrate && cd substrate
KIND_CLUSTER_NAME=amp-orbs hack/create-kind-cluster.sh
go run ./cmd/ate-setup deploy ate-system --kind --context kind-amp-orbs \
  --atenet-dataplane agentgateway --credential-provider='{"enabled":false}' \
  --image-repo ghcr.io/kagent-dev/substrate --image-tag $SUBSTRATE_VERSION
cd ..
  • --atenet-dataplane agentgateway makes agentgateway carry the traffic into and out of every actor. Step 5 builds on it.
  • --credential-provider is Substrate’s credential injection for outbound requests, which this post doesn’t use.

The cluster takes about 15 seconds and Substrate about a minute. Check that everything came up:

$ kubectl get pods -n ate-system
NAME                              READY   STATUS      RESTARTS   AGE
ate-api-server-7945b677bc-csgz8   2/2     Running     0          35s
ate-api-server-7945b677bc-fzmsm   2/2     Running     0          35s
ate-controller-b5c465d8c-rhfnn    1/1     Running     0          32s
ate-idp-server-868678869c-k429f   1/1     Running     0          34s
ate-idp-server-868678869c-rxpld   1/1     Running     0          34s
atelet-npj6x                      2/2     Running     0          31s
atenet-egress-67bdd68dc8-dcmrb    1/1     Running     0          24s
atenet-router-694c8c8bdf-zlblj    1/1     Running     0          30s
postgres-0                        2/2     Running     0          52s
rustfs-6c4c677cb6-djbjj           1/1     Running     0          28s
rustfs-bucket-init-mcsvj          0/1     Completed   0          27s

ate-api-server is Substrate’s API, with its state in postgres. atelet runs on every node and manages the sandboxes. atenet-router and atenet-egress carry traffic into and out of actors, and rustfs stores snapshots, in a bucket that rustfs-bucket-init creates once.

Step 2: Workers and the Orb Template

With Substrate running, orbs need somewhere to run and something to run as.

Orbs run on a WorkerPool: warm pods, each able to host an actor. An actor takes a whole worker, so replicas is the number of orbs that can run at the same time. Paused orbs take no worker at all. While every worker is busy, a new spawn fails with no worker has room for the actor.

kubectl apply -f - <<EOF
apiVersion: v1
kind: Namespace
metadata:
  name: amp-orbs
  labels:
    ate.dev/api-access: "true"
---
apiVersion: ate.dev/v1
kind: WorkerPool
metadata:
  name: amp-orbs
  namespace: amp-orbs
  labels:
    workload: amp-orb
spec:
  replicas: 2
  sandboxClasses:
  - name: gvisor
  workerImage: ghcr.io/kagent-dev/substrate/ateworker-gvisor:$SUBSTRATE_VERSION
  template:
    resources:
      requests: {cpu: 250m, memory: 1Gi}
      limits: {cpu: "2", memory: 4Gi}
EOF

The ate.dev/api-access label lets pods in the namespace reach Substrate’s API. The limits are what one orb may use; the requests are low so two workers fit on a laptop.

Actors live in an atespace. Create one, and let the provider’s ServiceAccount manage it and nothing else:

kubectl ate create atespace amp-orbs
kubectl ate create access-policy -a amp-orbs -f - <<EOF
metadata:
  name: default
bindings:
- role: editor
  members:
  - user:system:serviceaccount:amp-orbs:amp-orb-provider
EOF

You should see two idle workers:

$ kubectl ate get workers
NAME           POOL       STATE                 ACTORS   CPU(MILLICORES)   MEMORY   POD
c8bf9caf-…     amp-orbs   WORKER_STATE_ACTIVE   0/1000   0/2000            0/4Gi    amp-orbs/amp-orbs-5d84486f97-bfq96
84d1fe92-…     amp-orbs   WORKER_STATE_ACTIVE   0/1000   0/2000            0/4Gi    amp-orbs/amp-orbs-5d84486f97-zb946

Next, the ActorTemplate, which says what an orb is: the image, its resources, and how to snapshot it. When you create one, Substrate boots it once and checkpoints it as the template’s golden snapshot. Every new orb starts from that snapshot instead of booting.

kubectl ate create actor-template -f - <<EOF
metadata:
  atespace: amp-orbs
  name: amp-orb-v1
workerSelector:
  matchLabels:
    workload: amp-orb
containers:
- name: orb
  image: $ORB_IMAGE
  env:
  - {name: ORBD_RUN_AS, value: root}
  securityContext:
    capabilities:
      add: [CHOWN, DAC_OVERRIDE, FOWNER, FSETID, SETGID, SETUID, SETPCAP, NET_RAW, SYS_CHROOT, MKNOD, SETFCAP]
  wakeupProbe:
    httpGet: {path: /readyz, port: 80}
resources:
  limits: {cpuMillicores: "2000", memoryBytes: "4294967296"}
snapshotConfig:
  preferredFidelity: SNAPSHOT_FIDELITY_MEMORY
EOF
  • Substrate runs actor processes as root, so ORBD_RUN_AS and the extra capabilities keep sudo, package installs and chown working in the orb.
  • SNAPSHOT_FIDELITY_MEMORY makes a pause keep processes, not just files.
  • Templates are immutable, so pin ORB_IMAGE by digest outside a demo.

The golden snapshot takes about 22 seconds, most of it pulling the image:

$ kubectl ate get actor-templates -a amp-orbs
ATESPACE   NAME         GOLDEN TAG                             ERROR   AGE
amp-orbs   amp-orb-v1   528c2320-b400-4aa7-b6a9-5a7f32fe58e9           22s

Step 3: Connect the Provider to Amp

With the template ready, the last piece is the provider that turns Amp’s jobs into Substrate calls.

In Amp, open workspace settings, then Custom Orb Providers, and add one. Give each cluster its own provider: the token is the provider’s identity, and Amp hands each job to exactly one provider. Share one token between two clusters and they compete for the same jobs, and a thread lands on whichever cluster claimed it first.

[Screenshot: Custom Orb Providers with the new provider listed, token hidden.]

In the same settings, under Orbs, turn on Orb Saver Mode, so that an orb stays asleep until you actually interact with it. Without it, just opening a thread wakes its orb, and you’ll see spawns you never asked for.

[Screenshot: Orbs settings with Orb Saver Mode on.]

The provider needs its token, permission to verify Substrate’s certificates, and the egress policy it gives each new orb. Start with an open policy that lets the orb reach anything by name; you’ll lock it down in Step 5:

kubectl -n amp-orbs create serviceaccount amp-orb-provider
kubectl -n amp-orbs create secret generic amp-orb-provider \
  --from-literal=AMP_ORB_PROVIDER_TOKEN=<your-provider-token>
kubectl create clusterrole amp-orb-provider --verb=get,list,watch \
  --resource=clustertrustbundles.certificates.k8s.io
kubectl create clusterrolebinding amp-orb-provider --clusterrole=amp-orb-provider \
  --serviceaccount=amp-orbs:amp-orb-provider

cat > egress-open.yaml <<EOF
rules:
- tlsPassthrough:
    hostnames: ["*"]
    ports: {all: {}}
- http:
    hostnames: ["*"]
    ports: {numbers: [80]}
EOF
kubectl -n amp-orbs create configmap amp-orb-provider --from-file=egress-policy.yaml=egress-open.yaml

Then deploy the provider. It authenticates to Substrate with a projected ServiceAccount token, so there’s no other credential to manage:

kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
  name: amp-orb-provider
  namespace: amp-orbs
spec:
  replicas: 1
  strategy: {type: Recreate}
  selector:
    matchLabels: {app: amp-orb-provider}
  template:
    metadata:
      labels: {app: amp-orb-provider}
    spec:
      serviceAccountName: amp-orb-provider
      containers:
      - name: provider
        image: $PROVIDER_IMAGE
        env:
        - {name: ORB_TEMPLATE, value: amp-orb-v1}
        - {name: ATE_ENDPOINT, value: "dns:///api.ate-system.svc:443"}
        - {name: ATE_TOKEN_FILE, value: /var/run/secrets/ate/token}
        envFrom:
        - secretRef: {name: amp-orb-provider}
        volumeMounts:
        - {name: config, mountPath: /etc/amporbs}
        - {name: ate-token, mountPath: /var/run/secrets/ate}
      volumes:
      - name: config
        configMap: {name: amp-orb-provider}
      - name: ate-token
        projected:
          sources:
          - serviceAccountToken: {audience: api.ate-system.svc, path: token}
EOF

You’ll see the provider register with Amp:

$ kubectl -n amp-orbs logs deploy/amp-orb-provider
info Orb provider started {"spawnerID":"3eb61292-…","spawnerVersion":"0.0.1793104576-gc52692"}

Step 4: Start Your First Orb

Now for the fun part. In ampcode.com, start a new thread and pick Orb, then Self-Hosted, then your provider.

[Screenshot: thread picker with Self-Hosted and the provider.]

Amp sends a spawn, and three seconds later the thread is running on your cluster:

$ kubectl -n amp-orbs logs deploy/amp-orb-provider -f
14:36:31 info Claimed job {"op":"spawn","sandboxId":"amp-01a17dca-…"}
[dispatch spawn] creating actor amp-01a17dca-… from template amp-orb-v1
[dispatch spawn] orbd: started
14:36:34 info Completed job {"op":"spawn","durationMs":2980}

[Screenshot: the thread running on the self-hosted orb.]

A second thread a few minutes later starts from the same golden snapshot, and this time nothing has to be pulled:

14:41:32 info Claimed job {"op":"spawn","sandboxId":"amp-01a17dcf-…"}
[dispatch spawn] creating actor amp-01a17dcf-… from template amp-orb-v1
[dispatch spawn] orbd: started
14:41:32 info Completed job {"op":"spawn","durationMs":657}

Amp pauses an orb after five minutes of inactivity. The provider suspends the actor synchronously, so the pause only completes once the snapshot is stored. When you send the next message, Amp spawns the orb again, which on Substrate is a resume:

15:00:46 info Claimed job {"op":"pause","sandboxId":"amp-01a17dca-…"}
[dispatch pause] suspending amp-01a17dca-… (ACTOR_STATE_RUNNING)
15:00:47 info Completed job {"op":"pause","durationMs":993}

15:04:09 info Claimed job {"op":"spawn","sandboxId":"amp-01a17dca-…"}
[dispatch spawn] actor amp-01a17dca-… is ACTOR_STATE_SUSPENDED
[dispatch spawn] orbd: started
15:04:09 info Completed job {"op":"spawn","durationMs":723}

While it was paused, the orb had no worker:

$ kubectl ate get actors -a amp-orbs
ATESPACE   NAME             TEMPLATE              STATE                   WORKER POD
amp-orbs   amp-01a17dca-…   amp-orbs/amp-orb-v1   ACTOR_STATE_SUSPENDED   <none>
amp-orbs   amp-01a17dcf-…   amp-orbs/amp-orb-v1   ACTOR_STATE_RUNNING     amp-orbs/amp-orbs-5d84486f97-zb946

An orb's lifecycle on Substrate: spawn from the golden snapshot, pause to a snapshot, resume

Each Amp job is one Substrate transition. A running orb takes a worker; a suspended one is a snapshot in RustFS and takes none. The times are from the run above.

Step Time
First spawn, from the golden snapshot 3.0 s
Second orb from the same template 657 ms
Pause: memory snapshot stored, worker freed 993 ms
Resume from the orb’s own snapshot 723 ms (the restore itself: 215 ms)

A paused orb costs storage, not compute, so the pool’s two workers serve however many threads are actually busy. And because the snapshot includes memory, whatever the agent left running, a dev server or a tmux session, is still running when the thread resumes. No “can you restart the dev server” at the top of every resumed thread.

Step 5: Lock Down What the Orb Can Reach

The orb runs on your infrastructure. Now you control what it talks to.

In Substrate, every TCP connection an actor makes, except DNS, goes through a tunnel to the egress gateway, over mTLS with a certificate that names the actor. That gateway is agentgateway. It denies by default, applies the actor’s egress policy, and logs every connection with the actor’s identity:

$ kubectl -n ate-system logs deploy/atenet-egress | grep 'info.*request'
info request endpoint=github.com:443 tls.sni=github.com protocol=tcp
     ate.actor.name=amp-01a17dca-85d7-75d2-bc3d-a3fd1125c268 ate.atespace=amp-orbs duration=578ms

So what matters is the policy. The open one from Step 3 uses TLS passthrough rather than interception, which keeps the orb’s WebSocket connections to Amp working and needs no man-in-the-middle CA inside the orb.

To see the policy in action, ask the agent in a thread to reach GitHub, PyPI and npm:

Run each of these in the shell and show me the raw output, without fixing anything:
git ls-remote https://github.com/agentgateway/agentgateway HEAD
curl -sS -o /dev/null -w 'pypi.org %{http_code}\n' https://pypi.org/simple/
npm view left-pad version

With the open policy, all three go out.

Now a locked policy that allows GitHub and denies everything else, PyPI and npm included. The orb also needs Amp itself: ampcode.com for the thread and onamp.dev, which threads also connect to (hostnames like t-…-p28853.onamp.dev).

cat > egress-locked.yaml <<EOF
rules:
- tlsPassthrough:
    hostnames: [ampcode.com, "*.ampcode.com", "*.onamp.dev", github.com, "*.github.com", "*.githubusercontent.com"]
    ports: {numbers: [443]}
EOF

To let the agent install packages later, add the registries it needs, such as pypi.org, files.pythonhosted.org or registry.npmjs.org. apt is the one to remember: Ubuntu’s mirrors are plain HTTP, so it needs an http rule on port 80 for archive.ubuntu.com and security.ubuntu.com (on arm64, ports.ubuntu.com), which this policy leaves out.

You can apply the policy to a running orb. An update has to carry the stored policy’s metadata, so read it back and swap the rules:

ORB=amp-01a17dca-85d7-75d2-bc3d-a3fd1125c268
{ kubectl ate get egress-policy $ORB -a amp-orbs -o yaml | sed '/^rules:/,$d'; cat egress-locked.yaml; } > update.yaml
kubectl ate update egress-policy $ORB -a amp-orbs -f update.yaml

It takes effect within seconds, and the orb keeps running and stays connected to its thread. Here’s the same thread running the same three commands, before and after:

Command Open policy Locked policy
git ls-remote on GitHub works works
curl https://pypi.org/simple/ 200 Could not resolve host
npm view left-pad version 1.3.0 fails: registry.npmjs.org doesn’t resolve

[Screenshot: the two outputs side by side in the thread.]

PyPI and npm never got as far as a connection. The actor’s DNS relay only resolves names its policy covers, so after the change only GitHub reached agentgateway:

15:07:25 info  request endpoint=github.com:443 tls.sni=github.com ate.actor.name=amp-01a17dca-…

That’s two layers working together. The DNS relay stops names outside the policy, and agentgateway holds anything that does connect to the same policy, logging every allowed connection per orb. That’s your answer to “what did that agent talk to?”

One egress policy, enforced twice: at the orb's DNS relay and at agentgateway

The orb’s policy is enforced twice. Names outside it never resolve, so PyPI and npm stop at the DNS relay. What does connect is matched on its TLS SNI at agentgateway and logged with the orb’s identity.

One caveat: the DNS relay doesn’t log the names it refuses, so the gateway log is the record of what each orb reached, not of what it tried. For the attempts, you have the orb’s own output.

To give every new orb the locked policy, swap it into the provider’s ConfigMap:

kubectl -n amp-orbs create configmap amp-orb-provider --from-file=egress-policy.yaml=egress-locked.yaml \
  --dry-run=client -o yaml | kubectl apply -f -

Wrapping Up

A coding agent is a lot easier to say yes to when it runs where the code lives and someone can say what it did. With Amp’s self-hosted orbs on Agent Substrate, each thread runs in a sandbox on your own cluster, sits as a snapshot instead of an idle pod, and comes back in under a second. Every connection it makes goes through agentgateway, under a policy you set and with a log you own. The laptop-closing move still works. The difference is where the agent is while you’re gone.

On a real cluster, only the Substrate install changes (Helm charts instead of the kind tooling). On a three-node GKE cluster, the first spawn took 8.6 s while the node fetched the golden snapshot, and the resume that followed took under half a second.

Model traffic is next: Amp’s Model Routing settings accept a custom endpoint, and pointing it at agentgateway’s LLM gateway would put model calls under the same kind of policy. And nothing here is specific to Amp beyond the dispatch script.

If you take one thing from this post: start with the open policy, run a few real threads, and read the gateway log. The locked policy writes itself from what you see there.

When you’re done, delete the provider in Amp’s settings, then the cluster, the Substrate checkout and the plugin:

kind delete cluster --name amp-orbs
rm -rf substrate && sudo rm /usr/local/bin/kubectl-ate

Learn More



Previous Post
A Presidio PII guardrail for agentgateway