open-daytona 0.1.0__tar.gz
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.
- open_daytona-0.1.0/LICENSE +202 -0
- open_daytona-0.1.0/PKG-INFO +35 -0
- open_daytona-0.1.0/README.md +229 -0
- open_daytona-0.1.0/client/README.md +19 -0
- open_daytona-0.1.0/client/open_daytona/__init__.py +4 -0
- open_daytona-0.1.0/client/open_daytona/daytona_s3_http.py +39 -0
- open_daytona-0.1.0/client/open_daytona/harbor.py +100 -0
- open_daytona-0.1.0/client/open_daytona/sbxclient.py +109 -0
- open_daytona-0.1.0/client/open_daytona.egg-info/PKG-INFO +35 -0
- open_daytona-0.1.0/client/open_daytona.egg-info/SOURCES.txt +13 -0
- open_daytona-0.1.0/client/open_daytona.egg-info/dependency_links.txt +1 -0
- open_daytona-0.1.0/client/open_daytona.egg-info/requires.txt +5 -0
- open_daytona-0.1.0/client/open_daytona.egg-info/top_level.txt +1 -0
- open_daytona-0.1.0/pyproject.toml +25 -0
- open_daytona-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: open-daytona
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Clients for open-daytona, a self-hosted Daytona-compatible sandbox pool (rootless gVisor, GPUs included): pool client, Daytona SDK build-context patch, Harbor environment
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/andylizf/open-daytona
|
|
7
|
+
Project-URL: Documentation, https://github.com/andylizf/open-daytona/blob/main/docs/daytona-compat.md
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Provides-Extra: harbor
|
|
12
|
+
Requires-Dist: harbor==0.25.0; extra == "harbor"
|
|
13
|
+
Requires-Dist: daytona<1,>=0.234; extra == "harbor"
|
|
14
|
+
Requires-Dist: pyyaml; extra == "harbor"
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# open-daytona (Python clients)
|
|
18
|
+
|
|
19
|
+
Client side of [open-daytona](https://github.com/andylizf/open-daytona), a self-hosted sandbox pool that speaks the
|
|
20
|
+
Daytona API and runs each sandbox under rootless gVisor, GPU sandboxes included. The pool itself (the node daemon and
|
|
21
|
+
the gateway) runs from a checkout of the repository; see its README.
|
|
22
|
+
|
|
23
|
+
- `open_daytona.harbor.OpenDaytonaEnvironment`: a Harbor environment for a pool. Install with the `harbor` extra and
|
|
24
|
+
run Harbor with it:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install "open-daytona[harbor]"
|
|
28
|
+
export DAYTONA_API_URL=http://<gateway>:8790/api DAYTONA_API_KEY=<pool token>
|
|
29
|
+
harbor run -e open_daytona.harbor:OpenDaytonaEnvironment -p <task> -a <agent> ...
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
It is Harbor's Daytona environment with two changes: build contexts upload over plain http, and a task whose
|
|
33
|
+
`docker-compose.yaml` only sizes `/dev/shm` and reserves GPUs runs as one sandbox instead of Docker-in-Docker.
|
|
34
|
+
- `open_daytona.daytona_s3_http`: importing it lets the Daytona SDK upload build contexts to a gateway over http.
|
|
35
|
+
- `open_daytona.sbxclient`: a standard-library client for the pool's own `/v1` API.
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(max-width: 600px) and (prefers-color-scheme: dark)" srcset="docs/assets/lockup-tag2-dark.svg">
|
|
4
|
+
<source media="(max-width: 600px)" srcset="docs/assets/lockup-tag2-light.svg">
|
|
5
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/assets/lockup-tag-dark.svg">
|
|
6
|
+
<img src="docs/assets/lockup-tag-light.svg" width="717" alt="open-daytona: High-fidelity agent sandboxes on any hardware you already have">
|
|
7
|
+
</picture>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
<a href="https://github.com/andylizf">Zhifei Li</a> · Princeton University
|
|
12
|
+
<br>
|
|
13
|
+
<a href="docs/design.md"><b>Design</b></a> · <a href="docs/api.md"><b>HTTP API</b></a> · <a href="docs/daytona-compat.md"><b>Daytona SDK</b></a> · <a href="skills/README.md"><b>Agent skills</b></a> · <a href="https://zhifei.li/open-daytona/"><b>Website</b></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<p align="center">
|
|
17
|
+
<a href="AGENTS.md"><img src="https://img.shields.io/badge/Agent--native-AGENTS.md-0F766E.svg" alt="Agent-native repository"></a>
|
|
18
|
+
<a href="docs/daytona-compat.md"><img src="https://img.shields.io/badge/Daytona_SDK-0.234.0_%C2%B7_2.3.0_tested-2A78D6.svg" alt="Daytona SDK 0.234.0 and 2.3.0 tested"></a>
|
|
19
|
+
<a href="https://gvisor.dev"><img src="https://img.shields.io/badge/runtime-gVisor-4285F4.svg" alt="Runtime: gVisor"></a>
|
|
20
|
+
<img src="https://img.shields.io/badge/Python-3.9%2B_%C2%B7_stdlib_only-3776AB.svg?logo=python&logoColor=white" alt="Python 3.9+, standard library only">
|
|
21
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache_2.0-green.svg" alt="License: Apache 2.0"></a>
|
|
22
|
+
<br>
|
|
23
|
+
<sub>Not affiliated with or endorsed by Daytona Platforms, Inc. Daytona is a trademark of its owner.</sub>
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
> [!TIP]
|
|
27
|
+
> **This is an agent-native repository.** Your coding agent (Claude Code, Codex, ...) can deploy a pool on your
|
|
28
|
+
> cluster and connect your harness to it: it reads [`AGENTS.md`](AGENTS.md) for the rules and the map of the code,
|
|
29
|
+
> and follows a [skill](skills/README.md) for each task.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
<p align="center">
|
|
34
|
+
<img src="docs/assets/demo.svg" width="100%" alt="Terminal recording: with DAYTONA_V2_API_URL pointing at an open-daytona gateway, the unmodified daytona 2.3.0 SDK creates a python:3.12-slim sandbox, runs uname and a Python one-liner in it (gVisor kernel, prints 42) and deletes it">
|
|
35
|
+
<br><sub>The unmodified <code>daytona</code> 2.3.0 SDK against a gateway and one node in a Linux VM. Real recording, played back at its recorded speed.</sub>
|
|
36
|
+
</p>
|
|
37
|
+
|
|
38
|
+
open-daytona runs isolated Linux sandboxes for agent RL inside **ordinary Slurm jobs, with no root and no Docker**,
|
|
39
|
+
and serves them through the API that the official `daytona` Python SDK speaks. The same 1,536 recorded terminal-agent
|
|
40
|
+
RL episodes were replayed on open-daytona and on Daytona's hosted service. With CPU admission on, the default, a
|
|
41
|
+
command round trip took **0.070 s** at the median against **0.156 s** on Daytona, timed from the same client machine, and **no episode ended on an
|
|
42
|
+
infrastructure error**. In a run that started all 1,536 sandboxes at once, a sandbox was ready **4.0 s** after its
|
|
43
|
+
create against **32.1 s** on Daytona. The unmodified SDK passes the repository's SDK test, **21 of 21** checks at
|
|
44
|
+
version 0.234.0 and **20 of 20** at 2.3.0.
|
|
45
|
+
|
|
46
|
+
<p align="center">
|
|
47
|
+
<picture>
|
|
48
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/assets/results-dark.svg">
|
|
49
|
+
<img src="docs/assets/results-light.svg" width="90%" alt="Bar charts. Median command round trip: open-daytona 0.070 s, Daytona 0.156 s. Median time from create to a ready sandbox: open-daytona 4.0 s, Daytona 32.1 s.">
|
|
50
|
+
</picture>
|
|
51
|
+
<br><sub>open-daytona's median command round trip is under half of Daytona's, and its median time to a ready sandbox under an eighth. Command times come from the run with CPU admission (at most one running sandbox per 0.8 core, the rest queued), create times from the run that started all 1,536 sandboxes at once; <a href="#results">Results</a> gives each run's setup.</sub>
|
|
52
|
+
</p>
|
|
53
|
+
|
|
54
|
+
## About
|
|
55
|
+
|
|
56
|
+
open-daytona turns a cluster's nodes into a sandbox service, CPU nodes for most sandboxes and NVIDIA GPU nodes for those
|
|
57
|
+
that ask for GPUs ([design.md](docs/design.md#gpus)), through three designs:
|
|
58
|
+
|
|
59
|
+
1. **gVisor with no privileges.** [gVisor](https://gvisor.dev) is a kernel written in Go that runs in user space and
|
|
60
|
+
serves each sandbox's system calls. The node daemon re-executes itself under `unshare -Ur`, so gVisor's runtime,
|
|
61
|
+
`runsc`, runs as root of a user namespace of its own. It needs no setuid helper, and neither of the two things
|
|
62
|
+
rootless Docker and Podman rely on an administrator for: a subuid range and a delegated cgroup. The nodes need only
|
|
63
|
+
unprivileged user namespaces enabled. Each sandbox gets its own network stack, a disk cap with ENOSPC inside it,
|
|
64
|
+
and a memory limit that kills its largest process with exit code 137 while the sandbox lives on.
|
|
65
|
+
2. **A pool made of Slurm jobs.** Pilot jobs turn ordinary allocations into capacity. Dockerfiles are built once per
|
|
66
|
+
pool into a shared image cache, and one gateway places each create on the least-loaded node, preferring one that
|
|
67
|
+
has the image. The gateway runs sandboxes at 0.8 core each and queues further creates in FIFO order, the
|
|
68
|
+
density at which timing-sensitive tests and RL rewards matched Daytona.
|
|
69
|
+
3. **The Daytona SDK as the client.** Both protocols of the official `daytona` Python SDK, 0.x (the line Harbor pins;
|
|
70
|
+
unmodified Harbor passed 78 of Terminal-Bench 2.0's 89 tasks through it with the oracle agent, see [daytona-compat.md](docs/daytona-compat.md#harbor-on-terminal-bench-20)) and 2.x (what a plain `pip install daytona` gives), work unmodified, alongside the pool's own `/v1` API, a
|
|
71
|
+
standard-library client and an asyncio adapter for RL harnesses.
|
|
72
|
+
|
|
73
|
+
### Overview
|
|
74
|
+
|
|
75
|
+
<p align="center">
|
|
76
|
+
<picture>
|
|
77
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/assets/architecture-dark.svg">
|
|
78
|
+
<img src="docs/assets/architecture-light.svg" width="100%" alt="Architecture: RL rollout workers (daytona SDK, sbxclient.py, rl_adapter.py) send HTTP requests to gateway.py, which serves the pool's own API and both Daytona protocols, admits sandboxes at 0.8 core each in FIFO order and places them by load and cached image. The gateway forwards to pilot jobs on a Slurm cluster, each running sbxd.py under unshare -Ur with several gVisor sandboxes, and the pilots share one image cache.">
|
|
79
|
+
</picture>
|
|
80
|
+
</p>
|
|
81
|
+
|
|
82
|
+
Rollout workers call one gateway over HTTP with a bearer token. The gateway forwards each call to the node daemon
|
|
83
|
+
(`sbxd.py`) that holds the sandbox; each daemon runs inside one Slurm pilot job and starts gVisor sandboxes there,
|
|
84
|
+
with `builder.py` pulling and building images, `memenforce.py` holding each sandbox to its memory limit and
|
|
85
|
+
`netproxy.py` connecting each sandbox's network stack to the node's network. The
|
|
86
|
+
daemon and the gateway speak the same API ([docs/api.md](docs/api.md)), so a client can use one node directly or the
|
|
87
|
+
whole pool through the gateway. When the gateway cannot reach the compute nodes, reverse SSH tunnels carry the traffic
|
|
88
|
+
([docs/relay.md](docs/relay.md)). How each piece works and why: [docs/design.md](docs/design.md).
|
|
89
|
+
|
|
90
|
+
## Getting started
|
|
91
|
+
|
|
92
|
+
> [!TIP]
|
|
93
|
+
> To set up a pool with a coding agent, ask it: "Deploy an open-daytona pool on our Slurm cluster, following
|
|
94
|
+
> `skills/deploy-pool/SKILL.md`." Then: "Point our harness at the pool, following `skills/connect-sdk/SKILL.md`."
|
|
95
|
+
> Each skill checks every step and reports what it ran.
|
|
96
|
+
|
|
97
|
+
### Requirements
|
|
98
|
+
|
|
99
|
+
- Linux on x86_64 or aarch64 with unprivileged user namespaces (`unshare -Ur true` works).
|
|
100
|
+
- Python 3.9 or newer, standard library only; `curl`, `bzip2`, `tar`; `lz4` for the shared image cache.
|
|
101
|
+
- Tens of GB of node-local disk.
|
|
102
|
+
- For a pool: Slurm, and a filesystem shared by the login node and the compute nodes.
|
|
103
|
+
|
|
104
|
+
### Quickstart: one node
|
|
105
|
+
|
|
106
|
+
Install gVisor, create a token, and start a daemon and a gateway:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
git clone https://github.com/andylizf/open-daytona.git && cd open-daytona
|
|
110
|
+
bash sbxd/install_runsc.sh # gVisor runsc + a static busybox, into ./bin
|
|
111
|
+
mkdir -p ~/.config/open-daytona
|
|
112
|
+
(umask 077; python3 -c 'import secrets; print(secrets.token_hex(32))' > ~/.config/open-daytona/token)
|
|
113
|
+
python3 -I sbxd/sbxd.py --bind 127.0.0.1 --port 8791 --job-dir ./tmp/job --images-dir ./tmp/images \
|
|
114
|
+
--runsc ./bin/runsc --token-file ~/.config/open-daytona/token --mem-gb 16 --log ./tmp/sbxd.log &
|
|
115
|
+
python3 -I gateway/gateway.py --port 8790 --backends 127.0.0.1:8791 &
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Then create a sandbox with the unmodified Daytona SDK, as in the recording above:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
pip install daytona
|
|
122
|
+
export DAYTONA_V2_API_URL=http://127.0.0.1:8790/api/v2 DAYTONA_API_KEY=$(cat ~/.config/open-daytona/token)
|
|
123
|
+
python3 -c 'from daytona import Daytona; s = Daytona().v2.create("python:3.12-slim"); print(s.exec("echo 42").stdout); s.delete()'
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
[docs/quickstart.md](docs/quickstart.md) covers aarch64, the standard-library client, SDK 0.x, the smoke test and
|
|
127
|
+
the asyncio RL adapter.
|
|
128
|
+
|
|
129
|
+
### Running a pool on Slurm
|
|
130
|
+
|
|
131
|
+
Clone the repository on the shared filesystem (that path is `SBX_HOME`), install runsc and create the token as above,
|
|
132
|
+
and copy `slurm/open-daytona.env.example` to `$SBX_HOME/open-daytona.env` with your partition and paths. Then submit
|
|
133
|
+
pilot jobs, which register their daemons under `$SBX_HOME/registry/`, and start the gateway on that registry:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
slurm/start_pilots.sh 0:64:128 1:64:128 2:64:128 3:64:128 # one pilot job per slot:cores:mem_gb
|
|
137
|
+
python3 -I gateway/gateway.py --bind <address> --port 8790 --registry-dir $SBX_HOME/registry
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
[docs/slurm.md](docs/slurm.md) gives every step, the relay for training on another cluster, and the scripts that
|
|
141
|
+
reload pilots, stop them and change their memory limit.
|
|
142
|
+
|
|
143
|
+
## Results
|
|
144
|
+
|
|
145
|
+
Each run replayed the same 1,536 recorded terminal-agent RL episodes, with no model and no GPU;
|
|
146
|
+
[docs/results.md](docs/results.md) gives how each run was set up and measured.
|
|
147
|
+
|
|
148
|
+
| | open-daytona, all at once | open-daytona, with CPU admission | Daytona (hosted) |
|
|
149
|
+
|---|---|---|---|
|
|
150
|
+
| admission | none: all 1,536 at once | at most 323 running, the rest queued in FIFO order | none |
|
|
151
|
+
| CPU | 294 cores in all, about 0.19 core per sandbox | 259 sandbox cores, 0.8 core per sandbox | as each task requests (1 core for most, 4 for 96 of 1,536) |
|
|
152
|
+
| sandbox ready after create, median | 4.0 s | (time in the queue dominates) | 32.1 s |
|
|
153
|
+
| command round trip, median | 0.14 s | 0.070 s (172,533 commands) | 0.156 s (171,731 commands) |
|
|
154
|
+
|
|
155
|
+
[99 of 104 terminal-agent tasks' reference solutions pass; the 5 that fail also fail on Daytona](docs/results.md).
|
|
156
|
+
|
|
157
|
+
## Semantics compared with a hosted sandbox
|
|
158
|
+
|
|
159
|
+
A sandbox behaves like one on a cgroup-based hosted service, except that with no cgroup its memory limit is polled
|
|
160
|
+
and its CPU is a set of pinned cores; creates beyond the pool's CPU capacity wait in a FIFO queue.
|
|
161
|
+
[docs/semantics.md](docs/semantics.md) compares memory, CPU, working directory, network and disk side by side, and says how each client sees the queue.
|
|
162
|
+
|
|
163
|
+
## Known gaps
|
|
164
|
+
|
|
165
|
+
- [No inbound ports](docs/known-gaps.md#no-inbound-ports), so no preview links.
|
|
166
|
+
- [No Docker-in-Docker](docs/known-gaps.md#no-docker-in-docker), so no docker compose tasks.
|
|
167
|
+
- [GPU sandboxes](docs/known-gaps.md#gpu-sandboxes-nvidia-one-node-no-stop): NVIDIA only, through gVisor's nvproxy; all of a sandbox's GPUs on one node; no stop and start.
|
|
168
|
+
- [CPU is limited by core pinning](docs/known-gaps.md#cpu-is-limited-by-core-pinning), with no quota: a sandbox can use idle neighbors' cores.
|
|
169
|
+
- [The memory limit is polled](docs/known-gaps.md#memory-limit-is-polled) and can overshoot.
|
|
170
|
+
- [Memory-mapping churn, system calls](docs/known-gaps.md#memory-mapping-churn-and-system-calls) and many small file reads run slower than natively.
|
|
171
|
+
- [Network throughput](docs/known-gaps.md#network-throughput) per connection is below the node's.
|
|
172
|
+
- [Dockerfiles](docs/known-gaps.md#dockerfile-coverage): one FROM stage, and a few instructions unsupported.
|
|
173
|
+
- [Cold image builds](docs/known-gaps.md#cold-builds) take tens of seconds to minutes per image, once per pool.
|
|
174
|
+
- [C-c after typed-ahead input](docs/known-gaps.md#c-c-behind-an-unread-terminal-line) raises no SIGINT on upstream gVisor; the default x86_64 runsc fixes it.
|
|
175
|
+
- [One gateway over plain HTTP](docs/known-gaps.md#one-gateway-over-plain-http): run it on a trusted network.
|
|
176
|
+
- [Daytona SDK](docs/known-gaps.md#daytona-sdk): some setters are accepted but not applied; calls outside the compatibility list are unsupported.
|
|
177
|
+
|
|
178
|
+
## Record and replay
|
|
179
|
+
|
|
180
|
+
`replay/` records agent episodes, replays them against a sandbox backend with no model, and compares what the
|
|
181
|
+
environment returned across runs. Usage: [replay/README.md](replay/README.md).
|
|
182
|
+
|
|
183
|
+
## Repository layout
|
|
184
|
+
|
|
185
|
+
| path | contents |
|
|
186
|
+
|---|---|
|
|
187
|
+
| `sbxd/` | node daemon, memory enforcer, image builder, network proxy, `install_runsc.sh` |
|
|
188
|
+
| `gateway/` | gateway and the Daytona-SDK layer, systemd unit example |
|
|
189
|
+
| `client/` | standard-library Python client |
|
|
190
|
+
| `slurm/` | pilot job, submit/stop/reload scripts, site config example, optional relay |
|
|
191
|
+
| `replay/` | record–replay parity tools ([`replay/README.md`](replay/README.md)) |
|
|
192
|
+
| `examples/` | asyncio RL harness adapter |
|
|
193
|
+
| `patches/`, `scripts/` | the gVisor patches the default runsc carries, and the script that builds that runsc |
|
|
194
|
+
| `tests/` | single-node smoke test, Daytona SDK test, admission test |
|
|
195
|
+
| `docs/` | quickstart, Slurm pool, results, semantics, known gaps, design, API, relay, Daytona compatibility, public trial; `docs/assets/` holds the README's figures and the script that draws them |
|
|
196
|
+
| [`AGENTS.md`](AGENTS.md), [`skills/`](skills/README.md) | instructions and skills for coding agents |
|
|
197
|
+
| `site/` | the project page, deployed by `.github/workflows/pages.yml` |
|
|
198
|
+
|
|
199
|
+
## Contributing
|
|
200
|
+
|
|
201
|
+
Contributions are welcome, and a coding agent is a good way to make one:
|
|
202
|
+
|
|
203
|
+
- Point the agent at [`AGENTS.md`](AGENTS.md): the rules, the repository map and the commands to test a change.
|
|
204
|
+
- A pull request states what it changes and the command and result that show it works, at the level it was checked
|
|
205
|
+
(one node, a pool, an SDK version).
|
|
206
|
+
- For a larger change, open an issue first.
|
|
207
|
+
|
|
208
|
+
<!-- Community links (Discord, Slack, Discussions) go here once a channel exists. -->
|
|
209
|
+
Questions and bug reports go to [GitHub issues](https://github.com/andylizf/open-daytona/issues).
|
|
210
|
+
|
|
211
|
+
## Citation
|
|
212
|
+
|
|
213
|
+
If you use open-daytona in your research, please cite it ([CITATION.cff](CITATION.cff)):
|
|
214
|
+
|
|
215
|
+
```bibtex
|
|
216
|
+
@software{li2026opendaytona,
|
|
217
|
+
author = {Li, Zhifei},
|
|
218
|
+
title = {open-daytona: High-Fidelity Agent Sandboxes on Any Hardware You Already Have},
|
|
219
|
+
year = {2026},
|
|
220
|
+
url = {https://github.com/andylizf/open-daytona}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
Apache-2.0 ([LICENSE](LICENSE)). gVisor, also Apache-2.0, is not in the source tree. `sbxd/install_runsc.sh` fetches
|
|
227
|
+
`runsc` from this repository's release, built from gVisor's source plus the four patches in `patches/`, and
|
|
228
|
+
checks it against a SHA-256 pinned in the script. With `--upstream` it fetches gVisor's own release and checks its
|
|
229
|
+
published SHA-512.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# open-daytona (Python clients)
|
|
2
|
+
|
|
3
|
+
Client side of [open-daytona](https://github.com/andylizf/open-daytona), a self-hosted sandbox pool that speaks the
|
|
4
|
+
Daytona API and runs each sandbox under rootless gVisor, GPU sandboxes included. The pool itself (the node daemon and
|
|
5
|
+
the gateway) runs from a checkout of the repository; see its README.
|
|
6
|
+
|
|
7
|
+
- `open_daytona.harbor.OpenDaytonaEnvironment`: a Harbor environment for a pool. Install with the `harbor` extra and
|
|
8
|
+
run Harbor with it:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install "open-daytona[harbor]"
|
|
12
|
+
export DAYTONA_API_URL=http://<gateway>:8790/api DAYTONA_API_KEY=<pool token>
|
|
13
|
+
harbor run -e open_daytona.harbor:OpenDaytonaEnvironment -p <task> -a <agent> ...
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
It is Harbor's Daytona environment with two changes: build contexts upload over plain http, and a task whose
|
|
17
|
+
`docker-compose.yaml` only sizes `/dev/shm` and reserves GPUs runs as one sandbox instead of Docker-in-Docker.
|
|
18
|
+
- `open_daytona.daytona_s3_http`: importing it lets the Daytona SDK upload build contexts to a gateway over http.
|
|
19
|
+
- `open_daytona.sbxclient`: a standard-library client for the pool's own `/v1` API.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"""open-daytona clients: the standard-library pool client (sbxclient), the Daytona SDK patch for build contexts over
|
|
2
|
+
plain http (daytona_s3_http), and a Harbor environment (harbor). The pool itself (sbxd, gateway) runs from a checkout
|
|
3
|
+
of the repository."""
|
|
4
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Let the Daytona Python SDK upload build contexts to an open-daytona gateway over plain http. Import it before the
|
|
2
|
+
SDK creates an Image with local files (Image.from_dockerfile with COPY sources, add_local_file, add_local_dir).
|
|
3
|
+
|
|
4
|
+
Why: the SDK uploads those files to S3 at the address GET /object-storage/push-access gives it (here: the gateway's
|
|
5
|
+
own S3 endpoint, gateway/daytona_compat.py), through obstore's S3Store, which refuses an http address unless
|
|
6
|
+
allow_http is set; the SDK never sets it and clears the environment while it builds the store, so no setting can.
|
|
7
|
+
This wraps the SDK's S3Store so that an http address gets allow_http. https addresses are left as they are, so
|
|
8
|
+
against a gateway behind https the SDK needs nothing. Tested with daytona 0.234.0 (and 2.x's bundled 0.x client).
|
|
9
|
+
"""
|
|
10
|
+
import importlib
|
|
11
|
+
|
|
12
|
+
_MODULES = ("daytona._async.object_storage", "daytona._sync.object_storage",
|
|
13
|
+
"daytona.v0._async.object_storage", "daytona.v0._sync.object_storage")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _allow_http(store_cls):
|
|
17
|
+
def make(*args, **kwargs):
|
|
18
|
+
if str(kwargs.get("endpoint", "")).startswith("http://"):
|
|
19
|
+
kwargs["client_options"] = dict(kwargs.get("client_options") or {}, allow_http=True)
|
|
20
|
+
return store_cls(*args, **kwargs)
|
|
21
|
+
make._open_daytona = True
|
|
22
|
+
return make
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def patch():
|
|
26
|
+
"""Wrap S3Store in every SDK object-storage module present. -> the modules patched."""
|
|
27
|
+
done = []
|
|
28
|
+
for name in _MODULES:
|
|
29
|
+
try:
|
|
30
|
+
m = importlib.import_module(name)
|
|
31
|
+
except ImportError:
|
|
32
|
+
continue
|
|
33
|
+
if not getattr(m.S3Store, "_open_daytona", False):
|
|
34
|
+
m.S3Store = _allow_http(m.S3Store)
|
|
35
|
+
done.append(name)
|
|
36
|
+
return done
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
patch()
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""Harbor environment for an open-daytona pool: Harbor's own Daytona environment (`harbor run -e daytona`) with the two
|
|
2
|
+
changes a self-hosted pool needs. Use it in place of `-e daytona`:
|
|
3
|
+
|
|
4
|
+
pip install "open-daytona[harbor]"
|
|
5
|
+
harbor run -e open_daytona.harbor:OpenDaytonaEnvironment -p <task> ...
|
|
6
|
+
|
|
7
|
+
with DAYTONA_API_URL=http://<gateway>:8790/api and DAYTONA_API_KEY=<pool token>, as for `-e daytona`
|
|
8
|
+
(docs/daytona-compat.md, "Harbor").
|
|
9
|
+
|
|
10
|
+
1. Build contexts over plain http. An image built from a Dockerfile that copies local files (a task's
|
|
11
|
+
environment/Dockerfile, a separate verifier built from tests/Dockerfile) makes the Daytona SDK upload those files to
|
|
12
|
+
S3 at the address the gateway gives it. The SDK's object store refuses an http address (it never sets allow_http)
|
|
13
|
+
and clears the environment while it builds the store, so no setting can allow it; daytona_s3_http.py, imported
|
|
14
|
+
here, sets allow_http on the SDK's store for http addresses. Against a gateway behind https it changes nothing.
|
|
15
|
+
2. A docker-compose.yaml that only sizes /dev/shm and reserves NVIDIA GPUs for the one service `main` (what a GPU task
|
|
16
|
+
writes for Harbor's docker environment) makes Harbor's Daytona environment run the task as docker compose inside
|
|
17
|
+
the sandbox (Docker-in-Docker), which open-daytona does not have, and refuse its GPUs. Such a task runs as a direct
|
|
18
|
+
sandbox here: the GPUs come from the task's `gpus` / `gpu_types` as with any task, and shm_size is passed to the
|
|
19
|
+
pool as the label open-daytona.shm_mb. Any other compose file is left to Harbor.
|
|
20
|
+
|
|
21
|
+
One option, `--ek gpu_types=H100,H200`: the GPU types a GPU task may get, in place of its task.toml `gpu_types`
|
|
22
|
+
(Harbor itself only overrides the count, --override-gpus). The task's time limits assume the types it lists.
|
|
23
|
+
|
|
24
|
+
Tested with Harbor 0.25.0 and daytona 0.234.0. Needs PyYAML, which Harbor already depends on.
|
|
25
|
+
"""
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
import re
|
|
28
|
+
|
|
29
|
+
import yaml
|
|
30
|
+
from . import daytona_s3_http # noqa: F401 (1. above: the SDK's S3 uploads over http)
|
|
31
|
+
from harbor.environments.daytona import DaytonaEnvironment
|
|
32
|
+
|
|
33
|
+
SHM_LABEL = "open-daytona.shm_mb"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _mib(size):
|
|
37
|
+
"""A compose size ("16384m", "16g", 17179869184) -> MiB."""
|
|
38
|
+
m = re.fullmatch(r"\s*(\d+(?:\.\d+)?)\s*([bkmg]?)b?\s*", str(size).lower())
|
|
39
|
+
if not m:
|
|
40
|
+
raise ValueError("unreadable shm_size %r" % size)
|
|
41
|
+
return int(float(m.group(1)) * {"": 1 / 2**20, "b": 1 / 2**20, "k": 1 / 1024, "m": 1, "g": 1024}[m.group(2)])
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def single_service_shm(compose_path):
|
|
45
|
+
"""For a compose file that only sizes /dev/shm and reserves NVIDIA GPUs for its one service `main`: its shm size in
|
|
46
|
+
MiB (0 when it gives none). None for any other compose file."""
|
|
47
|
+
try:
|
|
48
|
+
doc = yaml.safe_load(Path(compose_path).read_text()) or {}
|
|
49
|
+
except (OSError, yaml.YAMLError):
|
|
50
|
+
return None
|
|
51
|
+
services = doc.get("services") or {}
|
|
52
|
+
if set(doc) - {"services"} or set(services) != {"main"}:
|
|
53
|
+
return None
|
|
54
|
+
main = services["main"] or {}
|
|
55
|
+
if set(main) - {"shm_size", "deploy"}:
|
|
56
|
+
return None
|
|
57
|
+
deploy = main.get("deploy") or {}
|
|
58
|
+
resources = deploy.get("resources") or {}
|
|
59
|
+
reservations = resources.get("reservations") or {}
|
|
60
|
+
if set(deploy) - {"resources"} or set(resources) - {"reservations"} or set(reservations) - {"devices"}:
|
|
61
|
+
return None
|
|
62
|
+
for dev in reservations.get("devices") or []:
|
|
63
|
+
if (dev or {}).get("driver") != "nvidia" or set(dev) - {"driver", "count", "capabilities", "device_ids"}:
|
|
64
|
+
return None
|
|
65
|
+
return _mib(main["shm_size"]) if main.get("shm_size") else 0
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class OpenDaytonaEnvironment(DaytonaEnvironment):
|
|
69
|
+
"""Harbor's Daytona environment for an open-daytona pool (module docstring)."""
|
|
70
|
+
|
|
71
|
+
def __init__(self, *args, **kwargs):
|
|
72
|
+
types = kwargs.pop("gpu_types", None)
|
|
73
|
+
if types and kwargs.get("task_env_config") is not None:
|
|
74
|
+
types = [t.strip() for t in (types.split(",") if isinstance(types, str) else types) if t.strip()]
|
|
75
|
+
kwargs["task_env_config"] = kwargs["task_env_config"].model_copy(update={"gpu_types": types})
|
|
76
|
+
env_dir = kwargs.get("environment_dir", args[0] if args else None)
|
|
77
|
+
self._od_compose_path = Path(env_dir) / "docker-compose.yaml" if env_dir else None
|
|
78
|
+
self._od_extra_compose = bool(kwargs.get("extra_docker_compose"))
|
|
79
|
+
self._od_shm_mb = 0
|
|
80
|
+
super().__init__(*args, **kwargs)
|
|
81
|
+
|
|
82
|
+
# DaytonaEnvironment.__init__ sets _compose_mode from the presence of docker-compose.yaml before anything else
|
|
83
|
+
# reads it; a compose file of the single-service kind runs as a direct sandbox instead.
|
|
84
|
+
@property
|
|
85
|
+
def _compose_mode(self):
|
|
86
|
+
return self.__dict__.get("_od_compose_mode", False)
|
|
87
|
+
|
|
88
|
+
@_compose_mode.setter
|
|
89
|
+
def _compose_mode(self, value):
|
|
90
|
+
if value and not self._od_extra_compose and self._od_compose_path is not None:
|
|
91
|
+
shm = single_service_shm(self._od_compose_path)
|
|
92
|
+
if shm is not None:
|
|
93
|
+
value, self._od_shm_mb = False, shm
|
|
94
|
+
self.__dict__["_od_compose_mode"] = value
|
|
95
|
+
|
|
96
|
+
def _sandbox_labels(self):
|
|
97
|
+
labels = super()._sandbox_labels()
|
|
98
|
+
if self._od_shm_mb:
|
|
99
|
+
labels[SHM_LABEL] = str(self._od_shm_mb)
|
|
100
|
+
return labels
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Synchronous standard-library client for an open-daytona gateway or a single sbxd daemon (both speak the same API; see
|
|
2
|
+
docs/api.md). Python 3.9+. examples/rl_adapter.py wraps it for an asyncio RL harness.
|
|
3
|
+
|
|
4
|
+
c = Client() # SBX_URL and SBX_TOKEN / SBX_TOKEN_FILE
|
|
5
|
+
sb = c.create(image="ubuntu:22.04", cpu=1, memory=2, disk_gb=10, labels={"run": "x"})
|
|
6
|
+
rc, out = c.exec(sb["id"], "echo hi", user="root", timeout=30)
|
|
7
|
+
c.put(sb["id"], "/tmp/f", b"data"); c.get(sb["id"], "/tmp/f"); c.delete(sb["id"])
|
|
8
|
+
"""
|
|
9
|
+
import base64, http.client, json, os, time, urllib.parse, uuid
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ApiError(Exception):
|
|
13
|
+
def __init__(self, status, body):
|
|
14
|
+
Exception.__init__(self, "HTTP %s: %s" % (status, body[:500]))
|
|
15
|
+
self.status = status
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Client:
|
|
19
|
+
def __init__(self, url=None, token=None, token_file=None):
|
|
20
|
+
"""url: SBX_URL, default http://127.0.0.1:8790. Token: `token`, else SBX_TOKEN, else the file `token_file` /
|
|
21
|
+
SBX_TOKEN_FILE (default ~/.config/open-daytona/token)."""
|
|
22
|
+
url = url or os.environ.get("SBX_URL", "http://127.0.0.1:8790")
|
|
23
|
+
u = urllib.parse.urlparse(url)
|
|
24
|
+
self.host, self.port = u.hostname, u.port or 80
|
|
25
|
+
token = token or os.environ.get("SBX_TOKEN")
|
|
26
|
+
if not token:
|
|
27
|
+
tf = token_file or os.environ.get("SBX_TOKEN_FILE", "~/.config/open-daytona/token")
|
|
28
|
+
token = open(os.path.expanduser(tf)).read()
|
|
29
|
+
self.token = token.strip()
|
|
30
|
+
|
|
31
|
+
def call(self, method, path, body=None, timeout=120, raw=False, ctype="application/json"):
|
|
32
|
+
conn = http.client.HTTPConnection(self.host, self.port, timeout=timeout)
|
|
33
|
+
try:
|
|
34
|
+
data = body if isinstance(body, (bytes, type(None))) else json.dumps(body).encode()
|
|
35
|
+
conn.request(method, path, body=data, headers={"Authorization": "Bearer " + self.token,
|
|
36
|
+
"Content-Type": ctype})
|
|
37
|
+
r = conn.getresponse()
|
|
38
|
+
out = r.read()
|
|
39
|
+
finally:
|
|
40
|
+
conn.close()
|
|
41
|
+
if r.status != 200:
|
|
42
|
+
raise ApiError(r.status, out.decode("utf-8", "replace"))
|
|
43
|
+
return out if raw else json.loads(out)
|
|
44
|
+
|
|
45
|
+
def health(self):
|
|
46
|
+
return self.call("GET", "/v1/health")
|
|
47
|
+
|
|
48
|
+
def create(self, retries=60, **spec):
|
|
49
|
+
spec.setdefault("request_id", uuid.uuid4().hex)
|
|
50
|
+
for i in range(retries):
|
|
51
|
+
try:
|
|
52
|
+
return self.call("POST", "/v1/sandboxes", spec, timeout=3600)
|
|
53
|
+
except ApiError as e:
|
|
54
|
+
if e.status not in (502, 503) or i == retries - 1:
|
|
55
|
+
raise
|
|
56
|
+
time.sleep(min(30, 2 + i * 2))
|
|
57
|
+
|
|
58
|
+
def exec(self, sid, cmd, user="root", env=None, timeout=120, slow_grace=600):
|
|
59
|
+
"""-> (rc, merged output str); rc 124 = timed out. Long-polls until the command is done.
|
|
60
|
+
|
|
61
|
+
The exec_id makes the call idempotent, so a retryable failure (502/503: a slow node, a daemon restarting, a
|
|
62
|
+
dropped connection) is retried with the same id for up to `slow_grace` seconds and never runs the command
|
|
63
|
+
twice; 404/410 (sandbox or its node gone) raise at once."""
|
|
64
|
+
eid = uuid.uuid4().hex
|
|
65
|
+
body = {"cmd": cmd, "user": user, "env": env, "timeout": timeout, "exec_id": eid, "wait": 25}
|
|
66
|
+
first_fail, r = None, None
|
|
67
|
+
while r is None or not r.get("done"):
|
|
68
|
+
try:
|
|
69
|
+
if r is None: # (re)submit: with the same exec_id the daemon answers for the command it already has
|
|
70
|
+
r = self.call("POST", "/v1/sandboxes/%s/exec" % sid, body, timeout=60)
|
|
71
|
+
else:
|
|
72
|
+
r = self.call("GET", "/v1/sandboxes/%s/exec/%s?wait=25" % (sid, eid), timeout=60)
|
|
73
|
+
first_fail = None
|
|
74
|
+
except (ApiError, OSError) as e:
|
|
75
|
+
if isinstance(e, ApiError) and e.status not in (502, 503):
|
|
76
|
+
raise
|
|
77
|
+
first_fail = first_fail or time.time()
|
|
78
|
+
if time.time() - first_fail > slow_grace:
|
|
79
|
+
raise
|
|
80
|
+
time.sleep(2)
|
|
81
|
+
r = None
|
|
82
|
+
return r["rc"], base64.b64decode(r["output_b64"]).decode("utf-8", "replace")
|
|
83
|
+
|
|
84
|
+
def put(self, sid, path, data, user="root"):
|
|
85
|
+
q = urllib.parse.urlencode({"path": path, "user": user})
|
|
86
|
+
return self.call("PUT", "/v1/sandboxes/%s/file?%s" % (sid, q), data, timeout=330,
|
|
87
|
+
ctype="application/octet-stream")
|
|
88
|
+
|
|
89
|
+
def get(self, sid, path):
|
|
90
|
+
q = urllib.parse.urlencode({"path": path})
|
|
91
|
+
return self.call("GET", "/v1/sandboxes/%s/file?%s" % (sid, q), timeout=330, raw=True)
|
|
92
|
+
|
|
93
|
+
def info(self, sid):
|
|
94
|
+
return self.call("GET", "/v1/sandboxes/%s" % sid)
|
|
95
|
+
|
|
96
|
+
def stop(self, sid):
|
|
97
|
+
"""Checkpoint the sandbox and end its processes; its files are kept until start() or delete()."""
|
|
98
|
+
return self.call("POST", "/v1/sandboxes/%s/stop" % sid, {}, timeout=1800)
|
|
99
|
+
|
|
100
|
+
def start(self, sid):
|
|
101
|
+
"""Restore a stopped sandbox."""
|
|
102
|
+
return self.call("POST", "/v1/sandboxes/%s/start" % sid, {}, timeout=900)
|
|
103
|
+
|
|
104
|
+
def delete(self, sid):
|
|
105
|
+
return self.call("DELETE", "/v1/sandboxes/%s" % sid)
|
|
106
|
+
|
|
107
|
+
def list(self, label=None):
|
|
108
|
+
q = "?" + urllib.parse.urlencode({"label": label}) if label else ""
|
|
109
|
+
return self.call("GET", "/v1/sandboxes" + q)["sandboxes"]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: open-daytona
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Clients for open-daytona, a self-hosted Daytona-compatible sandbox pool (rootless gVisor, GPUs included): pool client, Daytona SDK build-context patch, Harbor environment
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/andylizf/open-daytona
|
|
7
|
+
Project-URL: Documentation, https://github.com/andylizf/open-daytona/blob/main/docs/daytona-compat.md
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Provides-Extra: harbor
|
|
12
|
+
Requires-Dist: harbor==0.25.0; extra == "harbor"
|
|
13
|
+
Requires-Dist: daytona<1,>=0.234; extra == "harbor"
|
|
14
|
+
Requires-Dist: pyyaml; extra == "harbor"
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# open-daytona (Python clients)
|
|
18
|
+
|
|
19
|
+
Client side of [open-daytona](https://github.com/andylizf/open-daytona), a self-hosted sandbox pool that speaks the
|
|
20
|
+
Daytona API and runs each sandbox under rootless gVisor, GPU sandboxes included. The pool itself (the node daemon and
|
|
21
|
+
the gateway) runs from a checkout of the repository; see its README.
|
|
22
|
+
|
|
23
|
+
- `open_daytona.harbor.OpenDaytonaEnvironment`: a Harbor environment for a pool. Install with the `harbor` extra and
|
|
24
|
+
run Harbor with it:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install "open-daytona[harbor]"
|
|
28
|
+
export DAYTONA_API_URL=http://<gateway>:8790/api DAYTONA_API_KEY=<pool token>
|
|
29
|
+
harbor run -e open_daytona.harbor:OpenDaytonaEnvironment -p <task> -a <agent> ...
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
It is Harbor's Daytona environment with two changes: build contexts upload over plain http, and a task whose
|
|
33
|
+
`docker-compose.yaml` only sizes `/dev/shm` and reserves GPUs runs as one sandbox instead of Docker-in-Docker.
|
|
34
|
+
- `open_daytona.daytona_s3_http`: importing it lets the Daytona SDK upload build contexts to a gateway over http.
|
|
35
|
+
- `open_daytona.sbxclient`: a standard-library client for the pool's own `/v1` API.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
client/README.md
|
|
5
|
+
client/open_daytona/__init__.py
|
|
6
|
+
client/open_daytona/daytona_s3_http.py
|
|
7
|
+
client/open_daytona/harbor.py
|
|
8
|
+
client/open_daytona/sbxclient.py
|
|
9
|
+
client/open_daytona.egg-info/PKG-INFO
|
|
10
|
+
client/open_daytona.egg-info/SOURCES.txt
|
|
11
|
+
client/open_daytona.egg-info/dependency_links.txt
|
|
12
|
+
client/open_daytona.egg-info/requires.txt
|
|
13
|
+
client/open_daytona.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
open_daytona
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "open-daytona"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Clients for open-daytona, a self-hosted Daytona-compatible sandbox pool (rootless gVisor, GPUs included): pool client, Daytona SDK build-context patch, Harbor environment"
|
|
9
|
+
readme = "client/README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
dependencies = []
|
|
14
|
+
|
|
15
|
+
[project.optional-dependencies]
|
|
16
|
+
# The tested Harbor line: Harbor 0.25.0 with the Daytona SDK 0.x.
|
|
17
|
+
harbor = ["harbor==0.25.0", "daytona>=0.234,<1", "pyyaml"]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://github.com/andylizf/open-daytona"
|
|
21
|
+
Documentation = "https://github.com/andylizf/open-daytona/blob/main/docs/daytona-compat.md"
|
|
22
|
+
|
|
23
|
+
[tool.setuptools]
|
|
24
|
+
package-dir = {"" = "client"}
|
|
25
|
+
packages = ["open_daytona"]
|