Skip to content

Feat/kubernetes sandbox env injection#1713

Open
BukJiang wants to merge 3 commits into
agentscope-ai:mainfrom
BukJiang:feat/kubernetes-sandbox-env-injection
Open

Feat/kubernetes sandbox env injection#1713
BukJiang wants to merge 3 commits into
agentscope-ai:mainfrom
BukJiang:feat/kubernetes-sandbox-env-injection

Conversation

@BukJiang

@BukJiang BukJiang commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

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

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

BukJiang added 3 commits June 11, 2026 19:18
…stemSpec

KubernetesFilesystemSpec now supports environment(Map<String,String>),
mirroring the existing DockerFilesystemSpec API. Env vars are passed to
the K8s Pod container spec via EnvVar entries in Fabric8 ContainerBuilder.

- KubernetesSandboxClientOptions: add environment field with getter/setter
- KubernetesFilesystemSpec: add fluent environment() builder method
- KubernetesSandboxClient: include environment in merge() and copy()
- Fabric8KubernetesPodRuntime: apply env map via cb.withEnv() in createPod()
- merge(): source from o instead of base for consistency with other fields
- createPod(): drop redundant null-check, switch to addAllToEnv() for safety
Cover KubernetesSandboxClientOptions defensive copy, null-safety,
unmodifiable getter, and KubernetesSandboxClient.merge() semantics:
- null call options preserves spec-level env
- empty call-level env preserves spec-level env
- call-level key overrides spec-level key
- call-level key adds to spec-level env (non-overridden keys preserved)

Also widen merge() visibility to package-private to enable testing.
@BukJiang BukJiang requested a review from a team June 11, 2026 11:29
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ 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 ⚠️
...s/sandbox/kubernetes/KubernetesFilesystemSpec.java 0.00% 2 Missing ⚠️
...ns/sandbox/kubernetes/KubernetesSandboxClient.java 80.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added enhancement New feature or request area/extensions agentscope-extensions (general) labels Jun 12, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This PR adds a ConfigMap-based environment injection mechanism for Kubernetes sandboxes, allowing dynamic environment variables to be merged from multiple ConfigMaps.

Recommendation: COMMENT — 1 critical issue + 1 recommended + 1 nitpick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/extensions agentscope-extensions (general) enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants