agent-sandbox E2B SDK patch — one-line switch to use Agent Sandbox via the E2B Python SDK
Project description
agent-sandbox-e2b
A one-line patch that redirects the E2B Python SDK to a self-hosted Agent Sandbox deployment — no code changes to your existing E2B workflows required.
Agent Sandbox is a Kubernetes-native sandbox service for agentic AI scenarios (reasoning evaluation, training rollouts, code execution). It exposes an E2B-compatible API so you can reuse the E2B SDK while running on your own infrastructure.
Installation
pip install e2b agent-sandbox-e2b
Quick Start
Call patch_e2b() before importing Sandbox. It redirects all SDK requests to your Agent Sandbox cluster.
import os
os.environ["E2B_API_KEY"] = "agbx_your_api_key"
from agent_sandbox_e2b import patch_e2b
patch_e2b() # zero-argument: uses default in-cluster addresses
from e2b import Sandbox
sandbox = Sandbox.create("POOL_NAME", timeout=3600, secure=False)
sandbox.commands.run("echo hello")
sandbox.kill()
Note:
patch_e2b()must be called before anye2bimport; otherwise the SDK connects to the official E2B service.
Cross-Cluster Usage
Prefix the pool name with a cluster ID to route requests across clusters:
sandbox = Sandbox.create("CLUSTER_ID::POOL_NAME", timeout=3600, secure=False)
Custom Image Override
Override the pool's default image at creation time:
# Using metadata key
sandbox = Sandbox.create(
"POOL_NAME",
timeout=3600,
secure=False,
metadata={"agentbox.scitix.ai/image": "registry.example.com/my-env:v2"},
)
# Shorthand syntax
sandbox = Sandbox.create(
"CLUSTER_ID::POOL_NAME//registry.example.com/my-env:v2",
timeout=3600,
secure=False,
)
Configuration
patch_e2b() accepts optional arguments to override the target addresses:
| Parameter | Default (in-cluster) | Description |
|---|---|---|
domain |
agent-sandbox-data-plane.agentbox-system.svc.cluster.local |
Data-plane Envoy gateway address |
api_url |
http://agent-sandbox-e2b-api.agentbox-system.svc.cluster.local |
E2B-compatible API URL |
https |
False |
Use HTTPS for the data plane |
Priority: explicit argument > E2B_HTTPS / E2B_DOMAIN / E2B_API_URL environment variables > built-in defaults. E2B_HTTPS is truthy for 1/true/yes/on (case-insensitive).
# Local debugging via port-forward
patch_e2b(https=False, domain="localhost:9081", api_url="http://localhost:9082")
# Via environment variables (CI/CD)
# export E2B_DOMAIN=agent-sandbox-data-plane.agentbox-system.svc.cluster.local
# export E2B_API_URL=http://agent-sandbox-e2b-api.agentbox-system.svc.cluster.local
# export E2B_API_KEY=agbx_your_key
# export E2B_HTTPS=true # required when the data plane is behind an HTTPS ingress
patch_e2b()
When using the Helm chart in a namespace other than agentbox-system, pass the
installed namespace explicitly:
from agent_sandbox_e2b import patch_e2b
patch_e2b(
domain="agent-sandbox-data-plane.my-namespace.svc.cluster.local",
api_url="http://agent-sandbox-e2b-api.my-namespace.svc.cluster.local",
)
API key format (agbx_ keys)
Agent Sandbox issues API keys with an agbx_ prefix. Newer E2B SDKs
(>= ~2.24.0) added a client-side key-format check
(e2b.api.validate_api_key, pattern \Ae2b_[0-9a-f]+\Z) that rejects any key
not starting with e2b_, raising AuthenticationException before a request is
ever sent. patch_e2b() automatically neutralizes this local check (the
real authentication happens at the Agent Sandbox gateway), so agbx_ keys work
across both old and new E2B SDKs with no extra configuration:
os.environ["E2B_API_KEY"] = "agbx_..." # accepted after patch_e2b()
patch_e2b()
The override is applied inside patch_e2b() and is a no-op on older SDKs that
don't have the check. If you ever need the original behavior, do not call
patch_e2b() (or re-assign e2b.api.validate_api_key back yourself).
Compatibility
Release builds verify the patch against the latest E2B SDK from PyPI before
publishing (verified through E2B SDK 2.28.0). After patching, all standard
E2B SDK operations work unchanged:
sandbox.commands.run("python --version")
sandbox.commands.run("id", user="root")
sandbox.files.write("/tmp/hello.py", b"print('hello')\n")
sandbox.files.read("/tmp/hello.py")
sandbox.set_timeout(1800) # extend idle timeout dynamically
sandbox.kill()
Links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agent_sandbox_e2b-0.0.6.tar.gz.
File metadata
- Download URL: agent_sandbox_e2b-0.0.6.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0297888c0482068d3b78b15e7f336984b092fa76b2deafa4e64c12429f2f374b
|
|
| MD5 |
5f4f59b5fed86508672675911d3a7ee4
|
|
| BLAKE2b-256 |
dc84b8a44750c4c6bafc13493aae98f4acdca790cc86d51bc3a0cb499545e799
|
Provenance
The following attestation bundles were made for agent_sandbox_e2b-0.0.6.tar.gz:
Publisher:
sdk-python-publish.yml on scitix/Agent-Sandbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent_sandbox_e2b-0.0.6.tar.gz -
Subject digest:
0297888c0482068d3b78b15e7f336984b092fa76b2deafa4e64c12429f2f374b - Sigstore transparency entry: 1787149623
- Sigstore integration time:
-
Permalink:
scitix/Agent-Sandbox@2ecfcab5938e7ff86cfe01d0033428026f527fe7 -
Branch / Tag:
refs/tags/v0.0.6 - Owner: https://github.com/scitix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-python-publish.yml@2ecfcab5938e7ff86cfe01d0033428026f527fe7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file agent_sandbox_e2b-0.0.6-py3-none-any.whl.
File metadata
- Download URL: agent_sandbox_e2b-0.0.6-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d201e7df76499fffd813e809e2c10b726b24ca0fcc047e00fe0b999702a8500
|
|
| MD5 |
df0746ac18dde228224da488ff04934e
|
|
| BLAKE2b-256 |
9dae84776f8df016c341512be1a1086cca7164aab904c0505eb49df82a734b57
|
Provenance
The following attestation bundles were made for agent_sandbox_e2b-0.0.6-py3-none-any.whl:
Publisher:
sdk-python-publish.yml on scitix/Agent-Sandbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent_sandbox_e2b-0.0.6-py3-none-any.whl -
Subject digest:
8d201e7df76499fffd813e809e2c10b726b24ca0fcc047e00fe0b999702a8500 - Sigstore transparency entry: 1787149685
- Sigstore integration time:
-
Permalink:
scitix/Agent-Sandbox@2ecfcab5938e7ff86cfe01d0033428026f527fe7 -
Branch / Tag:
refs/tags/v0.0.6 - Owner: https://github.com/scitix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-python-publish.yml@2ecfcab5938e7ff86cfe01d0033428026f527fe7 -
Trigger Event:
push
-
Statement type: