Metadata-Version: 2.5
Name: groundbox
Version: 0.3.0
Summary: Python SDK for the Groundbox API: sandboxes and CI runners for your agents
Project-URL: Homepage, https://groundbox.dev
Project-URL: Documentation, https://groundbox.dev/docs
Author-email: Groundbox <contact@groundbox.dev>
License-Expression: MIT
License-File: LICENSE
Keywords: agents,ci,groundbox,sandbox,sdk
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# groundbox

The Python client for the Groundbox API: sandboxes and CI runners for your agents.

```sh
pip install groundbox
```

## Quickstart

```python
from groundbox import Groundbox
gb = Groundbox()  # reads GROUNDBOX_API_KEY
sandbox = gb.create_sandbox(cpus=2)
print(gb.run_command(sandbox["id"], "uname -a")["stdout"])
gb.delete_sandbox(sandbox["id"])
```

`list_sandboxes` keeps stopped and failed sandboxes. To get only the ones that are not over, or only some: `gb.list_sandboxes(live=True, metadata={"project": "alpha"})`, or `status=["running", "paused"]`.

`make_dir`, `stat_file`, `file_exists` and `delete_file` (with `recursive=True` for a folder that has files in it) work on single paths.

A failed call raises `GroundboxError` with the API's `code`, `status` and `request_id`. Python 3.9 or newer, standard library only.

## From a Docker image

`image` starts a sandbox from a Docker image, with no template made first: a public image, or one in your Groundbox registry.

```python
sandbox = gb.create_sandbox(image="python:3.12-slim")
sandbox = gb.wait_for_sandbox(sandbox["id"])  # running, or failed with sandbox["error"]
print(gb.run_command(sandbox["id"], "python -V")["stdout"])
```

The first sandbox from an image comes back `queued` while the image is turned into a disk; later ones start like a template's. Commands run as root with the image's `ENV`. Its `ENTRYPOINT`, `CMD`, `USER` and `WORKDIR` are not used: start your program with a command and pass `cwd`. Private images on other registries are not supported.

A command is a string (a shell line, run with `sh -c`) or a list (a program and its arguments, run with no shell). `stdin` is text or bytes; `encoding="base64"` returns the output as base64, byte for byte.

```python
gb.run_command(sandbox["id"], ["git", "commit", "-m", "Fix the $PATH bug"])
print(gb.run_command(sandbox["id"], ["python3", "-"], stdin="print(6 * 7)\n")["stdout"])
```

Commands in the background: `start_command` returns at once with the command's id, `get_command_output` reads what it printed from a position, `follow_command` yields output until it ends, `list_commands` shows what runs and ran, and `kill_command` ends one.

```python
server = gb.start_command(sandbox["id"], "npm run dev", cwd="/home/runner/app")
for part in gb.follow_command(sandbox["id"], server["id"]):
    print(part["stdout"], end="")
```

## Snapshots

A snapshot keeps a sandbox as it is at one moment: memory, disk and running processes. It stays when the sandbox is deleted, and new sandboxes start from it.

```python
snapshot = gb.keep_snapshot(sandbox["id"], label="deps installed")
gb.delete_sandbox(sandbox["id"])
copy = gb.create_sandbox(snapshot_id=snapshot["id"])
gb.list_snapshots()
gb.delete_snapshot(snapshot["id"])
```

`keep_snapshot` waits until the snapshot is ready. Pass `snapshot_id` to keep one of the sandbox's save points instead of the moment now; that also works while the sandbox is paused. Paid plan; storage is billed per GB-month like a paused sandbox.

## Templates and volumes

A template is a ready-made disk (an image, a Dockerfile or a list of packages) built once. Sandboxes of the template's exact size start from its warm snapshot in well under a second.

```python
gb.create_template("python-ml", image="python:3.12-slim", pip=["numpy", "pandas"])
for line in gb.follow_template_logs("python-ml", 1):
    print(line["text"])
gb.create_volume(10, name="data")
sandbox = gb.create_sandbox(template="python-ml", volumes=[{"volume": "data", "path": "/data"}])
```

Docs: https://groundbox.dev/docs
