Metadata-Version: 2.4
Name: tenki-sandbox
Version: 0.1.0
Summary: Python SDK for Tenki Sandbox
Author: Tenki Cloud
License-Expression: MIT
Requires-Python: >=3.10
Requires-Dist: grpcio>=1.73
Requires-Dist: protobuf>=6.31
Requires-Dist: websocket-client>=1.6
Provides-Extra: dev
Requires-Dist: grpcio-tools>=1.73; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Description-Content-Type: text/markdown

# Tenki Sandbox Python SDK

Python SDK for Tenki Sandbox: cloud sandboxes for AI agents and code execution.

```bash
pip install tenki-sandbox
```

```python
from tenki_sandbox import Sandbox

with Sandbox.create(project_id="proj_123", cpu_cores=2, memory_mb=4096) as sb:
    result = sb.exec("python3", "-c", "print('hello')")
    result.check()
    print(result.stdout_text)

    sb.fs.write_text("/workspace/input.txt", "data")
    print(sb.fs.read_text("/workspace/input.txt"))

    preview = sb.expose_port(3000, ttl=3600)
    print(preview.url)
```

## Auth

Auth resolution:

1. `auth_token=` passed to `Client` or `Sandbox.create`
2. `TENKI_AUTH_TOKEN`
3. `TENKI_API_KEY`

`TENKI_API_ENDPOINT` overrides the API URL; legacy `TENKI_API_URL` is also accepted.

## Process API

`exec` collects stdout/stderr and returns a result:

```python
result = sb.exec("npm", "test", timeout=60, env={"CI": "1"})
print(result.stdout_text)
result.check()
```

`start` returns a live process:

```python
proc = sb.start("bash", "-lc", "read name; echo hello $name")
proc.write_stdin("tenki\n")
proc.close_stdin()
for chunk in proc.stdout:
    print(chunk.decode(), end="")
proc.wait().check()
```

Use `shell()` when you want shell parsing:

```python
sb.shell("python3 -m http.server 3000 >/tmp/server.log 2>&1 &")
```

## Resource APIs

```python
from tenki_sandbox import Client, GiB

client = Client()

volume = client.volumes.create(
    workspace_id="ws_123",
    name="cache",
    size_bytes=10 * GiB,
    project_id="proj_123",
)

preview = client.preview_urls.create(
    project_id="proj_123",
    slug="demo",
    session_id=sb.id,
    port=3000,
)
```
