Overview
The--with flag lets you inject Metaflow step decorators at deploy time without modifying your flow source code. This is useful for adding infrastructure-level concerns (sandboxing, resource hints, compute backends) when compiling flows to Dagster.
Basic Usage
Inject a decorator on all steps:@sandbox to every step in your flow at compile time.
Multiple Decorators
Chain multiple--with flags to apply multiple decorators:
Resource Hints
The@resources decorator forwards CPU, memory, and GPU hints to the underlying compute backend (e.g., @kubernetes, @batch, @sandbox).
Defining Resources in Flow Code
Injecting Resources at Deploy Time
Alternatively, inject resource hints without modifying the flow:How Resource Hints Work
Decorator Added
The
--with=resources:... flag generates a resources:cpu=N,memory=M,gpu=G decorator spec.Forwarded to Compute Backend
The resource hints are passed to the underlying compute backend via the
--with flag when metaflow step is invoked.Resource hints are also visible as Dagster op tags in the UI, making it easy to see resource allocations at a glance.
Common Decorator Patterns
Sandbox Execution
Run all steps in isolated sandboxes (requiresmetaflow-sandbox extension):
Kubernetes Backend
Deploy all steps to Kubernetes:AWS Batch Backend
Run compute-intensive steps on AWS Batch:Combining with Step-Level Decorators
Decorators added via--with combine with decorators already present in your flow code:
process step gets both @retry and @sandbox decorators.
How —with Works Internally
--with decorators in STEP_WITH_DECORATORS and passes them to every metaflow step invocation.
Resource Spec Syntax
Theresources: decorator accepts three optional parameters:
cpu(int): Number of CPU coresmemory(int): Memory in MBgpu(int): Number of GPUs
The order of parameters doesn’t matter:
cpu=4,memory=8000 is equivalent to memory=8000,cpu=4.Best Practices
Per-Step vs. Global Decorators
- Per-step decorators (in flow code): Use when different steps need different configurations
- Global decorators (
--with): Use when all steps should share the same infrastructure setup
Advanced Example
A complete example with multiple decorators:@resourcesand@retryon theprocessstep (from code)@sandboxand@kuberneteson all steps (from--with)