template构建
支持通过预置镜像定义模板,并通过 Template.build 构建出可在 Sandbox.create 中使用的模板(别名)。构建时可指定 CPU、内存等资源。
支持函数
e2b.Template:模板定义与构建
Template().from_image(image_url):从镜像定义模板
Template.build(template, alias=..., cpu_count=..., memory_mb=...):构建模板并得到别名,供后续创建沙箱使用
使用示例
测试中使用构建好的 sandbox1 创建沙箱。
from e2b import Template
from e2b_code_interpreter import Sandbox
# 1. 从镜像定义模板
template = (
Template()
.from_image("registry.sensetime.com/sensecore-higgs/sandbox/sandbox-server:latest")
)
# 2. 构建模板(创建 Snapshot),指定别名与资源
result = Template.build(
template,
alias="sandbox1",
cpu_count=1,
memory_mb=1024,
)
# 3. 使用模板别名创建沙箱
sb = Sandbox.create(template="sandbox1")