agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

Feat/kubernetes sandbox env injection

Open Buktal opened this issue 5 months ago • 1 comments

Summary

Adds environment(Map<String, String>) support to KubernetesFilesystemSpec, bringing it to parity with DockerFilesystemSpec. Env vars are injected into the K8s Pod container spec at creation time via Fabric8 ContainerBuilder.addAllToEnv().

Fixes / Relates to: #


Description

Background & Purpose

DockerFilesystemSpec supports per-call environment variable injection via .environment(Map), but KubernetesFilesystemSpec has no equivalent. This blocks use cases where per-user secrets (e.g. an API key for a CLI tool pre-installed in the container image) need to be passed into the sandbox Pod without being written to the workspace filesystem — writing to workspace would cause the secret to land in JdbcSnapshotSpec / agent_sandbox_snapshots.

Changes Made

  • KubernetesSandboxClientOptions: add environment field (defaults to empty map) with defensive-copy setter and unmodifiable-view getter
  • KubernetesFilesystemSpec: add fluent environment(Map<String, String>) builder method
  • KubernetesSandboxClient: include environment in merge() (call-level keys override spec-level; non-overridden spec-level keys are preserved) and copy()
  • Fabric8KubernetesPodRuntime.createPod(): apply env map via ContainerBuilder.addAllToEnv() (additive, safe for future env var additions)
  • KubernetesSandboxClientOptionsTest: 8 unit tests covering options defensive copy, null-safety, unmodifiable getter, and all merge() semantics

How to Test

  1. Configure a KubernetesFilesystemSpec with .environment(Map.of("MY_VAR", "hello")) and run HarnessAgent against a real or mock K8s cluster
  2. Inside the sandbox, run execute_shell_command("echo $MY_VAR") and verify the output is hello
  3. Run the unit tests: mvn test -pl agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-kubernetes

Checklist

  • [x] Code has been formatted according to project guidelines (Spotless applied)
  • [x] All automated tests are passing (KubernetesSandboxClientOptionsTest, KubernetesSandboxStateSerdeTest)
  • [x] Documentation / inline comments have been updated accordingly
  • [x] Code is ready for review

Buktal avatar Jun 11 '26 11:06 Buktal

Codecov Report

:x: Patch coverage is 38.09524% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...andbox/kubernetes/Fabric8KubernetesPodRuntime.java 0.00% 10 Missing :warning:
...s/sandbox/kubernetes/KubernetesFilesystemSpec.java 0.00% 2 Missing :warning:
...ns/sandbox/kubernetes/KubernetesSandboxClient.java 80.00% 0 Missing and 1 partial :warning:

:loudspeaker: Thoughts on this report? Let us know!

codecov[bot] avatar Jun 11 '26 11:06 codecov[bot]