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.1.tar.gz (36.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.1-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: metaflow_sandbox-0.1.1.tar.gz
  • Upload date:
  • Size: 36.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.1.tar.gz
Algorithm Hash digest
SHA256 7c6f029d0b9d3aa60e29928f2aea1b0a72814c8c0388e043f014f37ec8d0fb06
MD5 62a678f5833cb21c91b3c3c4c53a4014
BLAKE2b-256 d9b7033bad507d622534795aca5ed8131e54f70b96bb70dab975be4e53daa2f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for metaflow_sandbox-0.1.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for metaflow_sandbox-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9ffdee37bfc465063832a2574c08c5fdac6646807c48400cb022d6c1250fc17a
MD5 4390c551b0b31e1469f8896444f8eb5f
BLAKE2b-256 85bac3f1b40752d27dcd38dbcb8595cf67768d8668203f0ab65ab5429337bebd

See more details on using hashes here.

Provenance

The following attestation bundles were made for metaflow_sandbox-0.1.1-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