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

45 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
pip install "computesdk[deepagents]"      # plus the Deep Agents (LangChain) sandbox backend, Python 3.11+

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.

Temporal

The backend works with Temporal's OpenAI Agents integration (temporalio-openai-agents), which runs each sandbox operation as an activity. Register the client on the worker with SandboxClientProvider and name it from the workflow:

from temporalio.openai_agents import OpenAIAgentsPlugin, SandboxClientProvider
from computesdk.openai_agents import ComputeSDKSandboxClient

plugin = OpenAIAgentsPlugin(
    sandbox_clients=[SandboxClientProvider("computesdk", ComputeSDKSandboxClient())],
)
# In the workflow
from temporalio.openai_agents.workflow import temporal_sandbox_client

run_config = RunConfig(
    sandbox=SandboxRunConfig(
        client=temporal_sandbox_client("computesdk"),
        options=ComputeSDKSandboxClientOptions(timeout_s=900),
    )
)

Session state is serialized into workflow history, so a worker restart mid-run reattaches to the same sandbox if it is still running (otherwise a replacement is created and hydrated from the workspace snapshot). Note that resume() creates the replacement eagerly, so Temporal's post-shutdown sandbox_client_delete briefly creates and then destroys an extra sandbox per run. Import computesdk.openai_agents inside workflow.unsafe.imports_passed_through().

Deep Agents (LangChain)

computesdk.deepagents.ComputeSDKSandbox is a Deep Agents sandbox backend (BaseSandbox), so the agent's shell and filesystem tools run in a ComputeSDK sandbox:

from deepagents import create_deep_agent
from computesdk.deepagents import ComputeSDKSandbox

with ComputeSDKSandbox.create(provider="e2b", timeout=900) as backend:
    agent = create_deep_agent(model="anthropic:claude-sonnet-5-5", backend=backend)
    agent.invoke({"messages": [{"role": "user", "content": "Write and run a script that prints the kernel version"}]})

create() takes the same arguments as compute.sandbox.create() and destroys the sandbox when the with block exits; attach(sandbox_id) wraps an existing sandbox and leaves it running. Both the sync and async (aexecute, aupload_files, ...) methods are supported. Each command is limited to 290 seconds; a longer one returns exit code 124.

Development

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

Releasing

Bump version in pyproject.toml, merge, then publish a GitHub release tagged v<version> (for example v0.2.0). The release workflow checks that the tag matches the version, builds the sdist and wheel, and uploads them to PyPI through trusted publishing.

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