Metadata-Version: 2.4
Name: sandcovery
Version: 0.4.0
Summary: Python client for the Sandcovery API: one API and one key for ephemeral sandboxes across providers.
License-Expression: MIT
License-File: LICENSE
Requires-Dist: httpx>=0.28.1
Requires-Dist: pydantic>=2.14.3
Requires-Python: >=3.11
Project-URL: Homepage, https://www.sandcovery.com
Description-Content-Type: text/markdown

<p align="center">
  <img src="https://www.sandcovery.com/logo.svg" alt="Sandcovery" width="96" height="96">
</p>

# Sandcovery

Python client for the [Sandcovery API](https://www.sandcovery.com): one API and one key for ephemeral sandboxes across [every routed provider](https://www.sandcovery.com/providers), running on your own provider accounts.

## Install

```sh
pip install sandcovery
```

Python 3.11 or later.

## Quick start

Create an API key and add your provider credentials in the dashboard at https://www.sandcovery.com/app, then set `SANDCOVERY_API_KEY`.

```python
from sandcovery import Sandcovery

with Sandcovery() as sandcovery:
    sandbox = sandcovery.sandboxes.create(slug="sandcovery/2x4:cheapest", ttl_seconds=600)

    result = sandcovery.sandboxes.exec(sandbox.id, "python --version")
    print(result.exit_code, result.stdout)

    for event in sandcovery.sandboxes.exec_stream(sandbox.id, "pytest"):
        if event.type == "stdout":
            print(event.data, end="")

    sandcovery.sandboxes.destroy(sandbox.id)
```

Sandcovery destroys every sandbox at its `ttl_seconds`, even when your process exits first.

## Routing

A slug names a provider and a size, written `<provider>/<vcpu>x<memory_gib>`, in the shape of OpenRouter model slugs. `boat/2x4` pins boat at 2 vCPU and 4 GiB, and `sandcovery/2x4` routes across every candidate provider. Either number may be `n` for any value, so `sandcovery/nx16` runs each provider's cheapest size with 16 GiB. A slug routes as `:cheapest`, sorting candidates by list price. Add `:fastest` or `:most-reliable` to sort them by measured create latency or uptime over the last 15 minutes instead. With no slug, a create runs `sandcovery/2x4`.

```python
sandbox = sandcovery.sandboxes.create(slugs=["boat/2x4", "sandcovery/nx16:cheapest"])
```

`slugs` takes up to 8 slugs to try in order, as OpenRouter takes `models`, and `slug` goes first when both are set. Within a `sandcovery/` slug, a failed create falls back across that slug's candidates first, then moves to the next slug. `provider` takes `order`, `only`, `ignore`, `sort`, and `allow_fallbacks` and applies them to every slug. Every create attempt is listed in `sandbox.attempts`, and `sandbox.slug` is the provider and size it runs on.

Provider, region, and slug names are open strings, so a name the API adds later works with this version. The names known at release are `sandcovery.PROVIDERS`, `REGIONS`, `STANDARD_SIZES`, `SLUGS`, and `EGRESS_MODES`.

## Keys and provider credentials

`keys`, `credentials`, `usage`, and `billing` need a management key, which an organization owner mints in the dashboard. An API key receives 403 there.

```python
import os

from sandcovery import Sandcovery

admin = Sandcovery(os.environ["SANDCOVERY_MANAGEMENT_KEY"])
admin.credentials.set("e2b", api_key=os.environ["E2B_API_KEY"])
```

An organization on Pro can hold more than one credential for a provider: `credentials.add(provider, **fields)` adds another, a create tries them in the order they were added, and `credentials.delete_one(provider, credential_id)` deletes one.

The fields each provider takes are its `credential_fields` on `sandcovery.providers.get(provider)`. `sandcovery.providers.catalog()` lists every provider on the [provider board](https://www.sandcovery.com/providers), where `routed` is `False` for a provider that is coming soon. `credentials.offer()` reads the free vCPU-hours your keys have earned, `billing.get()` reads the plan and the credit balance, and `billing.buy_credits(amount_micro_usd=...)` answers the Stripe Checkout page that takes a credit payment.

## Errors

A failed call raises `SandcoveryError` with the HTTP `status`, the error `code`, such as `unsupported`, `no_provider_available`, `provider_error`, or `spend_limit_reached`, and the decoded error in `body`, which lists every attempt for `no_provider_available` and names the provider for `provider_error`.

## Reference

The API reference and the OpenAPI document are at https://www.sandcovery.com/docs.
