from e2b.connection_config import ConnectionConfig
from e2b.api.client_sync import get_api_client
from e2b.api.client.api.templates import post_templates
from e2b.api.client.models import TemplateBuildRequest
使用官方 E2B SDK 创建 SandboxTemplate
api_base_url: E2B API 服务基础地址
namespace: Kubernetes 命名空间(默认 default)
template_spec: 可选的模版 spec 配置
if template_spec is None:
"agent.sandbox.io/snapshot-max-num": "2",
"vci.vke.volcengine.com/enable-auto-create-imc": "true",
"vci.vke.volcengine.com/preferred-instance-family": "vci.u1,vci.n3i",
"vci.volcengine.com/persistent-container": "true",
"vci.volcengine.com/tls-enable": "false",
"vci.volcengine.com/usable-disk-capacity": "40",
"vke.volcengine.com/burst-to-vci": "enforce"
{"name": "ENVD_DIR", "value": "/mnt/envd"},
{"name": "PORT", "value": "49999"}
"image": "cr-cn-guilin-boe.volces.com/vke/code-interpreter:v0.1.0",
"command": ["/bin/bash", "-c", "/mnt/envd/envd-run.sh"]
"limits": {"cpu": "2", "memory": "4Gi"},
"requests": {"cpu": "2", "memory": "4Gi"}
{"mountPath": "/mnt/envd", "name": "envd-volume"}
"command": ["sh", "/workspace/entrypoint.sh"],
{"name": "ENVD_DIR", "value": "/mnt/envd"},
{"name": "__IGNORE_RESOURCE__", "value": "true"}
"image": "helm-cr-cn-guilin-boe.cr.volces.com/vke/agent-runtime:v0.0.4",
"restartPolicy": "Always",
{"mountPath": "/mnt/envd", "name": "envd-volume"}
"terminationGracePeriodSeconds": 1,
"volumes": [{"emptyDir": {}, "name": "envd-volume"}]
"apiVersion": "extensions.agents.x-k8s.io/v1alpha1",
"kind": "SandboxTemplate",
config = ConnectionConfig(
api_client = get_api_client(
require_access_token=False
print(f" ✅ SDK 连接初始化成功!")
print(f" ❌ SDK 连接初始化失败: {e}")
build_request = TemplateBuildRequest(
build_request["namespace"] = namespace
build_request["sandboxTemplate"] = sandbox_template
response = post_templates.sync_detailed(