Metadata-Version: 2.4
Name: swarmbox-sdk
Version: 0.4.1
Summary: Async Python client for swarmbox, open-source Sandboxes for RL rollouts, with a Harbor environment provider.
Keywords: sandbox,reinforcement-learning,rollouts,evals,agents,harbor
Author: Vibrant Labs
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Requires-Dist: httpx>=0.28.1
Requires-Dist: harbor>=0.8.1 ; extra == 'harbor'
Requires-Dist: pyyaml>=6.0.3 ; extra == 'harbor'
Requires-Python: >=3.12
Project-URL: Documentation, https://swarmbox.vibrantlabs.com
Project-URL: Source, https://github.com/vibrantlabsai/swarmbox
Provides-Extra: harbor
Description-Content-Type: text/markdown

# swarmbox

Async Python client for [swarmbox](https://swarmbox.vibrantlabs.com): Sandboxes for agentic RL rollouts and evals, with a [Harbor](https://github.com/harbor-framework/harbor) environment provider.

Each trial gets a **World**: a **Sandbox** for the agent's workspace and one for every service the task needs, on one private network, started and torn down as one.

```sh
pip install swarmbox-sdk
```

```python
import asyncio

import swarmbox_sdk


async def main():
    # Reads SWARMBOX_URL (default http://localhost:7700) and SWARMBOX_TOKEN.
    async with swarmbox_sdk.Client() as client:
        world = await client.create_world(
            [
                swarmbox_sdk.Sandbox(name="env", image="docker.io/library/python:3.12-slim",
                                     command=["python", "-m", "http.server", "8080"],
                                     aliases=["svc.internal"]),
                swarmbox_sdk.Sandbox(name="main", image="docker.io/library/python:3.12-slim",
                                     command=["sleep", "infinity"]),
            ],
            ttl="5m",
        )
        result = await world.exec("main", "getent hosts svc.internal")
        print(result.exit_code, result.stdout)
        await world.stop()


asyncio.run(main())
```

- `Client.create_world(sandboxes, ttl)` returns once every Sandbox is ready, or raises `WorldFailed` if the platform couldn't deliver the World.
- `Client.build_image(dir)` builds an image on the platform from a Dockerfile and its build context, and returns once it is ready (a lookup if those files were built before). Use its `ref` as a Sandbox's `image`. No Docker and no registry access needed.
- `World.exec`, `upload` and `download` act in one Sandbox, by name. An exec is killed after its `timeout` (10 minutes if none is given); the request waits that long whatever the client's own timeout.
- `get_world` and `list_worlds` look Worlds up.

## Harbor

Each Harbor trial runs as one World, and each service in the task's compose file as one Sandbox in it. The agent and the task stay the same; only the environment flag changes.

```sh
pip install 'swarmbox-sdk[harbor]'
export SWARMBOX_URL=https://api.swarmbox.vibrantlabs.com   # or your own API server
export SWARMBOX_TOKEN=...                                  # your token
harbor run -p tasks/ -a oracle --environment-import-path swarmbox_sdk.harbor:SwarmboxEnvironment
```

`tasks/` is a directory of Harbor tasks.

A token is all the machine running Harbor needs: the provider uploads each task's files and swarmbox builds its image, tagged by a hash of those files, so a task whose files haven't changed is a lookup, not a rebuild.

To build on your own machine instead, set `SWARMBOX_REGISTRY` to a registry your swarmbox nodes pull from. The provider then builds each image with `docker` and pushes it there (it needs `docker`, [`crane`](https://github.com/google/go-containerregistry/tree/main/cmd/crane) and push access), which is how `python -m swarmbox_sdk.harbor.prebuild` loads a batch of tasks ahead of a run.

| Option (`--ek key=value`) | Variable | Default |
|---|---|---|
| `url` | `SWARMBOX_URL` | `http://localhost:7700` |
| `token` | `SWARMBOX_TOKEN` | none |
| `registry` | `SWARMBOX_REGISTRY` | none: swarmbox builds the images |
| `pull_registry` | `SWARMBOX_PULL_REGISTRY` | `registry` |
| `platform` | `SWARMBOX_PLATFORM` | this machine's architecture (used only with `registry`) |
| `ttl` | | `3h`: each trial World's lifetime, and the longest an agent's run may take (Harbor's own agent timeout usually ends it first) |

Tasks may use only the compose keys `image`, `build`, `command`, `environment`, `volumes`, `expose`, `networks`, `healthcheck` and `depends_on`; anything else fails the trial before it starts rather than running it wrong.

More: [Run a Harbor job](https://github.com/vibrantlabsai/swarmbox/blob/main/docs/run-a-harbor-job.md).

## Docs

- [Quickstart](https://swarmbox.vibrantlabs.com/docs/quickstart/): the hosted test bed, from token to rollouts.
- [Docs](https://swarmbox.vibrantlabs.com/docs/) and [API reference](https://swarmbox.vibrantlabs.com/api/http/): the Harbor provider, the SDK, the HTTP API and the World spec. Their source is [`docs/`](https://github.com/vibrantlabsai/swarmbox/blob/main/docs/README.md).
- Renamed from opendsec: [what to change](https://swarmbox.vibrantlabs.com/docs/migrate-from-opendsec/).

## Contributing

See [AGENTS.md](https://github.com/vibrantlabsai/swarmbox/blob/main/AGENTS.md) for how the repo is laid out, how to run the checks, and how docs and releases work. It is written for people and coding agents alike.

Licensed under Apache-2.0.

<!-- This file is the PyPI page too: keep its links absolute. -->
