Skip to main content

Run Metaflow steps in isolated cloud sandboxes — instant container spinup via Daytona, E2B, or custom backends

Project description

metaflow-sandbox

CI Publish PyPI version Python License: Apache-2.0

Run selected Metaflow steps in fast remote sandboxes (Daytona or E2B) while keeping normal Metaflow behavior for artifacts, retries, and flow state.

Why Use It

  • ⚡ Speed + scale: launch sandboxes in milliseconds (<100ms) and fan out to thousands of containers.
  • 🔒 Isolation: run tool-heavy or untrusted code without polluting the launcher machine.
  • 📦 Dependency management: keep runtime dependencies consistent across local runs, CI, and remote execution.
  • 🧪 Throughput for evals: run many short-lived agent tasks in parallel for benchmark and regression loops.
  • 🔁 Continuity: keep normal step-to-step state and result passing.

Quick Start (Daytona) 🚀

pip install metaflow-sandbox[daytona]

export DAYTONA_API_KEY=...
export METAFLOW_DEFAULT_DATASTORE=s3
export METAFLOW_DATASTORE_SYSROOT_S3=s3://your-bucket/metaflow
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...

python my_flow.py run

Minimal example:

from metaflow import FlowSpec, step, daytona

class Demo(FlowSpec):
    @step
    def start(self):
        self.msg = "hello"
        self.next(self.remote)

    @daytona(cpu=1, memory=2048)
    @step
    def remote(self):
        self.msg = self.msg + " from sandbox"
        self.next(self.end)

    @step
    def end(self):
        print(self.msg)

if __name__ == "__main__":
    Demo()

R2 / S3-Compatible Setup ☁️

For Cloudflare R2, set:

export METAFLOW_S3_ENDPOINT_URL=https://<accountid>.r2.cloudflarestorage.com
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
# optional for R2:
export AWS_DEFAULT_REGION=auto

Dependency Hydration in Sandbox 📦

Use your normal Metaflow decorators:

@daytona
@pypi(packages={"pydash": "==8.0.5"})
@step
def pypi_step(self):
    import pydash
    self.x = pydash.camel_case("hello_world")
    self.next(self.conda_step)

@daytona
@conda(libraries={"numpy": "1.26.4"}, python="3.12.12")
@step
def conda_step(self):
    import numpy as np
    print(self.x, int(np.array([1, 2, 3]).sum()))

Backends 🔌

  • Daytona: pip install metaflow-sandbox[daytona], use @daytona
  • E2B: pip install metaflow-sandbox[e2b], use @e2b
  • Generic: @sandbox(backend="daytona", cpu=2, memory=4096)

Configuration 🧭

For the full list of decorator parameters, environment variables, defaults, and advanced toggles, see docs/configuration.md.

Troubleshooting 🛠️

  • Symptom: auth error from backend API

  • Fix: set the right key (DAYTONA_API_KEY or E2B_API_KEY) in the shell that runs the flow.

  • Symptom: @sandbox/@daytona says remote datastore is required

  • Fix: set METAFLOW_DEFAULT_DATASTORE and its remote datastore root.

  • Symptom: datastore access errors (403, missing objects, endpoint errors)

  • Fix: verify cloud credentials and endpoint config (METAFLOW_S3_ENDPOINT_URL for R2/custom S3).

Development 🧪

ruff check src/ tests/
pytest tests/unit/ tests/structural/
pytest tests/integration/ -m integration

Architecture details: docs/architecture.md
Backend interface: docs/adding-a-backend.md

License

Apache License 2.0. See LICENSE.

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

metaflow_sandbox-0.1.0.tar.gz (35.2 kB view details)

Uploaded Source

Built Distribution

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

metaflow_sandbox-0.1.0-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file metaflow_sandbox-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for metaflow_sandbox-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5003fd8a46f2d37ef1dab0eab0ebb31cfcddfd78e7073e15a03f8c9770117ceb
MD5 6b0ff06e86a4a347881fd55ce40393ea
BLAKE2b-256 3a530b9dc12079c72671f0b26ac0be36920d9bf8e78a1e8beff6e0e07f945cb7

See more details on using hashes here.

Provenance

The following attestation bundles were made for metaflow_sandbox-0.1.0.tar.gz:

Publisher: publish.yml on npow/metaflow-sandbox

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

File details

Details for the file metaflow_sandbox-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for metaflow_sandbox-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0726fb2d708c0cbdb981e3861b4cf2986cda1ab336e6b5dc282a0c12f15026ea
MD5 e569553f39559ae308b119a2362fbb7d
BLAKE2b-256 c64a1c4e31aad485d7e1a5f8c2ae41f0276fc8e17c6fddb885fd3d65674cf5c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for metaflow_sandbox-0.1.0-py3-none-any.whl:

Publisher: publish.yml on npow/metaflow-sandbox

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