porter-sandbox
Python SDK for the Porter Sandbox API.
Pre-release. Pilot for Porter's multi-language SDK rollout.
Install
pip install porter-sandbox
Usage
from porter_sandbox import Porter
with Porter() as porter:
sb = porter.sandboxes.create(
image="python:3.11-alpine",
command=["python", "-c", "print('hi')"],
)
print(sb.logs())
sb.terminate()
Volumes can be created up front and mounted into sandboxes at launch, and their contents browsed and read straight from the volume handle:
volume = porter.volumes.create(name="my-data")
sb = porter.sandboxes.create(
image="python:3.11-alpine",
volume_mounts={"/mnt/my-data": volume.id},
)
for file in volume.listdir("/checkpoints"):
print(file.path, file.size_bytes)
config = volume.read_text("/checkpoints/config.json")
with open("model.safetensors", "wb") as out:
for chunk in volume.stream("/checkpoints/model.safetensors"):
out.write(chunk)
Inside a sandbox-enabled Porter cluster, the SDK connects to the in-cluster
sandbox API at http://sandbox-api.porter-sandbox-system.svc.cluster.local:8080
automatically, with no configuration needed.
From outside the cluster, set a Porter API token (created from Settings > API tokens in the Porter Dashboard) and the cluster where sandboxes are enabled:
export PORTER_SANDBOX_API_KEY=<porter-api-token>
export PORTER_CLUSTER_ID=<cluster-id>
The SDK reads the project from the token and calls the sandbox API through the
Porter API at dashboard.porter.run. To target a specific URL instead, set
PORTER_SANDBOX_BASE_URL or pass base_url - both take precedence over
everything above.
Async
For async code (FastAPI handlers, concurrent sandbox fan-out, etc.) use AsyncPorter — same surface, awaitable methods:
import asyncio
from porter_sandbox import AsyncPorter
async def main():
async with AsyncPorter() as porter:
sb = await porter.sandboxes.create(image="python:3.11-alpine", command=["python", "-c", "print('hi')"])
print(await sb.logs())
await sb.terminate()
asyncio.run(main())
Async is also the right choice when launching many sandboxes in parallel:
async with AsyncPorter() as porter:
results = await asyncio.gather(*[
porter.sandboxes.create(image="python:3.11", command=cmd) for cmd in commands
])
Layout
Everything under porter_sandbox/ is generated from the Porter Sandbox OpenAPI
spec. Do not edit it by hand - changes there are overwritten on the next release.
porter_sandbox/sandbox.py,porter_sandbox/volume.py- sync and asyncSandboxandVolumehandlesporter_sandbox/porter.pyand resource namespace modules likeporter_sandbox/sandboxes.py- public client and namespacesporter_sandbox/_client.py,_models.py,enums.py,_errors.py,resources/- low-level client, models, and errorsporter_sandbox/_base_client.py,_async_base_client.py,_config.py,_retries.py- sync and async HTTP transports, env-var resolution, retry/backoff
Development
pip install -e ".[dev]"
pytest
ruff check .
mypy
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file porter_sandbox-0.1.41.tar.gz.
File metadata
- Download URL: porter_sandbox-0.1.41.tar.gz
- Upload date:
- Size: 65.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42d5c3967a9460f35f8ec35711933251d4da4748d375ba359714c92ff038d21e
|
|
| MD5 |
ea3280d4e529dc12918740865428e946
|
|
| BLAKE2b-256 |
cef8172d60cc73eb36489ab9221df13aa118d209dc28d261e2b3ade03eca64b0
|
Provenance
The following attestation bundles were made for porter_sandbox-0.1.41.tar.gz:
Publisher:
release.yml on porter-dev/porter-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
porter_sandbox-0.1.41.tar.gz -
Subject digest:
42d5c3967a9460f35f8ec35711933251d4da4748d375ba359714c92ff038d21e - Sigstore transparency entry: 2282912305
- Sigstore integration time:
-
Permalink:
porter-dev/porter-python-sdk@46bf022487e5038a161800ccb35f6ee9aea0d251 -
Branch / Tag:
refs/tags/v0.1.41 - Owner: https://github.com/porter-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@46bf022487e5038a161800ccb35f6ee9aea0d251 -
Trigger Event:
release
-
Statement type:
File details
Details for the file porter_sandbox-0.1.41-py3-none-any.whl.
File metadata
- Download URL: porter_sandbox-0.1.41-py3-none-any.whl
- Upload date:
- Size: 32.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
deef16fa3e9a0764846578d033d9be7712b57f8d80aa39d75492d47b95f6f03d
|
|
| MD5 |
1ec3d42bd5f980b799c9fe38f6b9805e
|
|
| BLAKE2b-256 |
4830696047ec0a625a9ee94c98571b1eaf4ca860bff01bdc5f5bc52f199e44c6
|
Provenance
The following attestation bundles were made for porter_sandbox-0.1.41-py3-none-any.whl:
Publisher:
release.yml on porter-dev/porter-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
porter_sandbox-0.1.41-py3-none-any.whl -
Subject digest:
deef16fa3e9a0764846578d033d9be7712b57f8d80aa39d75492d47b95f6f03d - Sigstore transparency entry: 2282912490
- Sigstore integration time:
-
Permalink:
porter-dev/porter-python-sdk@46bf022487e5038a161800ccb35f6ee9aea0d251 -
Branch / Tag:
refs/tags/v0.1.41 - Owner: https://github.com/porter-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@46bf022487e5038a161800ccb35f6ee9aea0d251 -
Trigger Event:
release
-
Statement type: