Skip to content

About

Official Python SDK for ComputeSDK gateway — unified sandbox execution across cloud providers.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

24 Commits

Folders and files

Repository files navigation

ComputeSDK Python

Python client for ComputeSDK: create cloud sandboxes on any supported provider (E2B, Modal, Daytona, Vercel, Superserve and more) through one API and one API key, then run commands, move files, start background processes and get preview URLs.

Version 0.2 is a rewrite on the platform API (https://platform.computesdk.com/api/v1/sandboxes). It replaces 0.1, which used the retired gateway.computesdk.com.

Install

pip install computesdk                    # the client
pip install "computesdk[openai-agents]"   # plus the OpenAI Agents SDK sandbox backend

Requires Python 3.10+. Create an API key at https://platform.computesdk.com and export it:

export COMPUTESDK_API_KEY=...

Quick start

import asyncio
from computesdk import compute

async def main():
    sandbox = await compute.sandbox.create()          # the platform picks a provider
    try:
        result = await sandbox.run_command("echo hello && uname -a")
        print(result.stdout, result.exit_code)

        await sandbox.filesystem.write_file("/tmp/app.py", "print('hi')")
        print((await sandbox.run_command("python3 /tmp/app.py")).stdout)
    finally:
        await sandbox.destroy()

asyncio.run(main())

Choosing where the sandbox runs

await compute.sandbox.create(provider="e2b")                     # pin one provider
await compute.sandbox.create(provider_order=["modal", "daytona"]) # ordered fallbacks
await compute.sandbox.create(size="large")                       # small … 3xlarge
await compute.sandbox.create(cpus=2, memory_mb=4096, image="python:3.12", timeout=1800, label="ci")

timeout is the sandbox lifetime in seconds. env={...} is applied to every command. Create is idempotent: a network failure replays the same request instead of booting a second sandbox.

Sandbox API

Call What it does
run_command(cmd, cwd=, env=, timeout=) Run a shell command (up to 290 s) and return stdout, stderr, exit_code. A non-zero exit is returned, not raised.
run_command(..., on_stdout=, on_stderr=) Same, streaming output to callbacks as it arrives.
start_process(cmd) / wait_process(id) / kill_process(id) Background processes for servers and long jobs.
filesystem.read_file / write_file / mkdir / readdir / exists / remove Text file operations on absolute paths.
get_url(port) Preview URL for a port.
refresh() / destroy() Re-read status; destroy (repeat calls are no-ops).

compute.sandbox.get(id), compute.sandbox.list() and compute.sandbox.destroy(id) manage existing sandboxes. Errors are ApiError (with status, code, retryable), SandboxNotFoundError, ClientError and CommandTimeoutError, all subclasses of ComputeError.

Configuration

Setting Argument Environment
API key Compute(api_key=...) COMPUTESDK_API_KEY (also COMPUTE_API_KEY)
Org (OAuth tokens with several orgs) Compute(org=...) COMPUTESDK_ORG
API URL Compute(base_url=...) COMPUTESDK_BASE_URL

The client only sends the key to computesdk.com hosts over HTTPS (or to localhost). Pass allow_untrusted_host=True to use another host.

OpenAI Agents SDK

computesdk.openai_agents is a sandbox backend for the OpenAI Agents SDK. Pass it as the sandbox client, and the agent's shell, file and workspace tools run in a ComputeSDK sandbox on whichever provider you choose:

from agents import RunConfig, Runner
from agents.sandbox import Manifest, SandboxAgent, SandboxRunConfig
from agents.sandbox.capabilities import Shell
from computesdk.openai_agents import ComputeSDKSandboxClient, ComputeSDKSandboxClientOptions

agent = SandboxAgent(
    name="Coder",
    instructions="Use the shell to answer.",
    default_manifest=Manifest(),
    capabilities=[Shell()],
)

result = await Runner.run(
    agent,
    "What Python version is installed?",
    run_config=RunConfig(
        sandbox=SandboxRunConfig(
            client=ComputeSDKSandboxClient(),
            options=ComputeSDKSandboxClientOptions(provider="e2b", timeout_s=900),
        )
    ),
)

ComputeSDKSandboxClientOptions takes the same placement fields as create() (provider, provider_order, size, cpus, memory_mb, disk_mb, image, timeout_s, label, env, ...). The API key stays on the client and is never written to serialized session state.

Behavior:

  • The workspace root defaults to /workspace.
  • The runner destroys the sandbox it created when the run ends.
  • resume() reattaches to the saved sandbox if it is still running, otherwise creates a replacement that the SDK hydrates from the workspace snapshot.
  • Workspace snapshots are tar archives of the workspace.
  • Not supported: PTY sessions, user= (sandbox-local users), and mounts that need provider-native support.

Development

python -m venv .venv && .venv/bin/pip install -e ".[dev,openai-agents]"
.venv/bin/ruff check computesdk tests && .venv/bin/mypy computesdk
COMPUTESDK_API_KEY=... .venv/bin/pytest   # live tests create and destroy real sandboxes

License

MIT

About

Official Python SDK for ComputeSDK gateway — unified sandbox execution across cloud providers.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages