1616import json
1717import os
1818from functools import wraps
19- from typing import Any , Callable , Dict , List , Optional , Union
19+ from typing import Any , Callable , Dict , List , Literal , Optional , Union
2020
2121from pydantic import BaseModel
2222
2626
2727logger = get_logger (__name__ )
2828
29+ _DEFAULT_IMAGES : Dict [str , str ] = {
30+ "python" : "python:3.11" ,
31+ "typescript" : "node:20" ,
32+ "javascript" : "node:20" ,
33+ }
34+
2935
3036class DaytonaRuntime (BaseRuntime ):
3137 r"""A runtime that executes functions in a Daytona sandbox environment.
@@ -39,22 +45,32 @@ class DaytonaRuntime(BaseRuntime):
3945 provided, it will try to use the DAYTONA_API_URL environment
4046 variable. If none is provided, it will use "http://localhost:8000".
4147 (default: :obj:`None`)
42- language (Optional[str]): The programming language for the sandbox.
48+ language (Optional[Literal["python", "typescript", "javascript"]]):
49+ The programming language for the sandbox.
4350 (default: :obj:`"python"`)
51+ image (Optional[str]): The Docker image to use for the sandbox.
52+ If not provided, a default image based on the language will be
53+ used. (default: :obj:`None`)
4454 """
4555
4656 def __init__ (
4757 self ,
4858 api_key : Optional [str ] = None ,
4959 api_url : Optional [str ] = None ,
50- language : Optional [str ] = "python" ,
60+ language : Optional [
61+ Literal ["python" , "typescript" , "javascript" ]
62+ ] = "python" ,
63+ image : Optional [str ] = None ,
5164 ):
5265 from daytona_sdk import Daytona , DaytonaConfig , Sandbox
5366
5467 super ().__init__ ()
5568 self .api_key = api_key or os .environ .get ('DAYTONA_API_KEY' )
5669 self .api_url = api_url or os .environ .get ('DAYTONA_API_URL' )
5770 self .language = language
71+ self .image = image or _DEFAULT_IMAGES .get (
72+ language or "python" , "python:3.11"
73+ )
5874 self .config = DaytonaConfig (api_key = self .api_key , api_url = self .api_url )
5975 self .daytona = Daytona (self .config )
6076 self .sandbox : Optional [Sandbox ] = None
@@ -66,10 +82,12 @@ def build(self) -> "DaytonaRuntime":
6682 Returns:
6783 DaytonaRuntime: The current runtime.
6884 """
69- from daytona_sdk import CreateSandboxBaseParams
85+ from daytona_sdk import CreateSandboxFromImageParams
7086
7187 try :
72- params = CreateSandboxBaseParams (language = self .language )
88+ params = CreateSandboxFromImageParams (
89+ image = self .image , language = self .language
90+ )
7391 self .sandbox = self .daytona .create (params )
7492 if self .sandbox is None :
7593 raise RuntimeError ("Failed to create sandbox." )
0 commit comments