Python SDK for Cerver - Sandboxed code execution for AI agents
Project description
Cerver Python SDK
Sandboxed code execution for AI agents.
Installation
pip install cerver
Quick Start
from cerver import Sandbox
# Set your API key
# export CERVER_API_KEY=sk_live_...
with Sandbox() as sandbox:
result = sandbox.run("print('Hello from sandbox!')")
print(result.output) # Hello from sandbox!
Usage
Basic Execution
from cerver import Sandbox
with Sandbox() as sandbox:
# Run code
result = sandbox.run("x = 1 + 1; print(x)")
print(result.output) # 2
print(result.exit_code) # 0
print(result.duration) # execution time in ms
State Persistence
Variables persist across runs in the same sandbox:
with Sandbox() as sandbox:
sandbox.run("x = 10")
sandbox.run("y = 20")
result = sandbox.run("print(x + y)")
print(result.output) # 30
Error Handling
from cerver import Sandbox, CerverError, TimeoutError
try:
with Sandbox() as sandbox:
result = sandbox.run("print(undefined_var)")
if result.exit_code != 0:
print(f"Error: {result.error}")
except TimeoutError:
print("Code timed out")
except CerverError as e:
print(f"Error: {e}")
Custom Configuration
sandbox = Sandbox(
api_key="sk_live_...", # Or use CERVER_API_KEY env var
timeout=60 # Default timeout in seconds
)
API Reference
Sandbox
run(code, timeout=None)- Execute Python codeclose()- Close the sandbox
ExecutionResult
output- stdout as stringerror- stderr as stringexit_code- Process exit code (0 = success)duration- Execution time in milliseconds
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cerver-0.1.0.tar.gz
(6.5 kB
view details)
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 cerver-0.1.0.tar.gz.
File metadata
- Download URL: cerver-0.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14344fea45d15afea2b706254105dc1fffbab9ee914fcca88d6b03022953e29e
|
|
| MD5 |
83aec7622e5bf73acdc2c47ab37c2c77
|
|
| BLAKE2b-256 |
4613ab8fd428b2524744354ba2c3cfd9bea1410b81265e7c4f0e547bc31aa471
|
File details
Details for the file cerver-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cerver-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34386fdeb3b8b422cc26486701e9abfd405d62bbe5fdb2096450d19bb88a70ee
|
|
| MD5 |
9e1c8e3e8ae77edf4da0fc0f967a31a6
|
|
| BLAKE2b-256 |
c2437bdc606093eb41445e049b74f9633284ebcee3a86e0f80e9ea40ac74d128
|