Skip to main content
Handles creation and management of Daytona sandboxes for code execution.

react_agent.utils.sandboxes.ValidationSandbox Objects

View Source Manager class for Daytona validation sandboxes. This class tracks active container instances and handles the lifecycle of building and restoring runtime environment snapshots (e.g., pulling Docker images and installing dependencies). It ensures that validation steps execute in a clean, consistent sandbox environment, while minimizing startup latency via snapshot caching.

ValidationSandbox.get_sandbox

View Source Retrieve or create an active validation sandbox, ensuring that the base environment snapshot is loaded. Arguments:
  • daytona - The AsyncDaytona API client instance.
  • sandbox_type - The type of sandbox runtime container needed (.NET or Java).
  • stream_writer - Callback to stream snapshot compilation and startup progress events back to client.
  • env_vars - Optional dictionary of environment variables to inject into the sandbox.
Returns:
  • AsyncSandbox - The active, fully initialized AsyncSandbox container.

ValidationSandbox.create_snapshot

View Source Create and cache a Daytona snapshot for the specified sandbox architecture. A snapshot acts as a baseline environment (e.g., pre-installing Maven or downloading the .NET SDK). This function checks if a snapshot named validation-snapshot-<type> already exists. If not, it instructs the Daytona daemon to build one based on the configuration in DAYTONA_SANDBOX_IMAGES, streaming the build logs back to the LangGraph UI. Arguments:
  • daytona AsyncDaytona - The asynchronous Daytona API client.
  • sandbox_type SandboxType - The target architecture.
  • stream_writer Callable[[Any], None] - Callback to stream logs to the UI.
Raises:
  • Exception - If snapshot creation fails after multiple exponential backoff retries.

ValidationSandbox.create_validation_sandbox

View Source Provision and start a Daytona sandbox container based on the cached snapshot. This complex lifecycle manager ensures that a sandbox container named validation-sandbox-<type> is actively running. It robustly handles Daytona state machine transitions (e.g., cleaning up stuck ERROR/DESTROYING states, waiting for PENDING_BUILD, or waking up a STOPPED container). Arguments:
  • daytona AsyncDaytona - The asynchronous Daytona API client.
  • sandbox_type SandboxType - The target architecture.
  • env_vars dict[str, Any] | None, optional - Optional environment variables to inject.
Returns:
  • AsyncSandbox - The verified running sandbox instance.
Raises:
  • RuntimeError - If the sandbox cannot be transitioned to a STARTED state after max retries.