Kubernetes & Flux
The Helm chart and agent template provide deployment and Flux manifests.
Helm chart
One shared chart, published to an OCI registry and used by every agent app. Its contents include:
- Deployment with liveness (
/healthz), readiness (/readyz) and startup probes, a longterminationGracePeriodSeconds(about 120 s) and a shortpreStopsleep, so the app fails readiness, drains and exits cleanly. - Service and an optional Ingress for webhooks, the API and the UI.
envFromfor one or more Secrets.- Optional CronJobs for the one-shot
run-jobmode. - When sandboxes are enabled: a ServiceAccount and Role for the sandbox pods (the verbs below), and a NetworkPolicy that limits sandbox egress to DNS, the npm registry and GitHub.
- An optional ServiceMonitor for Prometheus.
The values stay small: image, environment, Secrets, ingress, replicas, sandbox and cron jobs.
Ingress client addresses and channel bursts
An ingress does not automatically make forwarded client addresses trustworthy to the app. Configure httpModule({ trustProxy: [...] }) with the known source addresses or CIDRs of your ingress, and configure that ingress to sanitize incoming forwarded headers. Do not trust arbitrary forwarding headers from publicly reachable peers. Without this, the HTTP limiter may group all GitHub deliveries under the ingress IP; even correct forwarding can leave many deliveries sharing GitHub source IPs.
Use httpModule({ channelRateLimits: { github: { max: 3_000, windowMs: 60_000 } } }) for an independent GitHub request bucket, or github: false to disable only that intake limit. Neither changes signature validation or REST protection. These are code options, not chart env variables. See GitHub bursts. MAX_CONCURRENT_RUNS remains per pod/engine; use agent/subscription ceilings over a shared store for fleet-wide execution control.
Graceful shutdown
On SIGTERM the app fails readiness first, stops intake, then calls engine.drain() (which stops the channels, the cron schedule among them, first) within its budget. Runs still in progress are marked interrupted and recovered by another replica or the next pod. The drain deadline must be shorter than the grace period. This part already works in core: see Cancel, Drain & Recovery.
Flux
Each agent repository gets:
- an
OCIRepositoryfor the chart and aHelmReleasewith its values, - an
ImageRepositoryand anImagePolicythat select the newestmain-<sha>-<timestamp>tag (or a semver range), - an image update marker in the
HelmRelease, so Flux commits new tags back to the repository.
Sandboxes in the cluster
@chamvi/sandbox-k8s and the chart's sandbox configuration ship today. Untrusted code runs in one bare pod per workspace (chamvi-ws-<id>):
- root (uid and gid 0) with a writable root filesystem, every capability dropped but
CHOWN,DAC_OVERRIDE,FOWNER,FSETID,SETUID,SETGIDandKILL, seccompRuntimeDefault, no privilege escalation, not privileged; the hardened mode (user: { uid: 1000, gid: 1000 },readOnlyRoot: true) runs non-root on a read-only root without any capability automountServiceAccountToken: false,enableServiceLinks: false, no chamvi Secrets or environment- requests equal to limits for
cpu,memoryandephemeral-storage;/workspacean emptyDir with asizeLimit,/tmpa 1 GiB memory emptyDir (tmpSize), HOME/home/sandboxa disk emptyDir,/cachethe ReadWriteMany claim ofcache: { claimName }shared by every workspace (else an emptyDir per pod) with the package-cache variables pointing into it; pids through the kubelet'spodPidsLimit restartPolicy: NeverandactiveDeadlineSeconds= the workspace's lifetime (limits.maxLifetimeMs, 7 days by default; the container sleeps that long with the image's entrypoint replaced): a workspace pod lives as long as its run (through approval pauses and chamvi restarts) and is found again by label, up to that hard cap, where it ends itself even when no collection runs- labels
app.kubernetes.io/managed-by=chamvi,app.kubernetes.io/component=sandbox,chamvi.dev/run=<runId>,chamvi.dev/workspace=<id>plus yourpodLabels; the expiry as the annotationchamvi.dev/expires-at
Pod Security
The default pods run as root, which the Pod Security level restricted refuses; the capability set above is within baseline. Label the sandbox namespace baseline, never chamvi's own namespace:
kubectl label namespace agents-sandbox pod-security.kubernetes.io/enforce=baselineWhere a cluster allows only restricted, use the hardened mode: non-root with runAsNonRoot and fsGroup, a read-only root, no capability. apt-get then fails; toolchains still install into HOME with mise. A shared cache claim must honour fsGroup (NFS-style volume plugins ignore it) or be world-writable, else the hardened user cannot write it.
A shared cache claim is shared trust: a malicious package one run fetched can sit in another run's cache (npm verifies integrity hashes, pip and Go's build cache less). Leave cache unset, or use one claim per trust level, where runs must not influence each other.
Expired, failed and finished sandbox pods, and the pods of settled runs, are garbage-collected by the provider; each pod carries its chamvi.dev/deployment (DEPLOYMENT), so deployments sharing a namespace leave each other's pods alone. Run the pods in their own namespace and give chamvi's service account this Role there:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: chamvi-sandbox
namespace: agents-sandbox
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["create", "get", "list", "delete"]
- apiGroups: [""]
resources: ["pods/exec"]
verbs: ["get", "create"]
# only with SANDBOX_PERSISTENCE=true
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["create", "get", "list", "delete"]pods/exec needs both get (the exec WebSocket opens with a GET) and create (API servers with the WebSocket-upgrade authorization change). With SANDBOX_PERSISTENCE=true every workspace keeps /workspace and its home on a claim of its own (SANDBOX_STORAGE_CLASS, else the cluster's default class), so the pod of a run waiting for an approval can be deleted and rebuilt on resume (waiting runs).
NetworkPolicy required
Without an enforced NetworkPolicy a workspace pod can reach cluster services, including the chamvi API and its database, and cloud metadata. Keep the chart's sandbox egress policy enabled and use a network plugin that enforces it. If the chart policy is disabled or unavailable, including when deploying sandbox pods without the chart, add an equivalent policy selecting app.kubernetes.io/component=sandbox that restricts egress to the required DNS and public HTTPS destinations and blocks access to the chamvi namespace and 169.254.169.254.
A short-lived, narrowly scoped GitHub token for a sandbox that must push is planned.
Replicas
See Multiple Replicas.