Skip to main content

Run code in fast, isolated cloud sandboxes — zero Metaflow dependency

Project description

sandrun

CI PyPI License: Apache-2.0 Python 3.9+

Run code in fast, isolated cloud sandboxes without touching your local environment.

The problem

You want to execute untrusted or resource-intensive code in an isolated environment, but spinning up a full VM or container pipeline is slow, complex, and tightly coupled to your infrastructure. Existing sandbox SDKs lock you into a single provider — switching from Daytona to E2B means rewriting your integration from scratch.

Quick start

pip install sandrun[daytona]
export DAYTONA_API_KEY=...
from sandrun.backends import get_backend

backend = get_backend("daytona")
sandbox_id = backend.create()
result = backend.exec(sandbox_id, ["python", "-c", "print('hello from sandbox')"])
print(result.stdout)   # hello from sandbox
backend.destroy(sandbox_id)

Install

# Daytona backend
pip install sandrun[daytona]

# E2B backend
pip install sandrun[e2b]

# Both
pip install "sandrun[daytona,e2b]"

# Core only (bring your own backend)
pip install sandrun

Usage

Run a bash script and stream output

backend = get_backend("daytona")
sandbox_id = backend.create()

result = backend.exec_script_streaming(
    sandbox_id,
    "for i in 1 2 3; do echo step $i; sleep 1; done",
    on_stdout=print,
)
print("exit code:", result.exit_code)
backend.destroy(sandbox_id)

Upload a file, then execute it

backend = get_backend("e2b")
sandbox_id = backend.create()

backend.upload(sandbox_id, "script.py", "/tmp/script.py")
result = backend.exec(sandbox_id, ["python", "/tmp/script.py"])
backend.destroy(sandbox_id)

Deliver a code package and install deps offline

from sandrun.stager import TarballStager
from sandrun.installer import CondaOfflineInstaller

stager = TarballStager("my-project.tar")
installer = CondaOfflineInstaller.from_staged("staging-dir/")

backend = get_backend("daytona")
sandbox_id = backend.create()

stager.deliver(backend, sandbox_id)
installer.stage(backend, sandbox_id)

backend.exec_script(sandbox_id, "\n".join([
    *stager.setup_commands(),
    *installer.setup_commands(),
    "cd /tmp/.sandrun-workdir && python main.py",
]))
backend.destroy(sandbox_id)

How it works

sandrun is a thin orchestration layer with a provider-agnostic SandboxBackend interface. Each backend wraps a cloud sandbox SDK (Daytona, E2B) behind a uniform API: create, exec, upload, download, destroy. The TarballStager and CondaOfflineInstaller handle code and dependency delivery via backend.upload() — no object storage required.

Development

git clone https://github.com/npow/sandrun
cd sandrun
pip install -e ".[dev]"
pytest
ruff check .

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sandrun-0.1.1.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sandrun-0.1.1-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file sandrun-0.1.1.tar.gz.

File metadata

  • Download URL: sandrun-0.1.1.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sandrun-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cf7c079d1c5ef061df0673fb5214bc18b50ac9639c8b5af00e5621f930fd7770
MD5 262c7a84cc11b5e1ef1b1896edc8f44b
BLAKE2b-256 f95f73baba28898ff13dff8b68335da276727e29f6727258d7139a5616eef32d

See more details on using hashes here.

Provenance

The following attestation bundles were made for sandrun-0.1.1.tar.gz:

Publisher: publish.yml on npow/sandrun

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sandrun-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sandrun-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sandrun-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ca836fab2d90400737bf00b85ddf8883dc70cfa5d3058a72ea021503aa3c70ba
MD5 a5d96d621f3e7c4d224fe5656fa765d2
BLAKE2b-256 4c65353210816a6618e9617f5088dc4cc862047943032374f7a125d5666afe66

See more details on using hashes here.

Provenance

The following attestation bundles were made for sandrun-0.1.1-py3-none-any.whl:

Publisher: publish.yml on npow/sandrun

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page