Skip to main content

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

NameTypeDescription
nameOptional[str] = nullThe sandbox name. This name derives task and image names.
codeOptional[str] = nullThe Python source code to run in auto-IO or verbatim mode. This parameter is mutually exclusive with command.
inputsOptional[dict[str, type]] = nullInput 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).
outputsOptional[dict[str, type]] = nullOutput 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).
commandOptional[list[str]] = nullThe entrypoint command to execute in command mode. This parameter is mutually exclusive with code.
argumentsOptional[list[str]] = nullArguments to be forwarded to the command when in command mode.
packagesOptional[list[str]] = nullA list of Python packages to install via pip within the sandbox environment.
system_packagesOptional[list[str]] = nullA list of system packages to install via apt within the sandbox environment.
additional_commandsOptional[list[str]] = nullA list of extra Dockerfile RUN commands to execute during image build.
resourcesOptional[flyte.Resources] = nullCPU and memory resource specifications for the container running the sandbox.
image_configOptional[ImageConfig] = nullRegistry and Python version settings for the container image.
image_nameOptional[str] = nullAn explicit name for the container image, which overrides the auto-generated one.
imageOptional[str] = nullThe URI of a pre-built container image. Providing this skips the image build step.
auto_iobool = TrueA 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.
retriesint = 0The number of times the task will retry on failure.
timeoutOptional[int] = nullThe maximum duration, in seconds, before the task times out.
env_varsOptional[dict[str, str]] = nullA dictionary of environment variables that will be available inside the container.
secretsOptional[list] = nullA list of Flyte flyte.Secret objects to mount into the container.
cachestr = "auto"The caching behavior for the sandbox, which can be set to "auto", "override", or "disable".
block_networkbool = FalseA 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

TypeDescription
_SandboxConfigured sandbox ready to .run().