Skip to main content

UCloud Sandbox Python SDK

UCloud Sandbox Python SDK 提供云端沙箱环境,用于安全运行 AI 生成的代码。

安装

pip install ucloud_sandbox

快速开始

1. 获取 API Key

  1. 访问 UCloud Sandbox 注册账号
  2. 在控制台获取 API Key
  3. 设置环境变量:
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()

文档

访问 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

ucloud_sandbox-1.3.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ucloud_sandbox-1.3.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file ucloud_sandbox-1.3.0.tar.gz.

File metadata

  • Download URL: ucloud_sandbox-1.3.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ucloud_sandbox-1.3.0.tar.gz
Algorithm Hash digest
SHA256 011dfce023dfc7b59982c0dca114e81fd816f96b1b1e9ce6ee092b46e6484527
MD5 9c7d66d23ba35c30ff62bf9a65d9ee4a
BLAKE2b-256 4d5b725e3a65a8ba2a75be3655c9359922ba14c63eca3c301ffee393b9762f11

See more details on using hashes here.

File details

Details for the file ucloud_sandbox-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: ucloud_sandbox-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ucloud_sandbox-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a8f8991fd60b4cb1ba61d14b818c90f68dfd53ddd95306b9bfbad1b7abe701ad
MD5 a3dc7ddef243591717f143b65fa363f1
BLAKE2b-256 d44f0654794514b104f991861bef23e22168df08ffdf8951a229cbeab8026fbd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page