Skip to content

feat(orchestrator): run the daemon in an agent-sandbox Sandbox with runtime: Sandbox - #301

Merged
edenreich merged 2 commits into
mainfrom
feat/orchestrator-sandbox-runtime
Oct 31, 2026
Merged

edenreich merged 2 commits into
mainfrom
feat/orchestrator-sandbox-runtime

Conversation

@edenreich

@edenreich edenreich commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

spec.runtime: Sandbox runs the Orchestrator's daemon in an agent-sandbox Sandbox (agents.x-k8s.io/v1beta1) instead of a Deployment. The Sandbox is a stable pod with a workspace volume (/workspace) and a state volume (~/.infer/projects) that outlive a suspension. The infer CLI will create one per teleported session instead of managing Sandboxes itself.

The runtime follows agent-sandbox v1.0.8's API docs, KEPs and threat model. A review against them reworked the first version (see the second commit).

Closes #298

Changes

  • API
    • spec.runtime: Deployment|Sandbox, default Deployment. It is fixed at creation, because switching away from a Sandbox would delete its volumes.
    • spec.sandbox:
      • storage, fixed at creation
      • operatingMode
      • shutdownTime
      • retention
      • runtimeClassName
    • A CEL rule rejects spec.sandbox without runtime: Sandbox.
    • status.podName, and a RUNTIME print column.
  • Sandbox runtime (internal/controller/orchestrator_sandbox.go)
    • It renders the daemon's pod, shared with the Deployment runtime, into a Sandbox owned by the Orchestrator. The Sandbox gets the Orchestrator's labels, both volume claims and failedPodPolicy: Recreate.
    • No Kubernetes API access. The pod runs with automountServiceAccountToken: false, following the threat model's rule that pods get no API access unless explicitly authorized.
    • Idle parking. The daemon idles out by exiting 0 (INFER_DAEMON_IDLE_EXIT). The operator sees Finished=True with reason PodSucceeded, sets the Orchestrator's spec.sandbox.operatingMode: Suspended itself, and a client resumes the daemon by setting Running. A daemon that leaves agents-done=true as its termination message starts spec.sandbox.retention.
    • Hardened pod.
      • uid 1000, runAsNonRoot, no privilege escalation, all capabilities dropped, RuntimeDefault seccomp.
      • runtimeClassName selects gVisor or Kata.
    • Template rollout. agent-sandbox applies a changed pod template only to the pod it creates next. A changed template (its hash is recorded on the Sandbox) therefore cycles the running pod through Suspended, and a resume waits for the suspension to complete.
    • Pod exits. Failed pods are left to failedPodPolicy: Recreate and its backoff (KEP-729). Succeeded pods stay terminal and mean "idle".
    • Expiry.
      • The Sandbox gets the earlier of shutdownTime and the retention deadline, with shutdownPolicy: Retain.
      • The Orchestrator, and everything it owns, is deleted once the Sandbox reports Ready=False with reason SandboxExpired.
      • A shutdownTime that already passed deletes it before the spec is validated.
    • Readiness.
      • Ready comes from the Sandbox's conditions, and a condition only counts for the Sandbox's current generation.
      • The reasons are SandboxReady, SandboxNotReady (with the Sandbox's own reason, such as ImagePullBackOff), SandboxSuspended and SandboxCRDMissing.
      • status.podName names the pod once it is ready.
  • agent-sandbox stays optional. The controller checks for its CRD through the RESTMapper at startup and watches Sandboxes only when it is there. Without it the operator runs as before, and a Sandbox Orchestrator gets Ready=False with reason SandboxCRDMissing. A RESTMapper error other than a missing kind fails the setup instead of turning the runtime off.
  • The Sandbox is driven as an unstructured object, so there is no agent-sandbox Go dependency. Reading the idle daemon's pod goes through the uncached API reader, so the operator never caches pods.
  • RBAC: agents.x-k8s.io sandboxes, and get on pods. install.yaml is regenerated.
  • Channels fix (from feat(orchestrator): run the full infer daemon with optional channels and the AG-UI binding #300): the controller enabled the channels whenever spec.channels was set, even with no channel enabled, which infer daemon refuses with exit 1. Channels now turn on, and count as something to run, only while a channel is enabled.
  • Tooling:
    • AGENT_SANDBOX_VERSION: v1.0.8.
    • task fetch-agent-sandbox-crds installs that CRD in envtest.
    • task agent-sandbox:install, which task cluster:create now runs for the e2e cluster.
  • Docs:
    • A README section covering the lifecycle and the threat model, with a NetworkPolicy example. The operator creates no NetworkPolicy, because the daemon reaches in-cluster gateways, MCPs and A2A agents.
    • A prerequisites entry and a sample.

Contract for the infer CLI

  • Idle exit: the daemon idles out by exiting 0, after writing agents-done=true or agents-done=false to /dev/termination-log.
  • Resume: a client resumes a parked daemon by setting spec.sandbox.operatingMode: Running.

Where this differs from #298

  • No pod ServiceAccount, Role or RoleBinding. Giving the pod a token that can patch its Orchestrator would let LLM-driven code in it change spec.image, spec.env or spec.runtime. The daemon signals idleness by exiting instead.
  • No shutdownPolicy field. The operator always passes Retain to the Sandbox and deletes the Orchestrator on SandboxExpired, so an expired Sandbox is never recreated with empty volumes.
  • No agent-sandbox Go dependency.

Test plan

  • task test (envtest). 23 sandbox specs cover:
    • the rendered Sandbox: labels, volumes, no token, the hardened security context, runtimeClassName
    • storage sizing and its immutability
    • readiness for the current generation, and the Sandbox's own not-ready reason
    • the template rollout through Suspended
    • suspend, then resume once the suspension completed
    • idle parking with retention, and the resume that clears it
    • expiry through SandboxExpired, and an overdue shutdownTime
    • the missing CRD
    • spec.runtime immutability and the CEL rules
    • rollout and shutdown-time tables
    • the channels fix
  • task fmt, task vet, and task generate manifests leave the tree clean
  • e2e on a local k3d cluster with agent-sandbox v1.0.8, three specs:
    • create, then Ready
    • a file written to /workspace survives suspend and resume
    • expiry deletes the Orchestrator, and garbage collection removes the Sandbox
    • the daemon of cli:0.239.0-rc.9 idles out with exit 0, the operator parks the Orchestrator, and setting Running resumes it
    • the existing Telegram Orchestrator spec
  • The full task test:e2e (CI)

The idle e2e spec pins cli:0.239.0-rc.9, the first CLI with INFER_DAEMON_IDLE_EXIT. It moves to cli:latest once 0.239.0 is released.

task lint reports one finding that main has too: the deprecated Requeue at internal/controller/gpu_controller.go:109.

…untime: Sandbox

spec.runtime: Sandbox runs the Orchestrator's daemon in an agent-sandbox
Sandbox (agents.x-k8s.io/v1beta1) instead of a Deployment: a stable pod
with a workspace volume at /workspace and a state volume at
~/.infer/projects that outlive a suspension.

- spec.sandbox.operatingMode suspends and resumes the Sandbox. A pod that
  finished is cycled through Suspended, and a suspension completes before
  a resume, so a fresh pod reattaches the volumes.
- spec.sandbox.shutdownTime deletes the Orchestrator once it passes, with
  the Sandbox, the volumes and everything else it owns.
- spec.sandbox.storage sizes both volumes when the Sandbox is created.
- The pod runs as <name>-daemon, a ServiceAccount whose Role may only get
  and patch its own Orchestrator, so the daemon can suspend itself. It
  finds the Orchestrator through INFER_DAEMON_KUBERNETES_ORCHESTRATOR and
  INFER_DAEMON_KUBERNETES_NAMESPACE.
- status.podName names the Sandbox's pod once it is ready.
- Switching the runtime replaces the workload the other runtime left.

agent-sandbox stays optional. The controller detects the Sandbox CRD
through the RESTMapper at startup and only watches Sandboxes when it is
there. Without it the operator runs as before, and a Sandbox Orchestrator
gets Ready=False with reason SandboxCRDMissing.

The Sandbox is driven as an unstructured object, so the operator takes no
agent-sandbox Go dependency. envtest installs the pinned v1.0.8 CRD, and
task cluster:create installs agent-sandbox for the e2e suite.

Closes #298
@edenreich
edenreich requested a review from a team as a code owner October 31, 2026 15:10
…in the Sandbox runtime

A review against agent-sandbox v1.0.8's API docs, KEPs and threat model
found the Sandbox runtime deviating from them.

- The pod has no Kubernetes API access (automountServiceAccountToken:
  false), so the per-Orchestrator ServiceAccount, Role and RoleBinding
  are gone. The daemon idles out by exiting 0, and the operator parks the
  Orchestrator itself by setting spec.sandbox.operatingMode: Suspended.
  A daemon that leaves agents-done=true as its termination message starts
  the new spec.sandbox.retention.
- The pod runs as uid 1000 with runAsNonRoot, no privilege escalation, no
  capabilities and the RuntimeDefault seccomp profile, and the new
  spec.sandbox.runtimeClassName runs it under gVisor or Kata.
- agent-sandbox applies a new pod template only to the next pod, so a
  template change now cycles the running pod through Suspended.
- Failed pods are left to failedPodPolicy: Recreate and its backoff.
  Succeeded pods stay terminal, as upstream intends.
- spec.sandbox.shutdownTime is passed to the Sandbox with shutdownPolicy
  Retain, and the Orchestrator is deleted once the Sandbox reports
  SandboxExpired. Expiry is checked before the spec is validated.
- Conditions only count for the Sandbox's current generation, and a
  Sandbox that is not ready passes on its own reason.
- spec.runtime and spec.sandbox.storage are fixed at creation, because a
  switch would drop the Sandbox's volumes. The workload swap is gone.
- A RESTMapper error other than a missing kind fails the setup instead of
  turning the runtime off.

The controller also enabled the channels whenever spec.channels was set,
even with no channel enabled, which `infer daemon` refuses. Channels now
count as something to run only while a channel is enabled.
@inference-gateway-maintainer inference-gateway-maintainer Bot moved this to Todo in 2026 Oct 31, 2026
@edenreich
edenreich merged commit 63386e2 into main Oct 31, 2026
1 check passed
@edenreich
edenreich deleted the feat/orchestrator-sandbox-runtime branch October 31, 2026 15:54
inference-gateway-releaser Bot added a commit that referenced this pull request Oct 31, 2026
## [0.28.0](v0.27.1...v0.28.0) (2026-10-31)

### ✨ Features

* **orchestrator:** run the daemon in an agent-sandbox Sandbox with runtime: Sandbox ([#301](#301)) ([63386e2](63386e2)), closes [#298](#298)
* **orchestrator:** run the full infer daemon with optional channels and the AG-UI binding ([#300](#300)) ([fa7d927](fa7d927)), closes [#297](#297)

### 🐛 Bug Fixes

* **orchestrator:** run infer daemon instead of the removed channels-manager ([#299](#299)) ([62a6af7](62a6af7)), closes [#296](#296), references [inference-gateway/cli#1051](inference-gateway/cli#1051)

### 👷 CI

* **deps:** bump actions/setup-node ([#288](#288)) ([d98dcb2](d98dcb2))
* **deps:** bump docker/login-action ([#293](#293)) ([5f0cef1](5f0cef1))
* **deps:** bump github.com/onsi/ginkgo/v2 ([#289](#289)) ([03684df](03684df))
* **deps:** bump rancher/k3s ([#283](#283)) ([d58b0db](d58b0db))
* **deps:** bump sigs.k8s.io/controller-runtime ([#284](#284)) ([4dc8bc9](4dc8bc9))
* **deps:** bump sigs.k8s.io/gateway-api ([#287](#287)) ([262ff14](262ff14))
* **deps:** bump the github-actions group with 2 updates ([#290](#290)) ([cf4c07b](cf4c07b))
* **release:** label issues and PRs shipped in an rc with rc ([#295](#295)) ([25cac50](25cac50))

### 🔧 Miscellaneous

* **deps:** bump claude-code 2.1.285 -> 2.1.289 ([#285](#285)) ([5e36bc7](5e36bc7))
* **deps:** bump claude-code 2.1.289 -> 2.1.296 ([#291](#291)) ([eb53de2](eb53de2))
* **deps:** bump claude-code 2.1.296 -> 2.1.308 ([#294](#294)) ([025a54a](025a54a))
* **deps:** bump infer CLI v0.221.1 -> v0.226.0 ([#286](#286)) ([505d489](505d489))
* **deps:** bump infer CLI v0.226.0 -> v0.231.1 ([#292](#292)) ([490b5af](490b5af))
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.28.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Oct 31, 2026
@edenreich edenreich moved this from Todo to Done in 2026 Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[FEATURE] Sandbox runtime for the Orchestrator (agent-sandbox)

1 participant