langchain-daytona 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""Daytona sandbox backend implementation."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import time
|
|
7
|
+
from typing import TYPE_CHECKING, Any
|
|
8
|
+
|
|
9
|
+
from daytona import Daytona, DaytonaConfig, FileDownloadRequest, FileUpload
|
|
10
|
+
from deepagents.backends.protocol import (
|
|
11
|
+
ExecuteResponse,
|
|
12
|
+
FileDownloadResponse,
|
|
13
|
+
FileUploadResponse,
|
|
14
|
+
SandboxBackendProtocol,
|
|
15
|
+
)
|
|
16
|
+
from deepagents.backends.sandbox import (
|
|
17
|
+
BaseSandbox,
|
|
18
|
+
SandboxListResponse,
|
|
19
|
+
SandboxProvider,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from daytona import Sandbox
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class DaytonaBackend(BaseSandbox):
|
|
27
|
+
"""Daytona backend implementation conforming to SandboxBackendProtocol.
|
|
28
|
+
|
|
29
|
+
This implementation inherits all file operation methods from BaseSandbox
|
|
30
|
+
and only implements the execute() method using Daytona's API.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, sandbox: Sandbox) -> None:
|
|
34
|
+
"""Create a backend wrapping an existing Daytona sandbox."""
|
|
35
|
+
self._sandbox = sandbox
|
|
36
|
+
self._timeout: int = 30 * 60
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def id(self) -> str:
|
|
40
|
+
"""Return the Daytona sandbox id."""
|
|
41
|
+
return self._sandbox.id
|
|
42
|
+
|
|
43
|
+
def execute(
|
|
44
|
+
self,
|
|
45
|
+
command: str,
|
|
46
|
+
) -> ExecuteResponse:
|
|
47
|
+
"""Execute a shell command inside the sandbox."""
|
|
48
|
+
result = self._sandbox.process.exec(command, timeout=self._timeout)
|
|
49
|
+
|
|
50
|
+
return ExecuteResponse(
|
|
51
|
+
output=result.result,
|
|
52
|
+
exit_code=result.exit_code,
|
|
53
|
+
truncated=False,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
def download_files(self, paths: list[str]) -> list[FileDownloadResponse]:
|
|
57
|
+
"""Download files from the sandbox."""
|
|
58
|
+
download_requests = [FileDownloadRequest(source=path) for path in paths]
|
|
59
|
+
daytona_responses = self._sandbox.fs.download_files(download_requests)
|
|
60
|
+
|
|
61
|
+
return [
|
|
62
|
+
FileDownloadResponse(
|
|
63
|
+
path=resp.source,
|
|
64
|
+
content=resp.result,
|
|
65
|
+
error=None,
|
|
66
|
+
)
|
|
67
|
+
for resp in daytona_responses
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
def upload_files(self, files: list[tuple[str, bytes]]) -> list[FileUploadResponse]:
|
|
71
|
+
"""Upload files into the sandbox."""
|
|
72
|
+
upload_requests = [
|
|
73
|
+
FileUpload(source=content, destination=path) for path, content in files
|
|
74
|
+
]
|
|
75
|
+
self._sandbox.fs.upload_files(upload_requests)
|
|
76
|
+
|
|
77
|
+
return [FileUploadResponse(path=path, error=None) for path, _ in files]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class DaytonaProvider(SandboxProvider[dict[str, Any]]):
|
|
81
|
+
"""Daytona sandbox provider implementation."""
|
|
82
|
+
|
|
83
|
+
def __init__(self, api_key: str | None = None) -> None:
|
|
84
|
+
"""Create a provider backed by the Daytona SDK."""
|
|
85
|
+
self._api_key = api_key or os.environ.get("DAYTONA_API_KEY")
|
|
86
|
+
if not self._api_key:
|
|
87
|
+
msg = "DAYTONA_API_KEY environment variable not set"
|
|
88
|
+
raise ValueError(msg)
|
|
89
|
+
self._client = Daytona(DaytonaConfig(api_key=self._api_key))
|
|
90
|
+
|
|
91
|
+
def list(
|
|
92
|
+
self,
|
|
93
|
+
*,
|
|
94
|
+
cursor: str | None = None,
|
|
95
|
+
**kwargs: Any,
|
|
96
|
+
) -> SandboxListResponse[dict[str, Any]]:
|
|
97
|
+
"""List sandboxes (not yet implemented for Daytona SDK)."""
|
|
98
|
+
if cursor is not None:
|
|
99
|
+
msg = "DaytonaProvider.list() does not support cursor"
|
|
100
|
+
raise ValueError(msg)
|
|
101
|
+
if kwargs:
|
|
102
|
+
keys = sorted(kwargs.keys())
|
|
103
|
+
msg = f"DaytonaProvider.list() got unsupported kwargs: {keys}"
|
|
104
|
+
raise ValueError(msg)
|
|
105
|
+
msg = "Listing with Daytona SDK not yet implemented"
|
|
106
|
+
raise NotImplementedError(msg)
|
|
107
|
+
|
|
108
|
+
def get_or_create(
|
|
109
|
+
self,
|
|
110
|
+
*,
|
|
111
|
+
sandbox_id: str | None = None,
|
|
112
|
+
timeout: int = 180,
|
|
113
|
+
**kwargs: Any,
|
|
114
|
+
) -> SandboxBackendProtocol:
|
|
115
|
+
"""Create a new sandbox and wait until it's ready."""
|
|
116
|
+
if kwargs:
|
|
117
|
+
keys = sorted(kwargs.keys())
|
|
118
|
+
msg = f"DaytonaProvider.get_or_create() got unsupported kwargs: {keys}"
|
|
119
|
+
raise ValueError(msg)
|
|
120
|
+
if sandbox_id:
|
|
121
|
+
msg = (
|
|
122
|
+
"Connecting to existing Daytona sandbox by ID not yet supported. "
|
|
123
|
+
"Create a new sandbox by omitting sandbox_id parameter."
|
|
124
|
+
)
|
|
125
|
+
raise NotImplementedError(msg)
|
|
126
|
+
|
|
127
|
+
sandbox = self._client.create()
|
|
128
|
+
|
|
129
|
+
for _ in range(timeout // 2):
|
|
130
|
+
try:
|
|
131
|
+
result = sandbox.process.exec("echo ready", timeout=5)
|
|
132
|
+
if result.exit_code == 0:
|
|
133
|
+
break
|
|
134
|
+
except Exception: # noqa: BLE001
|
|
135
|
+
# Ok: startup errors vary; we retry then timeout.
|
|
136
|
+
time.sleep(2)
|
|
137
|
+
continue
|
|
138
|
+
time.sleep(2)
|
|
139
|
+
else:
|
|
140
|
+
try:
|
|
141
|
+
sandbox.delete()
|
|
142
|
+
finally:
|
|
143
|
+
msg = f"Daytona sandbox failed to start within {timeout} seconds"
|
|
144
|
+
raise RuntimeError(msg)
|
|
145
|
+
|
|
146
|
+
return DaytonaBackend(sandbox)
|
|
147
|
+
|
|
148
|
+
def delete(self, *, sandbox_id: str, **kwargs: Any) -> None:
|
|
149
|
+
"""Delete a sandbox by id."""
|
|
150
|
+
if kwargs:
|
|
151
|
+
keys = sorted(kwargs.keys())
|
|
152
|
+
msg = f"DaytonaProvider.delete() got unsupported kwargs: {keys}"
|
|
153
|
+
raise ValueError(msg)
|
|
154
|
+
sandbox = self._client.get(sandbox_id)
|
|
155
|
+
self._client.delete(sandbox)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: langchain_daytona
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Daytona sandbox integration for deepagents
|
|
5
|
+
Project-URL: Homepage, https://github.com/langchain-ai/deepagents/tree/master/libs/partners/daytona
|
|
6
|
+
Project-URL: Repository, https://github.com/langchain-ai/deepagents
|
|
7
|
+
Project-URL: Documentation, https://github.com/langchain-ai/deepagents/tree/master/libs/partners/daytona
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Requires-Python: <4.0,>=3.11
|
|
19
|
+
Requires-Dist: daytona
|
|
20
|
+
Requires-Dist: deepagents
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# langchain_daytona
|
|
24
|
+
|
|
25
|
+
Daytona sandbox integration for deepagents.
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install langchain_daytona
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from langchain_daytona import DaytonaProvider
|
|
37
|
+
|
|
38
|
+
provider = DaytonaProvider()
|
|
39
|
+
sandbox = provider.get_or_create()
|
|
40
|
+
result = sandbox.execute("echo hello")
|
|
41
|
+
print(result.output)
|
|
42
|
+
```
|
|
43
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
langchain_daytona/__init__.py,sha256=zYNDZMMXcOsKxeZo1hf5ms2mxV_ZMghGmyjRN6hSm7Q,170
|
|
2
|
+
langchain_daytona/sandbox.py,sha256=YJtSmCdkjWe81q_vdEqOXW8--16af0uwvXyF-fYdeYY,5160
|
|
3
|
+
langchain_daytona-0.0.1.dist-info/METADATA,sha256=CBVL51BwS5_bYSXOK2uRSo-faFSjhHU2f_KdO2eprqo,1275
|
|
4
|
+
langchain_daytona-0.0.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
5
|
+
langchain_daytona-0.0.1.dist-info/licenses/LICENSE,sha256=TsZ-TKbmch26hJssqCJhWXyGph7iFLvyFBYAa3stBHg,1067
|
|
6
|
+
langchain_daytona-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) LangChain, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|