设置沙箱超时时间
更新时间 2026-03-13 16:16:26
最近更新时间: 2026-03-13 16:16:26
设置沙箱超时时间
每个沙箱都有一个 timeout(“超时时间”)配置,当沙箱的运行时间超过该配置值时,沙箱将自动关闭并释放。
您可以参考如下方式在启动的时候显式指定 timeout 的配置值,如果未指定,则默认值为 5 分钟。推荐按需设置 timeout 的值,以避免不必要的资源浪费。
from dotenv import load_dotenv
from e2b_code_interpreter import Sandbox
load_dotenv()
sbx = Sandbox.create(template="code-interpreter", timeout=60) # 单位为秒。
# 代码执行
execution = sbx.run_code("print('hello world')")
print(execution.logs)