Skip to main content

orchestrator_from_str

Create a reusable sandboxed task from a code string.

Warning: Experimental feature: alpha — APIs may change without notice.

The returned `CodeTaskTemplate` can be passed to `flyte.run()`
just like a decorated task.

The **last expression** in *source* becomes the return value::

pipeline = sandbox.orchestrator_from_str(
"add(x, y) * 2",
inputs=\{"x": int, "y": int\},
output=int,
tasks=[add],
)
result = flyte.run(pipeline, x=1, y=2) # → 6

Parameters
----------
source:
Python code string to execute in the sandbox.
inputs:
Mapping of input names to their types.
output:
The return type (default `NoneType`).
tasks:
List of external functions (tasks, durable ops) available inside the
sandbox. Each item's `__name__` is used as the key.
name:
Task name (default `"sandboxed-code"`).
timeout_ms:
Sandbox execution timeout in milliseconds.
cache:
Cache policy for the task.
retries:
Number of retries on failure.
image:
Docker image to use. If not provided, a default Debian image with
`pydantic-monty` is created automatically.
def orchestrator_from_str(
source: str,
*,
inputs: Dict[str, type],
output: type = type(None),
tasks: Optional[List[Any]] = None,
name: str = "sandboxed-code",
timeout_ms: int = 30_000,
cache: CacheRequest = "disable",
retries: int = 0,
image: Optional[Any] = None,
) -> CodeTaskTemplate: ...

Create a reusable sandboxed task from a code string.

Parameters​

NameTypeDescription
sourcestrPython code string to execute in the sandbox.
inputsDict[str, type]Mapping of input names to their types.
outputtype = type(None)The return type (default NoneType).
tasksOptional[List[Any]] = NoneList of external functions (tasks, durable ops) available inside the sandbox. Each item's name is used as the key.
namestr = "sandboxed-code"Task name.
timeout_msint = 30000Sandbox execution timeout in milliseconds.
cacheCacheRequest = "disable"Cache policy for the task.
retriesint = 0Number of retries on failure.
imageOptional[Any] = NoneDocker image to use. If not provided, a default Debian image with pydantic-monty is created automatically.

Returns​

TypeDescription
CodeTaskTemplateA reusable sandboxed task template that can be executed like a decorated task.