Is CubeSandbox Compatible with E2B? Complete Migration Guide
CubeSandbox is fully compatible with E2B environments and acts as a drop-in replacement for the E2B SDK, requiring only a single environment variable change to migrate existing code.
The TencentCloud/CubeSandbox repository provides a hardware-isolated sandbox service explicitly designed to mirror the E2B API contract. According to the project documentation, CubeSandbox is compatible with E2B environments through identical HTTP endpoints, SDK method signatures, and network policy configurations, enabling seamless migration without business logic changes.
How CubeSandbox Implements E2B Compatibility
Native API Contract Mirroring
CubeSandbox implements the exact HTTP API contract that the E2B sandbox expects. As stated in the repository's README.md, the service exposes REST endpoints matching the E2B spec, allowing existing E2B clients like e2b_code_interpreter.AsyncSandbox to connect by simply changing the target URL. The CubeAPI/README.md documents these endpoints, confirming they follow the E2B protocol structure.
SDK Programming Model Parity
Both the Python and Go SDKs maintain programming models identical to their E2B counterparts. In sdk/python/cubesandbox/sandbox.py, the Sandbox.create() method and run_code() functions mirror E2B's initialization and execution patterns. The Go SDK in sdk/go/client.go and sdk/go/sandbox.go implements the same HTTP contract, exposing NewSandbox() and RunCode() methods with matching signatures.
Network Policy Interchangeability
The network policy configuration accepts E2B-shaped per-host request transforms. According to sdk/python/cubesandbox/_policy.py, the policy field handles the E2B transform shape, which is interchangeable with the typed-Rule shape used by E2B. This ensures existing security policies migrate without modification.
Migrating from E2B to CubeSandbox
Migration requires changing only the API endpoint configuration. Instead of setting E2B_API_URL, set CUBE_API_URL to point to your CubeSandbox deployment.
Python SDK Example
import os
from cubesandbox import Sandbox
# Point the SDK at a CubeSandbox instance
os.environ["CUBE_API_URL"] = "http://my-cubeapi:3000"
# Usage remains identical to the E2B SDK
with Sandbox.create() as sb:
res = sb.run_code('print("hello from CubeSandbox")')
print(res.logs.stdout) # → ["hello from CubeSandbox\n"]
Go SDK Example
package main
import (
"log"
"github.com/TencentCloud/CubeSandbox/sdk/go"
)
func main() {
// Configure the CubeSandbox endpoint
cfg := cubesandbox.Config{
APIURL: "http://my-cubeapi:3000",
}
sb, err := cubesandbox.NewSandbox(&cfg)
if err != nil {
log.Fatal(err)
}
defer sb.Kill()
// Execute code using the same signature as E2B
exec, err := sb.RunCode("2 + 2")
if err != nil {
log.Fatal(err)
}
log.Println("Result:", exec.Text) // → Result: 4
}
Key Source Files Supporting Compatibility
Several implementation files ensure CubeSandbox remains compatible with E2B environments:
sdk/python/cubesandbox/_policy.py: Handles E2B-shaped per-host request transforms for network policies.sdk/python/cubesandbox/sandbox.py: Manages sandbox lifecycle operations (create(),run_code()) with E2B-compatible signatures.sdk/go/client.go&sdk/go/sandbox.go: Implement the E2B HTTP contract and client initialization patterns.CubeAPI/README.md: Documents REST endpoints that match the E2B API specification.sdk/python/README.md: Explains the interchangeable network policy shapes and endpoint configuration.
Summary
- CubeSandbox is fully compatible with E2B environments and serves as a drop-in replacement requiring zero business-code changes.
- Migration involves only switching the environment variable from
E2B_API_URLtoCUBE_API_URL. - The Python SDK (
sandbox.py,_policy.py) and Go SDK (client.go,sandbox.go) mirror E2B method signatures exactly. - Network policies accept E2B-shaped request transforms, ensuring existing security configurations remain valid.
Frequently Asked Questions
Do I need to modify my existing E2B code to use CubeSandbox?
No. CubeSandbox is advertised as a drop-in replacement where you only need to swap one environment variable. The README states you can migrate with "zero business-code changes" by pointing CUBE_API_URL to your CubeSandbox deployment instead of E2B_API_URL.
Which E2B SDK features are supported by CubeSandbox?
CubeSandbox supports the core sandbox lifecycle operations including creation, code execution, and network policies. The Python SDK's Sandbox.create() and run_code() methods, as well as the Go SDK's NewSandbox() and RunCode() functions, maintain identical signatures to their E2B counterparts.
How do I configure the API endpoint for CubeSandbox?
Set the CUBE_API_URL environment variable to your CubeSandbox instance URL (e.g., http://my-cubeapi:3000). In Go, you can also configure this programmatically via the Config struct's APIURL field as implemented in sdk/go/client.go.
Is the network policy configuration compatible between E2B and CubeSandbox?
Yes. According to sdk/python/README.md, the network policy field accepts E2B-shaped per-host request transforms. The shape is interchangeable with the typed-Rule shape, ensuring existing E2B security configurations work without modification.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →