Skip to content

refactor(sandbox-kubernetes): rebase the Kubernetes sandbox store on agent-sandbox - #2308

Merged
oss-maintainer merged 1 commit into
agentscope-ai:mainfrom
chickenlj:agent-sandbox
Jul 21, 2026
Merged

refactor(sandbox-kubernetes): rebase the Kubernetes sandbox store on agent-sandbox#2308
oss-maintainer merged 1 commit into
agentscope-ai:mainfrom
chickenlj:agent-sandbox

Conversation

@chickenlj

Copy link
Copy Markdown
Collaborator

Motivation

The Kubernetes sandbox store used to manage raw pods directly through fabric8 (Fabric8KubernetesPodRuntime), which meant we owned pod scheduling, readiness, cleanup, and connectivity ourselves — and offered none of the warm-start or lifecycle semantics that agentic workloads actually need.
agent-sandbox (a Kubernetes SIG project) solves exactly this problem at the cluster level: sandboxes are CRDs (Sandbox / SandboxClaim / SandboxTemplate / SandboxWarmPool) reconciled by a controller, with warm pools for sub-second acquisition, PVC-backed workspace persistence, and lifecycle policies (TTL, hibernation) built in. This PR rebases the Kubernetes store on it: the cluster owns the sandbox fleet, and the Java side merely claims an instance and talks to its runtime HTTP API.

What's in this PR

A standalone Java client SDK for agent-sandbox

io.agentscope.extensions.sandbox.kubernetes.client is a self-contained client mirroring the official Python SDK (agentic-sandbox-client), usable independently of the Harness:

  • SandboxClient / Sandbox for lifecycle: create (claim from a warm pool), get, list, delete, terminate.
  • CommandExecutor (POST /execute) and Filesystem (/upload, /download, /list, /exists) for the data plane, with client-side path sanitization.
  • Four pluggable connection strategies — direct URL, Gateway API, port-forward local tunnel (the development default), and in-cluster pod IP — selected via typed connection configs.
    The old fabric8 pod runtime and its tests are deleted; the Harness-facing KubernetesSandboxClient / KubernetesSandbox now delegate to the SDK while keeping Options / Spec / State serialization wire-compatible.

Workspace archives now travel over the file API

Persist/hydrate used to shell out tar | base64 and embed the entire archive in an /execute command line — which breaks past Linux's ~128 KiB per-argument limit and inflates memory. Snapshot tarballs are now transferred through the runtime's /upload / /download endpoints as raw bytes. The base directory is configurable (fileApiBaseDir, default /workspace); leaving it blank falls back to the exec path, whose base64 decoding also got fixed to tolerate GNU base64 line wrapping.

SandboxFileTransfer: an opt-in native transfer capability

The Harness Sandbox SPI deliberately has a single data-plane entry point (exec), because tool semantics like edit_file and grep_files can only be expressed as shell against a standard toolchain. But pure byte transfer doesn't need a shell. This PR adds an optional SandboxFileTransfer interface; SandboxBackedFilesystem prefers it when the backend implements it and the path qualifies, and falls back to exec+base64 otherwise. The Kubernetes store implements it by mapping workspace-absolute paths onto the file API, so write_file and file downloads are no longer bound by command-line length limits. Other stores are unaffected.

Documentation: the runtime image contract, and where state actually lives

Two new sections in the sandbox docs (zh + en), prompted by questions this migration surfaced:

  • Runtime image contract — sandbox images are user-supplied, but not arbitrary: every file tool is implemented as POSIX shell against the image's toolchain. The contract spells out the baseline (POSIX sh, coreutils, GNU stat -c, tar/base64, python3) with a one-line conformance check, plus the agent-sandbox-specific HTTP API requirements (/execute must have shell semantics; the file API root must match the workspace root). Notably, the upstream example runtime does not conform (it shlex.splits commands without a shell and roots its file API at /app) and is documented as endpoint-shape reference only.
  • Kubernetes state persistence — with agent-sandbox, workspace durability is primarily the PVC's job (declared in SandboxTemplate.volumeClaimTemplates and mounted at the workspace root); the Harness SandboxState + snapshot layer remains the identity pointer for resume and the cold-recovery fallback once a claim expires. The docs cover the split of responsibilities, a reference template, and the snapshot-vs-PVC trade-off.
    The Kubernetes section of the filesystem docs was rewritten to match the actual KubernetesFilesystemSpec API (warm pool + namespace + connection options), replacing an example that referenced setters from the pre-agent-sandbox era.

Testing

  • New unit tests for the client SDK (CommandExecutorTest, FilesystemTest, CreateSandboxOptionsTest) and the adapter (KubernetesSandboxTest: exec wrapping, file-API vs exec transfer paths, self-exclusion of temp archives, wrapped-base64 decoding).
  • SandboxBackedFilesystemTest extended to cover native-transfer dispatch, per-path fallback, and failure reporting.
  • agentscope-harness (638 tests) and agentscope-extensions-sandbox-kubernetes (23 tests) both green.

Notes for reviewers

  • The runtime HTTP API contract is stricter than the upstream reference runtime; a conformant image (shell-backed /execute, file API rooted at /workspace) is a deployment prerequisite and is documented as such.
  • This commit also carries two unrelated docs changes that rode along from the same working tree: the homepage adoption-stats redesign (intro.md + homepage.css) and a Chinese blog post (agentscope-v2-explained.md). Happy to split them out if preferred.

@oss-maintainer
oss-maintainer merged commit a20c01c into agentscope-ai:main Jul 21, 2026
5 of 6 checks passed
@chickenlj
chickenlj deleted the agent-sandbox branch July 22, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants