Feat/kubernetes sandbox env injection
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
- Configure a KubernetesFilesystemSpec with .environment(Map.of("MY_VAR", "hello")) and run HarnessAgent against a real or mock K8s cluster
- Inside the sandbox, run execute_shell_command("echo $MY_VAR") and verify the output is hello
- 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
Codecov Report
:x: Patch coverage is 38.09524% with 13 lines in your changes missing coverage. Please review.
:loudspeaker: Thoughts on this report? Let us know!