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
| Name | Type | Description |
|---|---|---|
| source | str | Python code string to execute in the sandbox. |
| inputs | Dict[str, type] | Mapping of input names to their types. |
| output | type = type(None) | The return type (default NoneType). |
| tasks | Optional[List[Any]] = None | List of external functions (tasks, durable ops) available inside the sandbox. Each item's name is used as the key. |
| name | str = "sandboxed-code" | Task name. |
| timeout_ms | int = 30000 | Sandbox execution timeout in milliseconds. |
| cache | CacheRequest = "disable" | Cache policy for the task. |
| retries | int = 0 | Number of retries on failure. |
| image | Optional[Any] = None | Docker image to use. If not provided, a default Debian image with pydantic-monty is created automatically. |
Returns
| Type | Description |
|---|---|
CodeTaskTemplate | A reusable sandboxed task template that can be executed like a decorated task. |