Python: Add agent-framework-agentsandbox connector to integrate agent-sandbox - #6939
Python: Add agent-framework-agentsandbox connector to integrate agent-sandbox#6939aleks-stefanovic wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new Python connector package, agent-framework-agentsandbox, that provides a CodeAct-style execute_code tool backed by kubernetes-sigs/agent-sandbox (Kubernetes Pod execution with persistent filesystem/package state), plus the associated core namespace shim, docs, tests, samples, and workspace/lockfile registration.
Changes:
- Introduces
AgentSandboxExecuteCodeToolandAgentSandboxCodeActProviderto run LLM-emitted Python inside an agent-sandbox Pod claimed from aSandboxWarmPool. - Adds a core lazy-import shim (
agent_framework.agentsandbox) and a runnable sample demonstrating multi-turn persistence. - Registers the new package in the Python workspace (
pyproject.toml), lockfile (uv.lock), and package status table.
Reviewed changes
Copilot reviewed 17 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| python/uv.lock | Adds the new workspace member and locks k8s-agent-sandbox (+ transitive deps). |
| python/pyproject.toml | Registers agent-framework-agentsandbox as a workspace dependency. |
| python/PACKAGE_STATUS.md | Marks the new package as alpha. |
| python/packages/core/agent_framework/agentsandbox/init.py | Lazy-import namespace shim for optional connector usage (agent_framework.agentsandbox). |
| python/packages/core/agent_framework/agentsandbox/init.pyi | Typing stub re-exporting the connector’s public classes. |
| python/samples/02-agents/context_providers/README.md | Adds the new agentsandbox CodeAct sample to the context provider index. |
| python/samples/02-agents/context_providers/agentsandbox_codeact/README.md | Sample-specific setup and usage documentation. |
| python/samples/02-agents/context_providers/agentsandbox_codeact/agentsandbox_codeact.py | Runnable demo using OllamaChatClient and the new provider. |
| python/packages/agentsandbox/LICENSE | Adds MIT license for the new package. |
| python/packages/agentsandbox/README.md | Package overview, quickstart, and behavioral notes. |
| python/packages/agentsandbox/TESTING.md | End-to-end local testing walkthrough (kind + agent-sandbox + router + Ollama). |
| python/packages/agentsandbox/pyproject.toml | New package metadata, dependencies, and tooling config. |
| python/packages/agentsandbox/agent_framework_agentsandbox/py.typed | Marks the package as typed. |
| python/packages/agentsandbox/agent_framework_agentsandbox/init.py | Package exports and version resolution. |
| python/packages/agentsandbox/agent_framework_agentsandbox/_provider.py | ContextProvider that injects CodeAct instructions + the execute_code tool. |
| python/packages/agentsandbox/agent_framework_agentsandbox/_instructions.py | Builders for CodeAct instructions and tool description. |
| python/packages/agentsandbox/agent_framework_agentsandbox/_execute_code_tool.py | FunctionTool implementation that claims/reuses a sandbox Pod and executes code in it. |
| python/packages/agentsandbox/tests/agentsandbox/init.py | Test package init. |
| python/packages/agentsandbox/tests/agentsandbox/test_agentsandbox_codeact.py | Unit tests using a stubbed async sandbox client (no cluster required). |
@microsoft-github-policy-service agree |
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||
|
@aleks-stefanovic the uv.lock has a conflict |
d7acf4a to
5968079
Compare
|
Rebased onto latest main and regenerated uv.lock - the conflict is resolved. (Also picked up a newer ty on rebase and adjusted a couple of test casts it flagged as redundant.) |
# Conflicts: # python/samples/02-agents/context_providers/README.md
|
@moonbox3 I'm regularly checking this PR after I resolved the conflicts, but from time to time conflicts are recurring as agent framework repo is getting updated frequently. |
|
@aleks-stefanovic while this is very cool and definitely adds something to the space, we feel this is not something we want to/can maintain inside of our repo, if you host and publish this outside of our repo, then we could welcome a sample that showcases it, since we then we do not have to maintain the core integration here, as none of us are familiar with the particulars of this setup, evolving of the underlying libraries and systems, etc. So I'm closing this PR, but know that we do really appreciate the effort and would welcome a sample! |
Motivation & Context
Agent Framework ships
agent-framework-hyperlightas the reference CodeAct backend: LLM-emitted Python runs in an in-process WASM micro-VM — great for short, stateless computations, but it has no real filesystem, cannotpip install, and cannot run non-WASM libraries.This PR adds a container-grade, persistent peer:
agent-framework-agentsandbox, which runs the model'sexecute_codeinside a Kubernetes Pod managed by thekubernetes-sigs/agent-sandboxcontroller. It targets the scenarios Hyperlight cannot cover — persistent filesystem andpip installacross calls, real Linux libraries, optional gVisor/Kata isolation, warm-pool pre-warming, and running on infrastructure the team already operates, without shipping code or data to a hosted interpreter.The connector plugs into the same extension points as Hyperlight (
ContextProvider+FunctionTool) and keeps the same constructor surface (approval_mode, theexecute_codeinput schema,Contentreturn shape, CodeAct instruction injection), so switching backends is an import change.Description & Review Guide
What are the major changes?
New package
python/packages/agentsandbox/(agent-framework-agentsandbox):agent_framework_agentsandbox/_provider.pyAgentSandboxCodeActProvider(ContextProvider) — injects theexecute_codetool + CodeAct instructions on every runagent_framework_agentsandbox/_execute_code_tool.pyAgentSandboxExecuteCodeTool(FunctionToolnamedexecute_code) — owns the Pod lifecycle; native async via the agent-sandboxAsyncSandboxClient/AsyncSandbox; claims Pods from aSandboxWarmPoolagent_framework_agentsandbox/_instructions.pytests/agentsandbox/test_agentsandbox_codeact.pyREADME.md,TESTING.mdPlus:
python/packages/core/agent_framework/agentsandbox/— lazy-import shim sofrom agent_framework.agentsandbox import …works (same pattern asollama/hyperlight).python/samples/02-agents/context_providers/agentsandbox_codeact/— runnable demo usingOllamaChatClient(no API key); a two-turn flow shows the Pod's filesystem persisting acrossexecute_codecalls.python/pyproject.tomland a row inpython/PACKAGE_STATUS.md(alpha).How it compares to
agent-framework-hyperlight:hyperlightagentsandboxSandboxWarmPool)pip install-ed packagesSandboxWarmPoolcontrollerallowed_domainsctor argNetworkPolicyWhat is the impact of these changes?
Additive only — a new optional connector package plus a lazy namespace under core. No existing package behavior changes. Not a breaking change.
Dependency. The connector uses agent-sandbox's native async client (
AsyncSandboxClient/AsyncSandbox) and warm-pool claim API (create_sandbox(warmpool=...)), first released ink8s-agent-sandbox 0.5.0.pyproject.tomldepends onk8s-agent-sandbox[async]>=0.5.0,<1(the[async]extra pulls inhttpxandkubernetes_asyncio).Testing. Verified end-to-end on a local Kubernetes cluster with a local Ollama model: the model emits
execute_code, a Pod is claimed from a warm pool, the code runs inside it, and a file written by oneexecute_codecall is read back by a later call (filesystem persistence), includingpip installpersistence. Static checks are green against currentmain:ruff,ruff format,pyright(strict, source),mypy, and the package unit tests.TESTING.mdreproduces the full local run (kind + Ollama, no API keys).Related Issue
Fixes #
Contribution Checklist