Sandboxes
zenml.sandboxes
Sandbox stack components for isolated code execution.
Attributes
DOCKER_SANDBOX_FLAVOR = 'docker'
module-attribute
LOCAL_SANDBOX_FLAVOR = 'local'
module-attribute
__all__ = ['DOCKER_SANDBOX_FLAVOR', 'LOCAL_SANDBOX_FLAVOR', 'BaseSandbox', 'BaseSandboxConfig', 'BaseSandboxFlavor', 'BaseSandboxSettings', 'ContainerizedSandboxSettings', 'DockerSandbox', 'DockerSandboxConfig', 'DockerSandboxFlavor', 'DockerSandboxPullPolicy', 'DockerSandboxSettings', 'SandboxSnapshot', 'LocalSandbox', 'LocalSandboxConfig', 'LocalSandboxFlavor', 'LocalSandboxSettings', 'SandboxExecError', 'SandboxOutput', 'SandboxProcess', 'SandboxSession', 'SandboxSessionClosedError']
module-attribute
Classes
BaseSandbox(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, environment: Optional[Dict[str, str]] = None, secrets: Optional[List[UUID]] = None, labels: Optional[Dict[str, Any]] = None, connector_requirements: Optional[ServiceConnectorRequirements] = None, connector: Optional[UUID] = None, connector_resource_id: Optional[str] = None, *args: Any, **kwargs: Any)
Bases: StackComponent, ABC
Base class for all ZenML sandbox components.
Source code in src/zenml/stack/stack_component.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
Attributes
config: BaseSandboxConfig
property
The sandbox component configuration.
Returns:
| Type | Description |
|---|---|
BaseSandboxConfig
|
The sandbox component configuration. |
settings_class: Optional[Type[BaseSettings]]
property
The sandbox settings class.
Returns:
| Type | Description |
|---|---|
Optional[Type[BaseSettings]]
|
The sandbox settings class. |
Methods:
attach(session_id: str) -> SandboxSession
Attach to a running sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The ID of the running sandbox session. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the sandbox does not support attaching to a running sandbox session. |
Returns:
| Type | Description |
|---|---|
SandboxSession
|
Sandbox session. |
Source code in src/zenml/sandboxes/base.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
create_session(settings: Optional[BaseSandboxSettings] = None, destroy_on_exit: bool = False) -> SandboxSession
abstractmethod
Create a fresh sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Optional[BaseSandboxSettings]
|
The sandbox settings. |
None
|
destroy_on_exit
|
bool
|
Whether to destroy the sandbox session when the session context manager exits. |
False
|
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A new sandbox session. |
Source code in src/zenml/sandboxes/base.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
resolve_settings(override: Optional[BaseSandboxSettings] = None) -> BaseSandboxSettings
Resolve the sandbox settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
override
|
Optional[BaseSandboxSettings]
|
Per-call settings override. If provided these will override values in the component settings/config. |
None
|
Returns:
| Type | Description |
|---|---|
BaseSandboxSettings
|
The resolved settings. |
Source code in src/zenml/sandboxes/base.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
restore(snapshot: SandboxSnapshot) -> SandboxSession
Restore a sandbox session from a snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
SandboxSnapshot
|
The snapshot to restore from. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the sandbox does not support restoring from a snapshot. |
Returns:
| Type | Description |
|---|---|
SandboxSession
|
Sandbox session. |
Source code in src/zenml/sandboxes/base.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
BaseSandboxConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: StackComponentConfig
Sandbox configuration.
Source code in src/zenml/stack/stack_component.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
Attributes
is_local: bool
property
Whether this sandbox component is running locally.
Returns:
| Type | Description |
|---|---|
bool
|
Whether this sandbox component is running locally. |
BaseSandboxFlavor
Bases: Flavor
Base sandbox flavor.
Attributes
config_class: Type[BaseSandboxConfig]
property
implementation_class: Type[BaseSandbox]
abstractmethod
property
type: StackComponentType
property
BaseSandboxSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSettings
Sandbox settings.
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
ContainerizedSandboxSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSandboxSettings
Containerized sandbox settings.
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
DockerSandbox(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, environment: Optional[Dict[str, str]] = None, secrets: Optional[List[UUID]] = None, labels: Optional[Dict[str, Any]] = None, connector_requirements: Optional[ServiceConnectorRequirements] = None, connector: Optional[UUID] = None, connector_resource_id: Optional[str] = None, *args: Any, **kwargs: Any)
Bases: BaseSandbox
Docker daemon-backed sandbox.
Source code in src/zenml/stack/stack_component.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
Attributes
config: DockerSandboxConfig
property
Docker sandbox configuration.
Returns:
| Type | Description |
|---|---|
DockerSandboxConfig
|
The Docker sandbox configuration. |
docker_client: DockerClient
property
Initialize and/or return the docker client.
Returns:
| Type | Description |
|---|---|
DockerClient
|
The docker client. |
docker_engine: DockerContainerEngine
property
Initialize and/or return the docker engine.
Returns:
| Type | Description |
|---|---|
DockerContainerEngine
|
The docker engine. |
settings_class: Optional[Type[BaseSandboxSettings]]
property
Settings class.
Returns:
| Type | Description |
|---|---|
Optional[Type[BaseSandboxSettings]]
|
|
Methods:
attach(session_id: str) -> SandboxSession
Attach to a running Docker sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The ID of the running sandbox session. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no running session with the given ID exists. |
Returns:
| Type | Description |
|---|---|
SandboxSession
|
Sandbox session. |
Source code in src/zenml/sandboxes/docker_sandbox.py
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |
create_session(settings: Optional[BaseSandboxSettings] = None, destroy_on_exit: bool = False) -> SandboxSession
Create a Docker sandbox session backed by a new container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Optional[BaseSandboxSettings]
|
Optional settings overrides. |
None
|
destroy_on_exit
|
bool
|
Whether to destroy the sandbox session when the session context manager exits. |
False
|
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A Docker sandbox session. |
Source code in src/zenml/sandboxes/docker_sandbox.py
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 | |
restore(snapshot: SandboxSnapshot) -> SandboxSession
Restore a sandbox session from a snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
SandboxSnapshot
|
The snapshot to restore from. |
required |
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A new session started from the snapshot image. |
Source code in src/zenml/sandboxes/docker_sandbox.py
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 | |
DockerSandboxConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSandboxConfig, DockerSandboxSettings
Docker sandbox configuration.
Source code in src/zenml/stack/stack_component.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
Attributes
is_local: bool
property
Whether this sandbox component is running locally.
Returns:
| Type | Description |
|---|---|
bool
|
Whether this sandbox component is running locally. |
DockerSandboxFlavor
Bases: BaseSandboxFlavor
Docker sandbox flavor.
Attributes
config_class: Type[DockerSandboxConfig]
property
docs_url: Optional[str]
property
Docs URL.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The docs URL. |
implementation_class: Type[DockerSandbox]
property
logo_url: str
property
Dashboard logo URL.
Returns:
| Type | Description |
|---|---|
str
|
The flavor logo URL. |
name: str
property
Flavor name.
Returns:
| Type | Description |
|---|---|
str
|
The flavor name. |
sdk_docs_url: Optional[str]
property
SDK docs URL.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The flavor SDK docs URL. |
DockerSandboxPullPolicy
DockerSandboxSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: ContainerizedSandboxSettings
Docker sandbox settings.
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
LocalSandbox(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, environment: Optional[Dict[str, str]] = None, secrets: Optional[List[UUID]] = None, labels: Optional[Dict[str, Any]] = None, connector_requirements: Optional[ServiceConnectorRequirements] = None, connector: Optional[UUID] = None, connector_resource_id: Optional[str] = None, *args: Any, **kwargs: Any)
Bases: BaseSandbox
Local subprocess-based Sandbox.
Warning: This class does NOT provide any isolation and is not suitable for running untrusted code.
Source code in src/zenml/stack/stack_component.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
Attributes
config: LocalSandboxConfig
property
Local sandbox configuration.
Returns:
| Type | Description |
|---|---|
LocalSandboxConfig
|
The local sandbox configuration. |
settings_class: Optional[Type[BaseSandboxSettings]]
property
Methods:
create_session(settings: Optional[BaseSandboxSettings] = None, destroy_on_exit: bool = False) -> SandboxSession
Create a local sandbox session in a clean working directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Optional[BaseSandboxSettings]
|
Optional settings overrides. |
None
|
destroy_on_exit
|
bool
|
Whether to destroy the sandbox session when the session context manager exits. |
False
|
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A local sandbox session. |
Source code in src/zenml/sandboxes/local_sandbox.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
LocalSandboxConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSandboxConfig, LocalSandboxSettings
Local sandbox configuration.
Source code in src/zenml/stack/stack_component.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
LocalSandboxFlavor
Bases: BaseSandboxFlavor
Local subprocess sandbox flavor.
Attributes
config_class: Type[LocalSandboxConfig]
property
docs_url: Optional[str]
property
Docs URL.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The docs URL. |
implementation_class: Type[LocalSandbox]
property
logo_url: str
property
Dashboard logo URL.
Returns:
| Type | Description |
|---|---|
str
|
The flavor logo URL. |
name: str
property
Flavor name.
Returns:
| Type | Description |
|---|---|
str
|
The flavor name. |
sdk_docs_url: Optional[str]
property
SDK docs URL.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The flavor SDK docs URL. |
LocalSandboxSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSandboxSettings
Local sandbox settings.
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
SandboxExecError
Bases: RuntimeError
Raised when a sandbox command fails to launch.
SandboxOutput(stdout: str, stderr: str, exit_code: int, stdout_truncated: bool = False, stderr_truncated: bool = False)
dataclass
Result of fully consuming a sandbox process.
SandboxProcess(session: SandboxSession, started_at: float)
Bases: ABC
Handle to a command being executed inside a sandbox session.
Initialize the sandbox process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
SandboxSession
|
The owning session. |
required |
started_at
|
float
|
The wall-clock time the process started. |
required |
Source code in src/zenml/sandboxes/process.py
49 50 51 52 53 54 55 56 57 58 | |
Attributes
exit_code: Optional[int]
abstractmethod
property
Exit code, or None if the command is still running.
Methods:
collect(*, max_chars: int = _DEFAULT_COLLECT_CHAR_COUNT) -> SandboxOutput
Wait for the process to exit and return the output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_chars
|
int
|
Maximum number of characters to collect per stream. |
_DEFAULT_COLLECT_CHAR_COUNT
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the process output was already collected. The streams are drained by the first call, so a second call would fabricate an empty result instead of the real output. |
drain_exception
|
Re-raised from a failed stdout or stderr drain. |
Returns:
| Type | Description |
|---|---|
SandboxOutput
|
The output of the process. |
Source code in src/zenml/sandboxes/process.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
kill() -> None
abstractmethod
Terminates the process.
Source code in src/zenml/sandboxes/process.py
87 88 89 | |
stderr() -> Iterator[str]
abstractmethod
Yield stderr lines.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator over standard error lines. |
Source code in src/zenml/sandboxes/process.py
68 69 70 71 72 73 74 | |
stdout() -> Iterator[str]
abstractmethod
Yield stdout lines.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator over standard output lines. |
Source code in src/zenml/sandboxes/process.py
60 61 62 63 64 65 66 | |
wait(timeout: Optional[float] = None) -> int
abstractmethod
Blocks until the process exits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
Optional[float]
|
Timeout in seconds to wait. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The exit code. |
Source code in src/zenml/sandboxes/process.py
76 77 78 79 80 81 82 83 84 85 | |
SandboxSession(*, id: str, parent: BaseSandbox, destroy_on_exit: bool = False)
Bases: ABC
Sandbox session.
Initialize the sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
Session identifier. |
required |
parent
|
BaseSandbox
|
The sandbox component that created this session. |
required |
destroy_on_exit
|
bool
|
Whether to destroy the sandbox session when the session context manager exits. |
False
|
Source code in src/zenml/sandboxes/session.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
Attributes
closed: bool
property
Whether this session handle has been closed.
Returns:
| Type | Description |
|---|---|
bool
|
|
Methods:
aexec(command: Union[str, List[str]], *, cwd: Optional[str] = None, env: Optional[Dict[str, str]] = None) -> SandboxProcess
async
Async execute a command in the sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
Union[str, List[str]]
|
The command to execute. |
required |
cwd
|
Optional[str]
|
Optional working directory override. |
None
|
env
|
Optional[Dict[str, str]]
|
Optional environment variables to set in the environment executing the command. |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the sandbox does not support async exec. |
Returns:
| Type | Description |
|---|---|
SandboxProcess
|
Process handle. |
Source code in src/zenml/sandboxes/session.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
close() -> None
Close the sandbox session handle. Terminal and idempotent.
After closing, the session handle rejects further use (exec,
snapshots, file transfer) — re-attach to the sandbox for a fresh
handle. For remote sandboxes, closing does not terminate the
sandbox on the provider: it keeps running until its TTL expires
or destroy() is called.
Source code in src/zenml/sandboxes/session.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
create_snapshot() -> SandboxSnapshot
Create a snapshot of the sandbox session.
Returns:
| Type | Description |
|---|---|
SandboxSnapshot
|
A sandbox snapshot. |
Source code in src/zenml/sandboxes/session.py
163 164 165 166 167 168 169 170 | |
destroy() -> None
Destroy the sandbox session. Terminal like close().
Terminates the sandbox on the provider and then closes this
handle, so after a successful call it is no longer possible to
attach to the session. Flavor failures (including
NotImplementedError from flavors without destroy support)
propagate and leave the handle open for retry, because the
flavor hook runs before close(). Callable on an
already-closed handle: close() is idempotent.
Source code in src/zenml/sandboxes/session.py
260 261 262 263 264 265 266 267 268 269 270 271 272 | |
download_file(remote_path: str, local_path: str) -> None
Download a file from the sandbox to the local filesystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
remote_path
|
str
|
Source path in the sandbox. |
required |
local_path
|
str
|
Destination path on the caller's filesystem. |
required |
Source code in src/zenml/sandboxes/session.py
210 211 212 213 214 215 216 217 218 | |
exec(command: Union[str, List[str]], *, cwd: Optional[str] = None, env: Optional[Dict[str, str]] = None) -> SandboxProcess
Execute a command in the sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
Union[str, List[str]]
|
The command to execute. |
required |
cwd
|
Optional[str]
|
Optional working directory override. |
None
|
env
|
Optional[Dict[str, str]]
|
Optional environment variables to set in the environment executing the command. |
None
|
Returns:
| Type | Description |
|---|---|
SandboxProcess
|
Process handle. |
Source code in src/zenml/sandboxes/session.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
upload_file(local_path: str, remote_path: str) -> None
Upload a file to the sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_path
|
str
|
Source path on the caller's filesystem. |
required |
remote_path
|
str
|
Destination path in the sandbox. |
required |
Source code in src/zenml/sandboxes/session.py
186 187 188 189 190 191 192 193 194 | |
SandboxSessionClosedError
Bases: RuntimeError
Raised when a closed sandbox session is used.
SandboxSnapshot
Bases: BaseModel
Sandbox snapshot.
Modules
base
Base sandbox flavor and component.
Classes
BaseSandbox(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, environment: Optional[Dict[str, str]] = None, secrets: Optional[List[UUID]] = None, labels: Optional[Dict[str, Any]] = None, connector_requirements: Optional[ServiceConnectorRequirements] = None, connector: Optional[UUID] = None, connector_resource_id: Optional[str] = None, *args: Any, **kwargs: Any)
Bases: StackComponent, ABC
Base class for all ZenML sandbox components.
Source code in src/zenml/stack/stack_component.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
config: BaseSandboxConfig
property
The sandbox component configuration.
Returns:
| Type | Description |
|---|---|
BaseSandboxConfig
|
The sandbox component configuration. |
settings_class: Optional[Type[BaseSettings]]
property
The sandbox settings class.
Returns:
| Type | Description |
|---|---|
Optional[Type[BaseSettings]]
|
The sandbox settings class. |
attach(session_id: str) -> SandboxSession
Attach to a running sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The ID of the running sandbox session. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the sandbox does not support attaching to a running sandbox session. |
Returns:
| Type | Description |
|---|---|
SandboxSession
|
Sandbox session. |
Source code in src/zenml/sandboxes/base.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
create_session(settings: Optional[BaseSandboxSettings] = None, destroy_on_exit: bool = False) -> SandboxSession
abstractmethod
Create a fresh sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Optional[BaseSandboxSettings]
|
The sandbox settings. |
None
|
destroy_on_exit
|
bool
|
Whether to destroy the sandbox session when the session context manager exits. |
False
|
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A new sandbox session. |
Source code in src/zenml/sandboxes/base.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
resolve_settings(override: Optional[BaseSandboxSettings] = None) -> BaseSandboxSettings
Resolve the sandbox settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
override
|
Optional[BaseSandboxSettings]
|
Per-call settings override. If provided these will override values in the component settings/config. |
None
|
Returns:
| Type | Description |
|---|---|
BaseSandboxSettings
|
The resolved settings. |
Source code in src/zenml/sandboxes/base.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
restore(snapshot: SandboxSnapshot) -> SandboxSession
Restore a sandbox session from a snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
SandboxSnapshot
|
The snapshot to restore from. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the sandbox does not support restoring from a snapshot. |
Returns:
| Type | Description |
|---|---|
SandboxSession
|
Sandbox session. |
Source code in src/zenml/sandboxes/base.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
BaseSandboxConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: StackComponentConfig
Sandbox configuration.
Source code in src/zenml/stack/stack_component.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
is_local: bool
property
Whether this sandbox component is running locally.
Returns:
| Type | Description |
|---|---|
bool
|
Whether this sandbox component is running locally. |
BaseSandboxFlavor
Bases: Flavor
Base sandbox flavor.
config_class: Type[BaseSandboxConfig]
property
implementation_class: Type[BaseSandbox]
abstractmethod
property
type: StackComponentType
property
BaseSandboxSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSettings
Sandbox settings.
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
ContainerizedSandboxSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSandboxSettings
Containerized sandbox settings.
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
Functions:
docker_sandbox
Docker sandbox flavor.
Classes
DockerSandbox(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, environment: Optional[Dict[str, str]] = None, secrets: Optional[List[UUID]] = None, labels: Optional[Dict[str, Any]] = None, connector_requirements: Optional[ServiceConnectorRequirements] = None, connector: Optional[UUID] = None, connector_resource_id: Optional[str] = None, *args: Any, **kwargs: Any)
Bases: BaseSandbox
Docker daemon-backed sandbox.
Source code in src/zenml/stack/stack_component.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
config: DockerSandboxConfig
property
Docker sandbox configuration.
Returns:
| Type | Description |
|---|---|
DockerSandboxConfig
|
The Docker sandbox configuration. |
docker_client: DockerClient
property
Initialize and/or return the docker client.
Returns:
| Type | Description |
|---|---|
DockerClient
|
The docker client. |
docker_engine: DockerContainerEngine
property
Initialize and/or return the docker engine.
Returns:
| Type | Description |
|---|---|
DockerContainerEngine
|
The docker engine. |
settings_class: Optional[Type[BaseSandboxSettings]]
property
Settings class.
Returns:
| Type | Description |
|---|---|
Optional[Type[BaseSandboxSettings]]
|
|
attach(session_id: str) -> SandboxSession
Attach to a running Docker sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The ID of the running sandbox session. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no running session with the given ID exists. |
Returns:
| Type | Description |
|---|---|
SandboxSession
|
Sandbox session. |
Source code in src/zenml/sandboxes/docker_sandbox.py
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |
create_session(settings: Optional[BaseSandboxSettings] = None, destroy_on_exit: bool = False) -> SandboxSession
Create a Docker sandbox session backed by a new container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Optional[BaseSandboxSettings]
|
Optional settings overrides. |
None
|
destroy_on_exit
|
bool
|
Whether to destroy the sandbox session when the session context manager exits. |
False
|
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A Docker sandbox session. |
Source code in src/zenml/sandboxes/docker_sandbox.py
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 | |
restore(snapshot: SandboxSnapshot) -> SandboxSession
Restore a sandbox session from a snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot
|
SandboxSnapshot
|
The snapshot to restore from. |
required |
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A new session started from the snapshot image. |
Source code in src/zenml/sandboxes/docker_sandbox.py
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 | |
DockerSandboxConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSandboxConfig, DockerSandboxSettings
Docker sandbox configuration.
Source code in src/zenml/stack/stack_component.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
is_local: bool
property
Whether this sandbox component is running locally.
Returns:
| Type | Description |
|---|---|
bool
|
Whether this sandbox component is running locally. |
DockerSandboxFlavor
Bases: BaseSandboxFlavor
Docker sandbox flavor.
config_class: Type[DockerSandboxConfig]
property
docs_url: Optional[str]
property
Docs URL.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The docs URL. |
implementation_class: Type[DockerSandbox]
property
logo_url: str
property
Dashboard logo URL.
Returns:
| Type | Description |
|---|---|
str
|
The flavor logo URL. |
name: str
property
Flavor name.
Returns:
| Type | Description |
|---|---|
str
|
The flavor name. |
sdk_docs_url: Optional[str]
property
SDK docs URL.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The flavor SDK docs URL. |
DockerSandboxProcess(client: APIClient, container_id: str, exec_id: str, pid_file: str, session: DockerSandboxSession, started_at: float)
Bases: SandboxProcess
Docker sandbox process wrapping an exec instance.
Initialize the Docker sandbox process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
APIClient
|
Low-level Docker API client. |
required |
container_id
|
str
|
ID of the container the command runs in. |
required |
exec_id
|
str
|
ID of the exec instance running the command. |
required |
pid_file
|
str
|
Path of the file inside the container that the command pid was recorded to. |
required |
session
|
DockerSandboxSession
|
The owning session. |
required |
started_at
|
float
|
The wall-clock time the process started. |
required |
Source code in src/zenml/sandboxes/docker_sandbox.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
exit_code: Optional[int]
property
Exit code, or None if the command is still running.
Returns:
| Type | Description |
|---|---|
Optional[int]
|
The exit code or |
kill() -> None
Terminate the command by killing its recorded pid.
Source code in src/zenml/sandboxes/docker_sandbox.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
stderr() -> Iterator[str]
Stderr line iterator.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
Stderr line iterator. |
Source code in src/zenml/sandboxes/docker_sandbox.py
272 273 274 275 276 277 278 279 280 | |
stdout() -> Iterator[str]
Stdout line iterator.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
Stdout line iterator. |
Source code in src/zenml/sandboxes/docker_sandbox.py
262 263 264 265 266 267 268 269 270 | |
wait(timeout: Optional[float] = None) -> int
Wait for command completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
Optional[float]
|
Timeout in seconds to wait. |
None
|
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the command did not finish in time. |
Returns:
| Type | Description |
|---|---|
int
|
The exit code. |
Source code in src/zenml/sandboxes/docker_sandbox.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
DockerSandboxPullPolicy
DockerSandboxSession(container: Container, workdir: str, env: Dict[str, str], *, parent: BaseSandbox, destroy_on_exit: bool = False, id: str)
Bases: SandboxSession
Docker sandbox session backed by a container.
Initialize the Docker sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
Container
|
The running container backing this session. |
required |
workdir
|
str
|
Working directory inside the container. |
required |
env
|
Dict[str, str]
|
Environment variables to set for this session. |
required |
parent
|
BaseSandbox
|
The sandbox component that created this session. |
required |
destroy_on_exit
|
bool
|
Whether to destroy the sandbox session when the session context manager exits. |
False
|
id
|
str
|
Session ID. |
required |
Source code in src/zenml/sandboxes/docker_sandbox.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
DockerSandboxSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: ContainerizedSandboxSettings
Docker sandbox settings.
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
Functions:
local_sandbox
Local sandbox flavor.
Classes
LocalSandbox(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, environment: Optional[Dict[str, str]] = None, secrets: Optional[List[UUID]] = None, labels: Optional[Dict[str, Any]] = None, connector_requirements: Optional[ServiceConnectorRequirements] = None, connector: Optional[UUID] = None, connector_resource_id: Optional[str] = None, *args: Any, **kwargs: Any)
Bases: BaseSandbox
Local subprocess-based Sandbox.
Warning: This class does NOT provide any isolation and is not suitable for running untrusted code.
Source code in src/zenml/stack/stack_component.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
config: LocalSandboxConfig
property
Local sandbox configuration.
Returns:
| Type | Description |
|---|---|
LocalSandboxConfig
|
The local sandbox configuration. |
settings_class: Optional[Type[BaseSandboxSettings]]
property
create_session(settings: Optional[BaseSandboxSettings] = None, destroy_on_exit: bool = False) -> SandboxSession
Create a local sandbox session in a clean working directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
Optional[BaseSandboxSettings]
|
Optional settings overrides. |
None
|
destroy_on_exit
|
bool
|
Whether to destroy the sandbox session when the session context manager exits. |
False
|
Returns:
| Type | Description |
|---|---|
SandboxSession
|
A local sandbox session. |
Source code in src/zenml/sandboxes/local_sandbox.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
LocalSandboxConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSandboxConfig, LocalSandboxSettings
Local sandbox configuration.
Source code in src/zenml/stack/stack_component.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
LocalSandboxFlavor
Bases: BaseSandboxFlavor
Local subprocess sandbox flavor.
config_class: Type[LocalSandboxConfig]
property
docs_url: Optional[str]
property
Docs URL.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The docs URL. |
implementation_class: Type[LocalSandbox]
property
logo_url: str
property
Dashboard logo URL.
Returns:
| Type | Description |
|---|---|
str
|
The flavor logo URL. |
name: str
property
Flavor name.
Returns:
| Type | Description |
|---|---|
str
|
The flavor name. |
sdk_docs_url: Optional[str]
property
SDK docs URL.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The flavor SDK docs URL. |
LocalSandboxProcess(process: subprocess.Popen[str], session: LocalSandboxSession, started_at: float)
Bases: SandboxProcess
Local sandbox process wrapping a subprocess.
Initialize the local sandbox process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
Popen[str]
|
The subprocess handle. |
required |
session
|
LocalSandboxSession
|
The owning session. |
required |
started_at
|
float
|
The wall-clock time the launch began. |
required |
Source code in src/zenml/sandboxes/local_sandbox.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
exit_code: Optional[int]
property
Exit code, or None if the subprocess is still running.
Returns:
| Type | Description |
|---|---|
Optional[int]
|
The exit code or |
kill() -> None
Kill the subprocess by sending SIGKILL.
Source code in src/zenml/sandboxes/local_sandbox.py
152 153 154 155 156 157 158 159 160 161 162 163 164 | |
stderr() -> Iterator[str]
Stderr line iterator.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
Stderr line iterator. |
Source code in src/zenml/sandboxes/local_sandbox.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
stdout() -> Iterator[str]
Stdout line iterator.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
Stdout line iterator. |
Source code in src/zenml/sandboxes/local_sandbox.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
wait(timeout: Optional[float] = None) -> int
Block until the subprocess exits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
Optional[float]
|
Timeout in seconds to wait. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The exit code. |
Source code in src/zenml/sandboxes/local_sandbox.py
141 142 143 144 145 146 147 148 149 150 | |
LocalSandboxSession(workdir: str, env: Dict[str, str], *, parent: BaseSandbox, destroy_on_exit: bool = False)
Bases: SandboxSession
Local sandbox session.
Initialize the local sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workdir
|
str
|
Absolute path to the working directory for this session. This directory is cleaned up when the session is closed. |
required |
env
|
Dict[str, str]
|
Environment variables to set for this session. |
required |
parent
|
BaseSandbox
|
The sandbox component that created this session. |
required |
destroy_on_exit
|
bool
|
Whether to destroy the sandbox session when the session context manager exits. |
False
|
Source code in src/zenml/sandboxes/local_sandbox.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
LocalSandboxSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseSandboxSettings
Local sandbox settings.
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
Functions:
process
Sandbox process.
Classes
SandboxExecError
Bases: RuntimeError
Raised when a sandbox command fails to launch.
SandboxOutput(stdout: str, stderr: str, exit_code: int, stdout_truncated: bool = False, stderr_truncated: bool = False)
dataclass
Result of fully consuming a sandbox process.
SandboxProcess(session: SandboxSession, started_at: float)
Bases: ABC
Handle to a command being executed inside a sandbox session.
Initialize the sandbox process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
SandboxSession
|
The owning session. |
required |
started_at
|
float
|
The wall-clock time the process started. |
required |
Source code in src/zenml/sandboxes/process.py
49 50 51 52 53 54 55 56 57 58 | |
exit_code: Optional[int]
abstractmethod
property
Exit code, or None if the command is still running.
collect(*, max_chars: int = _DEFAULT_COLLECT_CHAR_COUNT) -> SandboxOutput
Wait for the process to exit and return the output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_chars
|
int
|
Maximum number of characters to collect per stream. |
_DEFAULT_COLLECT_CHAR_COUNT
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the process output was already collected. The streams are drained by the first call, so a second call would fabricate an empty result instead of the real output. |
drain_exception
|
Re-raised from a failed stdout or stderr drain. |
Returns:
| Type | Description |
|---|---|
SandboxOutput
|
The output of the process. |
Source code in src/zenml/sandboxes/process.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
kill() -> None
abstractmethod
Terminates the process.
Source code in src/zenml/sandboxes/process.py
87 88 89 | |
stderr() -> Iterator[str]
abstractmethod
Yield stderr lines.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator over standard error lines. |
Source code in src/zenml/sandboxes/process.py
68 69 70 71 72 73 74 | |
stdout() -> Iterator[str]
abstractmethod
Yield stdout lines.
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator over standard output lines. |
Source code in src/zenml/sandboxes/process.py
60 61 62 63 64 65 66 | |
wait(timeout: Optional[float] = None) -> int
abstractmethod
Blocks until the process exits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
Optional[float]
|
Timeout in seconds to wait. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The exit code. |
Source code in src/zenml/sandboxes/process.py
76 77 78 79 80 81 82 83 84 85 | |
Functions:
session
Sandbox session.
Classes
SandboxSession(*, id: str, parent: BaseSandbox, destroy_on_exit: bool = False)
Bases: ABC
Sandbox session.
Initialize the sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
Session identifier. |
required |
parent
|
BaseSandbox
|
The sandbox component that created this session. |
required |
destroy_on_exit
|
bool
|
Whether to destroy the sandbox session when the session context manager exits. |
False
|
Source code in src/zenml/sandboxes/session.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
closed: bool
property
Whether this session handle has been closed.
Returns:
| Type | Description |
|---|---|
bool
|
|
aexec(command: Union[str, List[str]], *, cwd: Optional[str] = None, env: Optional[Dict[str, str]] = None) -> SandboxProcess
async
Async execute a command in the sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
Union[str, List[str]]
|
The command to execute. |
required |
cwd
|
Optional[str]
|
Optional working directory override. |
None
|
env
|
Optional[Dict[str, str]]
|
Optional environment variables to set in the environment executing the command. |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the sandbox does not support async exec. |
Returns:
| Type | Description |
|---|---|
SandboxProcess
|
Process handle. |
Source code in src/zenml/sandboxes/session.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
close() -> None
Close the sandbox session handle. Terminal and idempotent.
After closing, the session handle rejects further use (exec,
snapshots, file transfer) — re-attach to the sandbox for a fresh
handle. For remote sandboxes, closing does not terminate the
sandbox on the provider: it keeps running until its TTL expires
or destroy() is called.
Source code in src/zenml/sandboxes/session.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
create_snapshot() -> SandboxSnapshot
Create a snapshot of the sandbox session.
Returns:
| Type | Description |
|---|---|
SandboxSnapshot
|
A sandbox snapshot. |
Source code in src/zenml/sandboxes/session.py
163 164 165 166 167 168 169 170 | |
destroy() -> None
Destroy the sandbox session. Terminal like close().
Terminates the sandbox on the provider and then closes this
handle, so after a successful call it is no longer possible to
attach to the session. Flavor failures (including
NotImplementedError from flavors without destroy support)
propagate and leave the handle open for retry, because the
flavor hook runs before close(). Callable on an
already-closed handle: close() is idempotent.
Source code in src/zenml/sandboxes/session.py
260 261 262 263 264 265 266 267 268 269 270 271 272 | |
download_file(remote_path: str, local_path: str) -> None
Download a file from the sandbox to the local filesystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
remote_path
|
str
|
Source path in the sandbox. |
required |
local_path
|
str
|
Destination path on the caller's filesystem. |
required |
Source code in src/zenml/sandboxes/session.py
210 211 212 213 214 215 216 217 218 | |
exec(command: Union[str, List[str]], *, cwd: Optional[str] = None, env: Optional[Dict[str, str]] = None) -> SandboxProcess
Execute a command in the sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
Union[str, List[str]]
|
The command to execute. |
required |
cwd
|
Optional[str]
|
Optional working directory override. |
None
|
env
|
Optional[Dict[str, str]]
|
Optional environment variables to set in the environment executing the command. |
None
|
Returns:
| Type | Description |
|---|---|
SandboxProcess
|
Process handle. |
Source code in src/zenml/sandboxes/session.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
upload_file(local_path: str, remote_path: str) -> None
Upload a file to the sandbox session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_path
|
str
|
Source path on the caller's filesystem. |
required |
remote_path
|
str
|
Destination path in the sandbox. |
required |
Source code in src/zenml/sandboxes/session.py
186 187 188 189 190 191 192 193 194 | |
SandboxSessionClosedError
Bases: RuntimeError
Raised when a closed sandbox session is used.
Functions:
snapshot
Sandbox snapshot.
Classes
SandboxSnapshot
Bases: BaseModel
Sandbox snapshot.