Metadata-Version: 2.4
Name: vetoprotocol-sandbox
Version: 0.2.0
Summary: Python SDK for VetoProtocol Sandbox: secure cloud sandboxes for AI agents
Author: Veto Protocol
License-Expression: Apache-2.0
Project-URL: Homepage, https://vetoprotocol.live
Project-URL: Dashboard, https://sandbox.vetoprotocol.live
Keywords: sandbox,ai-agents,code-interpreter,llm,gvisor,firecracker
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# VetoProtocol Sandbox — Python SDK

Secure cloud sandboxes for AI agents. Start an isolated Linux sandbox in well under a second, then run Python and shell commands in it, work with its files, and open public URLs for apps running inside it. Each sandbox is destroyed when you kill it or its time runs out.

```bash
pip install vetoprotocol-sandbox
```

No dependencies — standard library only. Python 3.9+.

## Quickstart

1. Sign in at [sandbox.vetoprotocol.live](https://sandbox.vetoprotocol.live) and create an API key.
2. Set it in your environment:

   ```bash
   export SANDBOX_API_KEY=sk_...
   ```

3. Run code in a sandbox:

   ```python
   from vetoprotocol_sandbox import Sandbox

   with Sandbox.create() as sbx:
       print(sbx.run_code("1 + 1").text)   # 2
   ```

## Run Python

Code runs in a persistent kernel: variables and imports survive between calls, like notebook cells. Charts and tables come back as rich results.

```python
sbx.run_code("import pandas as pd\ndf = pd.DataFrame({'x': [1, 2, 3]})")
ex = sbx.run_code("print('rows:', len(df))\nint(df.x.sum())")
ex.text            # '6'  — the value of the last expression
ex.logs.stdout     # ['rows: 3\n']
ex.results         # [Result(text, html, png)] — DataFrames, matplotlib charts
ex.error           # ExecutionError(name, value, traceback), or None

sbx.run_code("for i in range(3): print(i)", on_stdout=print)   # stream output
sbx.restart_code_kernel()                                      # clear all state
```

## Run commands

```python
r = sbx.commands.run("pip install requests && python3 -V", timeout=120, on_stdout=print)
r.exit_code, r.stdout, r.stderr
```

## Terminal (PTY)

A real interactive terminal: full-screen programs, colors, Ctrl+C and resizing.
Output arrives as raw bytes on a background thread.

```python
import sys
term = sbx.pty.create(cols=120, rows=40, on_data=sys.stdout.buffer.write)
term.send_stdin("python3\n")
term.send_stdin("print(2 ** 10)\n")
term.send_stdin(b"\x04")          # Ctrl+D; b"\x03" is Ctrl+C
term.resize(100, 30)
term.send_stdin("exit\n")
term.wait()                       # exit code

sbx.pty.list()                    # open terminals in this sandbox (max 4)
term = sbx.pty.connect(term_id, on_data=...)   # reattach; replays recent output
term.kill()
```

## Files

```python
sbx.files.write("data/input.csv", "a,b\n1,2\n")   # relative paths start at /home/user
sbx.files.read("data/input.csv")
sbx.files.read("image.png", format="bytes")
sbx.files.list("data")                            # [EntryInfo(name, path, type, size)]
sbx.files.exists("data/input.csv")
sbx.files.remove("data")
```

## Preview URLs

Any server listening inside the sandbox gets a public HTTPS URL:

```python
import threading
threading.Thread(target=sbx.commands.run, args=("python3 -m http.server 8000",),
                 kwargs={"timeout": None}, daemon=True).start()
print(sbx.get_url(8000))   # https://8000-<sandbox-id>.sandbox.vetoprotocol.live
```

## Sandbox lifecycle

```python
sbx = Sandbox.create("code-interpreter", timeout=300, metadata={"user": "42"}, envs={"MY_VAR": "1"})
sbx.set_timeout(600)              # reset the remaining lifetime to 10 minutes
sbx.is_running()
Sandbox.list()                    # your running sandboxes
sbx = Sandbox.connect(sandbox_id) # reattach from another process
sbx.kill()
```

Templates: `code-interpreter` (Python with numpy, pandas, matplotlib, requests) and `base` (Python, git, curl).

## Configuration

| Setting | Argument | Environment variable | Default |
|---|---|---|---|
| API key | `api_key=` | `SANDBOX_API_KEY` | — (required) |
| API URL | `api_url=` | `SANDBOX_API_URL` | `https://sandbox.vetoprotocol.live` |

Failed API calls raise `SandboxError` with `.status` (HTTP status) and `.message`.

## License

Apache 2.0.
