Duibonduil commited on
Commit
df1fe5f
·
verified ·
1 Parent(s): 11430f7

Upload 4 files

Browse files
aworld/sandbox/api/__init__.py ADDED
File without changes
aworld/sandbox/api/apibase.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from abc import ABC
2
+
3
+
4
+ class SandboxApiBase(ABC):
5
+
6
+ @staticmethod
7
+ def _get_sandbox_id(sandbox_id: str) -> str:
8
+ return f"{sandbox_id}"
aworld/sandbox/api/base_sandbox_api.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import abc
2
+ from typing import Dict, List, Any, Optional
3
+
4
+ from aworld.sandbox.models import SandboxStatus, SandboxEnvType, SandboxInfo, SandboxCreateResponse, EnvConfig
5
+ from aworld.sandbox.api.apibase import SandboxApiBase
6
+
7
+
8
+ class BaseSandboxApi(SandboxApiBase, abc.ABC):
9
+ """
10
+ Base class for sandbox API implementations.
11
+ Defines the interface for interacting with different types of sandboxes.
12
+ """
13
+
14
+ @classmethod
15
+ @abc.abstractmethod
16
+ def _create_sandbox(
17
+ cls,
18
+ env_type: int,
19
+ env_config: EnvConfig,
20
+ mcp_servers: Optional[List[str]] = None,
21
+ mcp_config: Optional[Any] = None,
22
+ ) -> SandboxCreateResponse:
23
+ """
24
+ Create a sandbox based on the environment type and configuration.
25
+
26
+ Args:
27
+ env_type: The environment type (LOCAL, K8S, SUPERCOMPUTER).
28
+ env_config: Environment configuration.
29
+ mcp_servers: List of MCP servers to use.
30
+ mcp_config: Configuration for MCP servers.
31
+
32
+ Returns:
33
+ SandboxCreateResponse: Response containing sandbox information.
34
+ """
35
+ pass
36
+
37
+ @classmethod
38
+ @abc.abstractmethod
39
+ def _get_mcp_configs(
40
+ cls,
41
+ mcp_servers: Optional[List[str]] = None,
42
+ mcp_config: Optional[Any] = None,
43
+ metadata: Optional[Dict[str, str]] = None,
44
+ env_type: Optional[int] = None,
45
+ ) -> Any:
46
+ """
47
+ Get MCP configurations for the sandbox.
48
+
49
+ Args:
50
+ mcp_servers: List of MCP servers to use.
51
+ mcp_config: Configuration for MCP servers.
52
+ metadata: Additional metadata for the sandbox.
53
+ env_type: The environment type.
54
+
55
+ Returns:
56
+ Any: Updated MCP configuration.
57
+ """
58
+ pass
59
+
60
+ @classmethod
61
+ @abc.abstractmethod
62
+ async def _remove_sandbox(
63
+ cls,
64
+ sandbox_id: Optional[str] = None,
65
+ metadata: Optional[Dict[str, str]] = None,
66
+ env_type: Optional[int] = None,
67
+ ) -> bool:
68
+ """
69
+ Remove the sandbox and clean up resources.
70
+
71
+ Args:
72
+ sandbox_id: Unique identifier for the sandbox.
73
+ metadata: Metadata for the sandbox.
74
+ env_type: The environment type.
75
+
76
+ Returns:
77
+ bool: True if removal was successful, False otherwise.
78
+ """
79
+ pass
aworld/sandbox/api/setup.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from abc import ABC, abstractmethod
2
+
3
+
4
+ class SandboxSetup(ABC):
5
+
6
+
7
+ default_sandbox_timeout = 3000
8
+ default_template = "api"
9
+
10
+ @property
11
+ @abstractmethod
12
+ def sandbox_id(self) -> str:
13
+ ...