终端命令
支持在沙箱内执行 Shell 命令并获取标准输出等结果。
支持函数
- sandbox.commands.run(cmd):执行命令,返回结果对象,含 stdout、stderr 等
使用示例
from e2b_code_interpreter import Sandbox
# 创建
sandbox = Sandbox.create(template="sandbox1")
# 执行命令
result = sandbox.commands.run("ls -l")
result = sandbox.commands.run("echo Hello, E2B! > test_echo.txt")
result = sandbox.commands.run("cat test_echo.txt")
assert "Hello, E2B!" in result.stdout