Skip to content

feat(python-sdk): add SandboxInClusterConnectionConfig to bypass router#489

Open
vgunapati wants to merge 2 commits intokubernetes-sigs:mainfrom
vgunapati:skip-router-layer
Open

feat(python-sdk): add SandboxInClusterConnectionConfig to bypass router#489
vgunapati wants to merge 2 commits intokubernetes-sigs:mainfrom
vgunapati:skip-router-layer

Conversation

@vgunapati
Copy link
Copy Markdown

@vgunapati vgunapati commented Mar 30, 2026

Summary

  • Adds SandboxInClusterConnectionConfig to models.py for direct in-cluster connectivity to sandbox pods, bypassing the sandbox router entirely
  • Constructs the pod URL as http://{sandbox_id}.{namespace}.svc.cluster.local:{server_port} directly from the sandbox identity
  • Adds InClusterConnectionStrategy to connector.py which suppresses router-specific headers (X-Sandbox-ID, X-Sandbox-Namespace, X-Sandbox-Port) since requests go directly to the pod
  • Integrates cleanly with the existing SandboxClient factory via the connection_config parameter

Usage

from k8s_agent_sandbox.models import SandboxInClusterConnectionConfig
from k8s_agent_sandbox import SandboxClient

client = SandboxClient(connection_config=SandboxInClusterConnectionConfig())
sandbox = client.create_sandbox(template="my-template")
result = sandbox.commands.run("echo hello")

Note: SandboxInClusterConnectionConfig requires the SDK to run inside the same Kubernetes cluster as the sandbox. A Kubernetes Service with the same name as the sandbox must exist in the sandbox namespace.

Test Plan

  • Unit tests: cd clients/python/agentic-sandbox-client && pytest k8s_agent_sandbox/test/ sandbox-router/test_sandbox_router.py — 62 passed
    • TestInClusterConnectionStrategy — DNS URL construction, header suppression, idempotency
    • TestExistingStrategiesDefaultHeaderInjection — regression: existing strategies unaffected
    • TestSandboxConnectorStrategySelection — in-cluster strategy selected for SandboxInClusterConnectionConfig
    • TestSandboxConnectorHeaderInjection — router headers suppressed for in-cluster, present otherwise
    • TestSandboxClientInClusterConfig — config stored correctly, propagated to created Sandbox handles
    • TestSandboxClient — regression: existing factory behaviour unaffected

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: vgunapati
Once this PR has been reviewed and has the lgtm label, please assign barney-s for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 30, 2026

Deploy Preview for agent-sandbox ready!

Name Link
🔨 Latest commit 8ad07a4
🔍 Latest deploy log https://app.netlify.com/projects/agent-sandbox/deploys/69cf3eb9881d2a00087ca200
😎 Deploy Preview https://deploy-preview-489--agent-sandbox.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @vgunapati!

It looks like this is your first PR to kubernetes-sigs/agent-sandbox 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/agent-sandbox has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 30, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @vgunapati. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 30, 2026
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 31, 2026
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Mar 31, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 31, 2026
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 31, 2026
@SHRUTI6991
Copy link
Copy Markdown
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 31, 2026
@vgunapati vgunapati force-pushed the skip-router-layer branch from 964491f to 7b8f20a Compare April 1, 2026 07:40
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 1, 2026
@vgunapati vgunapati force-pushed the skip-router-layer branch from 7b8f20a to e00b667 Compare April 1, 2026 07:52
@vgunapati vgunapati changed the title feat(python-sdk): add use_in_cluster to SandboxClient to bypass router feat(python-sdk): add SandboxInClusterConnectionConfig to bypass router Apr 1, 2026
f"Stderr: {stderr.decode(errors='replace')}"
)

class InClusterConnectionStrategy(ConnectionStrategy):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@vicentefb is this okay to do so?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Any update on this ?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 3, 2026
@vgunapati vgunapati force-pushed the skip-router-layer branch from e00b667 to 8ad07a4 Compare April 3, 2026 04:14
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:python-client cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants