create
Create a stateless Python code sandbox.
def create(
name: Optional[str] = null,
code: Optional[str] = null,
inputs: Optional[dict[str, type]] = null,
outputs: Optional[dict[str, type]] = null,
command: Optional[list[str]] = null,
arguments: Optional[list[str]] = null,
packages: Optional[list[str]] = null,
system_packages: Optional[list[str]] = null,
additional_commands: Optional[list[str]] = null,
resources: Optional[flyte.Resources] = null,
image_config: Optional[ImageConfig] = null,
image_name: Optional[str] = null,
image: Optional[str] = null,
auto_io: bool = True,
retries: int = 0,
timeout: Optional[int] = null,
env_vars: Optional[dict[str, str]] = null,
secrets: Optional[list] = null,
cache: str = "auto",
block_network: bool = False
) - > _Sandbox
Create a stateless Python code sandbox. The sandbox is stateless — each invocation runs in a fresh, ephemeral container. No filesystem state, environment variables or side effects carry over between runs. Three modes, mutually exclusive: - Auto-IO mode (code provided, auto_io=True, default): write just the business logic. Flyte auto-generates an argparse preamble so declared inputs are available as local variables, and writes declared scalar outputs to /var/outputs/ automatically. No boilerplate needed. - Verbatim mode (code provided, auto_io=False): run an arbitrary Python script as-is. CLI args for declared inputs are still forwarded, but the script handles all I/O itself (reading from /var/inputs/, writing to /var/outputs/< name > manually). - Command mode (command provided): run any shell command directly, e.g. a compiled binary or a shell pipeline. Call .run() on the returned sandbox to build the image and execute.
Parameters
| Name | Type | Description |
|---|---|---|
| name | Optional[str] = null | The sandbox name. This name derives task and image names. |
| code | Optional[str] = null | The Python source code to run in auto-IO or verbatim mode. This parameter is mutually exclusive with command. |
| inputs | Optional[dict[str, type]] = null | Input type declarations for the sandbox. Supported types include primitive types (int, float, str, bool), date/time types (datetime.datetime, datetime.timedelta), and IO handles (flyte.io.File, flyte.io.Dir). |
| outputs | Optional[dict[str, type]] = null | Output type declarations for the sandbox. Supported types include primitive types (int, float, str, bool), date/time types (datetime.datetime, datetime.timedelta), and IO handles (flyte.io.File, flyte.io.Dir). |
| command | Optional[list[str]] = null | The entrypoint command to execute in command mode. This parameter is mutually exclusive with code. |
| arguments | Optional[list[str]] = null | Arguments to be forwarded to the command when in command mode. |
| packages | Optional[list[str]] = null | A list of Python packages to install via pip within the sandbox environment. |
| system_packages | Optional[list[str]] = null | A list of system packages to install via apt within the sandbox environment. |
| additional_commands | Optional[list[str]] = null | A list of extra Dockerfile RUN commands to execute during image build. |
| resources | Optional[flyte.Resources] = null | CPU and memory resource specifications for the container running the sandbox. |
| image_config | Optional[ImageConfig] = null | Registry and Python version settings for the container image. |
| image_name | Optional[str] = null | An explicit name for the container image, which overrides the auto-generated one. |
| image | Optional[str] = null | The URI of a pre-built container image. Providing this skips the image build step. |
| auto_io | bool = True | A boolean flag that, when True (default), enables Flyte to wrap the code with an auto-generated argparse preamble and output-writing epilogue, making declared inputs available as local variables and collecting scalar outputs automatically. When False, the code is run verbatim and must handle all I/O itself. |
| retries | int = 0 | The number of times the task will retry on failure. |
| timeout | Optional[int] = null | The maximum duration, in seconds, before the task times out. |
| env_vars | Optional[dict[str, str]] = null | A dictionary of environment variables that will be available inside the container. |
| secrets | Optional[list] = null | A list of Flyte flyte.Secret objects to mount into the container. |
| cache | str = "auto" | The caching behavior for the sandbox, which can be set to "auto", "override", or "disable". |
| block_network | bool = False | A boolean flag that, when True, blocks all outbound network access for the sandbox, both locally via Docker network_mode=none and on-cluster via a NetworkPolicy. Defaults to False. |
Returns
| Type | Description |
|---|---|
_Sandbox | Configured sandbox ready to .run(). |