UCloud Sandbox Python SDK
UCloud Sandbox Python SDK 提供云端沙箱环境,用于安全运行 AI 生成的代码。
安装
pip install ucloud_sandbox
快速开始
1. 获取 API Key
export UCLOUD_SANDBOX_API_KEY=your_api_key
2. 基础沙箱
from ucloud_sandbox import Sandbox
with Sandbox.create() as sandbox:
result = sandbox.commands.run("echo 'Hello, World!'")
print(result.stdout)
3. Code Interpreter(代码解释器)
支持有状态的代码执行,变量在多次调用之间保持:
from ucloud_sandbox.code_interpreter import Sandbox
with Sandbox.create() as sandbox:
sandbox.run_code("x = 1")
execution = sandbox.run_code("x += 1; print(x)")
print(execution.logs.stdout) # ['2']
4. Desktop(桌面环境)
支持鼠标键盘控制、截图、VNC 流媒体:
from ucloud_sandbox.desktop import Sandbox
desktop = Sandbox.create()
# 截图
screenshot = desktop.screenshot()
# 鼠标操作
desktop.left_click(100, 200)
desktop.write("Hello, World!")
# VNC 流
desktop.stream.start()
print(desktop.stream.get_url())
desktop.kill()
私有化 HTTP 部署
私有化服务未配置 TLS 时,设置 sandbox 域名并启用非安全 HTTP:
export UCLOUD_SANDBOX_DOMAIN=sandbox.example.com
export UCLOUD_SANDBOX_INSECURE_HTTP=true
默认管理 API 地址为 http://api.<domain>;如果实际地址不符合这个规则,再通过
UCLOUD_SANDBOX_API_URL 指定完整 URL。
也可以在调用时传入参数:
from ucloud_sandbox import Sandbox
sandbox = Sandbox.create(
api_url="http://api.sandbox.example.com",
domain="sandbox.example.com",
insecure_http=True,
)
UCLOUD_SANDBOX_INSECURE_HTTP 默认为 false;仅应在可信私有网络中启用。
文档
访问 UCloud Agent Sandbox 文档 获取更多信息。
致谢
本项目基于 E2B 开源项目开发,感谢 E2B 团队的贡献。
许可证
MIT License - 详见 LICENSE 文件
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ucloud_sandbox-1.4.2.tar.gz.
File metadata
- Download URL: ucloud_sandbox-1.4.2.tar.gz
- Upload date:
- Size: 186.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
671eb59dfd610456030a97e56b2735972089857dd7ec4f013d3b4291b181c469
|
|
| MD5 |
952f67a15b9873c714bdcfdf8bdaa401
|
|
| BLAKE2b-256 |
99a7d708ea65985c30f84a0cee728e07e7c729364e9136483e46ecbc7f4d6525
|
File details
Details for the file ucloud_sandbox-1.4.2-py3-none-any.whl.
File metadata
- Download URL: ucloud_sandbox-1.4.2-py3-none-any.whl
- Upload date:
- Size: 346.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b7e070e90a21744b2d3080e472775645beeed6667666b4b74b7de6f61c452d1
|
|
| MD5 |
3a7bee096854202ba0613770a4b3021e
|
|
| BLAKE2b-256 |
b9cd7d6e4a70737afae28bc1b83ada67dd2aea9deaf8d003f23e4c94c7160d92
|