Skip to main content

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 async Sandbox and Volume handles
  • porter_sandbox/porter.py and resource namespace modules like porter_sandbox/sandboxes.py - public client and namespaces
  • porter_sandbox/_client.py, _models.py, enums.py, _errors.py, resources/ - low-level client, models, and errors
  • porter_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

Metadata

Release files for porter-sandbox 0.1.58

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for porter-sandbox 0.1.58
File Size Uploaded Provenance Actions
porter_sandbox-0.1.58.tar.gz 73.0 kB With provenance Details for porter_sandbox-0.1.58.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for porter-sandbox 0.1.58
File Interpreter ABI Platform Actions
porter_sandbox-0.1.58-py3-none-any.whl Python 3 none any Details for porter_sandbox-0.1.58-py3-none-any.whl

Total release size: 113.8 kB

Release files / porter_sandbox-0.1.58.tar.gz

Download URL porter_sandbox-0.1.58.tar.gz
Size 73.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8fd2c3f87d1982eaad57cdd29221f6415ceb624bc5e26df74066b12ffa3c1f78
BLAKE2b-256 checksum
How to use checksums
b19f687780e5cf1ce4200028a232c23f198f2dee691430914b1812aa92b6087d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 1, 2026.

Transparency log

Release files / porter_sandbox-0.1.58-py3-none-any.whl

Download URL porter_sandbox-0.1.58-py3-none-any.whl
Size 40.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
11bdc7762025a87777db9bec1973b6dc9a34ad595095fe88198765b763688151
BLAKE2b-256 checksum
How to use checksums
af0ec61d44ad2980cd16b025d74e073f4c69d1fb2a09df74b4f88a1302b31729
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 1, 2026.

Transparency log

Security for porter-sandbox 0.1.58

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for porter_sandbox-0.1.58.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page