diff --git a/api/core/sandbox/builder.py b/api/core/sandbox/builder.py index d403f4da5b..9edf54005b 100644 --- a/api/core/sandbox/builder.py +++ b/api/core/sandbox/builder.py @@ -113,10 +113,21 @@ class SandboxBuilder: assets_id=self._assets_id, ) + """ + # Run synchronous initializers before marking sandbox as ready. + """ + for init in self._initializers: + if init.async_initialize(): + continue + init.initialize(sandbox) + # Run sandbox setup asynchronously so workflow execution can proceed. def initialize() -> None: try: for init in self._initializers: + if not init.async_initialize(): + continue + if sandbox.is_cancelled(): return init.initialize(sandbox) diff --git a/api/core/sandbox/initializer/base.py b/api/core/sandbox/initializer/base.py index c2213d9714..ba358e7371 100644 --- a/api/core/sandbox/initializer/base.py +++ b/api/core/sandbox/initializer/base.py @@ -6,3 +6,9 @@ from core.sandbox.sandbox import Sandbox class SandboxInitializer(ABC): @abstractmethod def initialize(self, env: Sandbox) -> None: ... + + def async_initialize(self) -> bool: + """ + Whether the initializer needs to run asynchronously. + """ + return False