@sandagent/daemon 0.8.5
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.
- package/LICENSE +201 -0
- package/README.md +378 -0
- package/dist/bundle.mjs +219213 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +20 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/nextjs.d.ts +20 -0
- package/dist/nextjs.d.ts.map +1 -0
- package/dist/nextjs.js +45 -0
- package/dist/nextjs.js.map +1 -0
- package/dist/router.d.ts +13 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +58 -0
- package/dist/router.js.map +1 -0
- package/dist/routes/coding.d.ts +22 -0
- package/dist/routes/coding.d.ts.map +1 -0
- package/dist/routes/coding.js +84 -0
- package/dist/routes/coding.js.map +1 -0
- package/dist/routes/fs.d.ts +83 -0
- package/dist/routes/fs.d.ts.map +1 -0
- package/dist/routes/fs.js +135 -0
- package/dist/routes/fs.js.map +1 -0
- package/dist/routes/git.d.ts +37 -0
- package/dist/routes/git.d.ts.map +1 -0
- package/dist/routes/git.js +106 -0
- package/dist/routes/git.js.map +1 -0
- package/dist/routes/health.d.ts +7 -0
- package/dist/routes/health.d.ts.map +1 -0
- package/dist/routes/health.js +5 -0
- package/dist/routes/health.js.map +1 -0
- package/dist/routes/volumes.d.ts +16 -0
- package/dist/routes/volumes.d.ts.map +1 -0
- package/dist/routes/volumes.js +21 -0
- package/dist/routes/volumes.js.map +1 -0
- package/dist/server.d.ts +8 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +37 -0
- package/dist/server.js.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +51 -0
- package/dist/utils.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
# @sandagent/daemon
|
|
2
|
+
|
|
3
|
+
Unified API gateway for sandbox containers. Runs **inside** the [sandock](~/Documents/kapps/apps/sandock) Next.js app — either embedded as a Next.js route handler (local/dev mode) or as a standalone process inside a sandbox container (production).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Where this runs
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
~/Documents/kapps/apps/buda/ ← buda.im Next.js app
|
|
11
|
+
app/api/daemon/[...path]/
|
|
12
|
+
route.ts ← embeds @sandagent/daemon via createNextHandler()
|
|
13
|
+
(local dev mode, no extra process)
|
|
14
|
+
|
|
15
|
+
sandbox container ← production
|
|
16
|
+
sandagent-daemon :3080 ← standalone process
|
|
17
|
+
(accessed via sandock.ai proxy)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The same `@sandagent/daemon` package works in both modes — Next.js embed for local development, standalone HTTP server for production containers.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Architecture
|
|
25
|
+
|
|
26
|
+
### 1. Big Picture — How Buda talks to a sandbox
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
buda.im
|
|
30
|
+
│
|
|
31
|
+
│ HTTPS
|
|
32
|
+
▼
|
|
33
|
+
sandock.ai
|
|
34
|
+
/api/v1/sandbox/http/proxy/{sandbox-id}/3080/
|
|
35
|
+
│
|
|
36
|
+
│ HTTP (proxied)
|
|
37
|
+
▼
|
|
38
|
+
┌─────────────────────────────────────────────────────┐
|
|
39
|
+
│ sandbox container │
|
|
40
|
+
│ │
|
|
41
|
+
│ ┌────────────────────────────────────┐ │
|
|
42
|
+
│ │ sandagent-daemon :3080 │ │
|
|
43
|
+
│ │ (unified API gateway) │ │
|
|
44
|
+
│ └────────────────────────────────────┘ │
|
|
45
|
+
│ │
|
|
46
|
+
│ chromium :9223 (internal) --remote-allow-origins=*│
|
|
47
|
+
│ nginx :9222 → :9223 (rewrites Host: localhost) │
|
|
48
|
+
└─────────────────────────────────────────────────────┘
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
External callers only ever see **one port: 3080**. Everything else is internal.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### 2. Inside the daemon — request routing
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
incoming HTTP request
|
|
59
|
+
│
|
|
60
|
+
▼
|
|
61
|
+
┌───────────────────────────────────────────────────────┐
|
|
62
|
+
│ sandagent-daemon │
|
|
63
|
+
│ │
|
|
64
|
+
│ POST /api/coding/run ──────────────────────────┐ │
|
|
65
|
+
│ │ │
|
|
66
|
+
│ GET|POST /api/fs/* ──────────────────────────┐ │ │
|
|
67
|
+
│ GET|POST /api/git/* ──────────────────────┐ │ │ │
|
|
68
|
+
│ GET|POST /api/volumes/* ──────────────┐ │ │ │ │
|
|
69
|
+
│ GET /healthz ─────────────────────┐ │ │ │ │ │
|
|
70
|
+
│ │ │ │ │ │ │
|
|
71
|
+
│ ▼ ▼ ▼ │ │ │
|
|
72
|
+
│ ┌─────────────┐ │ │ │
|
|
73
|
+
│ │ DaemonRouter│ │ │ │
|
|
74
|
+
│ │ (core logic)│ │ │ │
|
|
75
|
+
│ └──────┬──────┘ │ │ │
|
|
76
|
+
│ │ │ │ │
|
|
77
|
+
│ ┌───────────────────────┤ │ │ │
|
|
78
|
+
│ ▼ ▼ ▼ │ │
|
|
79
|
+
│ node:fs/promises spawn git SSE │ │
|
|
80
|
+
│ (file ops) (git CLI) stream │ │
|
|
81
|
+
│ │ │
|
|
82
|
+
│ @sandagent/ │ │
|
|
83
|
+
│ runner-core ◄───┘ │
|
|
84
|
+
│ claude/pi/ │
|
|
85
|
+
│ gemini/codex │
|
|
86
|
+
└───────────────────────────────────────────────────────┘
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
### 3. Package dependency graph
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
packages/
|
|
95
|
+
│
|
|
96
|
+
├── runner-claude ──┐
|
|
97
|
+
├── runner-codex ──┤
|
|
98
|
+
├── runner-gemini ──┼──► runner-core ◄──┬── apps/runner-cli
|
|
99
|
+
├── runner-pi ──┤ │
|
|
100
|
+
└── runner-opencode ──┘ └── apps/sandagent-daemon
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`runner-core` is the shared dispatch layer — no I/O, no stdout, just `createRunner() → AsyncIterable<string>`.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
### 4. Deployment modes
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
┌──────────────────────────────────────────────────────────────────┐
|
|
111
|
+
│ Mode A: Standalone process (container / local) │
|
|
112
|
+
│ │
|
|
113
|
+
│ entrypoint.sh │
|
|
114
|
+
│ ├── chromium :9223 (internal) --remote-allow-origins=* & │
|
|
115
|
+
│ ├── nginx :9222 → :9223 (rewrites Host: localhost) & │
|
|
116
|
+
│ └── sandagent-daemon ← node process, listens :3080 │
|
|
117
|
+
│ │
|
|
118
|
+
│ caller: curl / Buda SDK / any HTTP client │
|
|
119
|
+
│ → http://sandbox:3080/api/fs/read?path=file.txt │
|
|
120
|
+
└──────────────────────────────────────────────────────────────────┘
|
|
121
|
+
|
|
122
|
+
┌──────────────────────────────────────────────────────────────────┐
|
|
123
|
+
│ Mode B: Embedded in Next.js (local dev / sandock-cli) │
|
|
124
|
+
│ │
|
|
125
|
+
│ app/api/daemon/[...path]/route.ts │
|
|
126
|
+
│ └── createNextHandler({ root: process.cwd() }) │
|
|
127
|
+
│ │
|
|
128
|
+
│ No extra process. DaemonRouter runs inside Next.js. │
|
|
129
|
+
│ caller: browser / fetch │
|
|
130
|
+
│ → /api/daemon/fs/read?path=file.txt │
|
|
131
|
+
└──────────────────────────────────────────────────────────────────┘
|
|
132
|
+
|
|
133
|
+
┌──────────────────────────────────────────────────────────────────┐
|
|
134
|
+
│ Mode C: runner-cli (local terminal, no daemon needed) │
|
|
135
|
+
│ │
|
|
136
|
+
│ sandagent run --runner claude -- "Build a REST API" │
|
|
137
|
+
│ └── runner-core → stdout (AI SDK UI NDJSON stream) │
|
|
138
|
+
│ │
|
|
139
|
+
│ Runs directly on local filesystem. No HTTP server. │
|
|
140
|
+
└──────────────────────────────────────────────────────────────────┘
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
### 5. Internal code structure
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
apps/sandagent-daemon/
|
|
149
|
+
├── src/
|
|
150
|
+
│ ├── cli.ts entry point — reads env, starts http.Server
|
|
151
|
+
│ ├── server.ts createDaemon() — http.Server wrapping DaemonRouter
|
|
152
|
+
│ ├── router.ts DaemonRouter — framework-agnostic route table
|
|
153
|
+
│ ├── nextjs.ts createNextHandler() — Next.js adapter
|
|
154
|
+
│ ├── utils.ts path safety, ApiEnvelope helpers
|
|
155
|
+
│ └── routes/
|
|
156
|
+
│ ├── health.ts GET /healthz
|
|
157
|
+
│ ├── fs.ts GET|POST /api/fs/*
|
|
158
|
+
│ ├── volumes.ts GET|POST /api/volumes/*
|
|
159
|
+
│ ├── git.ts POST /api/git/* (spawns git CLI)
|
|
160
|
+
│ └── coding.ts POST /api/coding/run (SSE, uses runner-core)
|
|
161
|
+
└── src/__tests__/
|
|
162
|
+
└── daemon.test.ts 13 integration tests (no mocks, real fs + git)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Usage
|
|
168
|
+
|
|
169
|
+
### Option A: runner-cli (local terminal)
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
cd templates/coder
|
|
173
|
+
npx sandagent run -- "Build a REST API"
|
|
174
|
+
npx sandagent run --runner pi -- "Analyze this dataset"
|
|
175
|
+
npx sandagent run --runner gemini --model gemini-2.0-flash -- "Review my code"
|
|
176
|
+
npx sandagent run --resume <session-id> -- "Continue"
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Output: raw AI SDK UI NDJSON stream to stdout.
|
|
180
|
+
|
|
181
|
+
### Option B: daemon standalone (container)
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
# see docs/entrypoint.example.sh for the full script
|
|
185
|
+
#
|
|
186
|
+
# Chromium runs on internal port 9223 with --remote-allow-origins=* so
|
|
187
|
+
# the WebSocket origin check passes. nginx proxies 0.0.0.0:9222 → 9223
|
|
188
|
+
# and rewrites the Host header to "localhost" to satisfy Chromium's
|
|
189
|
+
# DNS-rebinding security check. Without this rewrite, external clients
|
|
190
|
+
# (Host: container-ip:9222) are rejected even when the port is open.
|
|
191
|
+
chromium --headless --no-sandbox \
|
|
192
|
+
--remote-debugging-port=9223 \
|
|
193
|
+
--remote-allow-origins=* &
|
|
194
|
+
nginx # proxies :9222 → :9223 with Host rewrite
|
|
195
|
+
exec sandagent-daemon
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Run an agent — SSE stream
|
|
200
|
+
curl -N -X POST http://localhost:3080/api/coding/run \
|
|
201
|
+
-H 'Content-Type: application/json' \
|
|
202
|
+
-d '{"runner":"claude","userInput":"List files in /workspace"}'
|
|
203
|
+
|
|
204
|
+
# File ops
|
|
205
|
+
curl -X POST http://localhost:3080/api/fs/write \
|
|
206
|
+
-H 'Content-Type: application/json' \
|
|
207
|
+
-d '{"path":"hello.txt","content":"hello world"}'
|
|
208
|
+
|
|
209
|
+
curl "http://localhost:3080/api/fs/read?path=hello.txt"
|
|
210
|
+
|
|
211
|
+
# Git
|
|
212
|
+
curl -X POST http://localhost:3080/api/git/clone \
|
|
213
|
+
-H 'Content-Type: application/json' \
|
|
214
|
+
-d '{"repo_parent":".","url":"https://github.com/user/repo","depth":1}'
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Option C: embed in Next.js
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
// app/api/daemon/[...path]/route.ts
|
|
221
|
+
import { createNextHandler } from "@sandagent/daemon/nextjs";
|
|
222
|
+
|
|
223
|
+
const handler = createNextHandler({ root: process.cwd() });
|
|
224
|
+
export const GET = handler;
|
|
225
|
+
export const POST = handler;
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Covers `/api/fs/*`, `/api/git/*`, `/api/volumes/*` at `/api/daemon/*`. No extra process.
|
|
229
|
+
|
|
230
|
+
### Option D: just run an agent directly (no daemon needed)
|
|
231
|
+
|
|
232
|
+
If you only need to run an agent — no file API, no HTTP server — use `runner-core` directly:
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
import { createRunner } from "@sandagent/runner-core";
|
|
236
|
+
|
|
237
|
+
const stream = createRunner({
|
|
238
|
+
runner: "claude", // or "pi", "gemini", "codex", "opencode"
|
|
239
|
+
model: "claude-sonnet-4-20250514",
|
|
240
|
+
userInput: "Build a REST API",
|
|
241
|
+
cwd: "/workspace",
|
|
242
|
+
env: process.env as Record<string, string>,
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// Collect all chunks into a full response
|
|
246
|
+
const chunks: string[] = [];
|
|
247
|
+
for await (const chunk of stream) {
|
|
248
|
+
chunks.push(chunk);
|
|
249
|
+
}
|
|
250
|
+
const fullResponse = chunks.join("");
|
|
251
|
+
|
|
252
|
+
// Or parse each NDJSON line as it arrives
|
|
253
|
+
for await (const chunk of stream) {
|
|
254
|
+
for (const line of chunk.split("\n").filter(Boolean)) {
|
|
255
|
+
const msg = JSON.parse(line);
|
|
256
|
+
console.log(msg);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
`runner-core` is the shared core used by both `runner-cli` and `sandagent-daemon`. Use it directly when you don't need the HTTP gateway.
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## API Reference
|
|
266
|
+
|
|
267
|
+
All JSON responses: `{ "ok": true, "data": {}, "error": null }`
|
|
268
|
+
|
|
269
|
+
### Agent `/api/coding/*`
|
|
270
|
+
|
|
271
|
+
#### `POST /api/coding/run`
|
|
272
|
+
|
|
273
|
+
Run an agent and stream the output as SSE (AI SDK UI NDJSON format).
|
|
274
|
+
|
|
275
|
+
Request body:
|
|
276
|
+
|
|
277
|
+
| Field | Type | Default | Description |
|
|
278
|
+
|-------|------|---------|-------------|
|
|
279
|
+
| `userInput` | string | required | The task / prompt |
|
|
280
|
+
| `runner` | string | `"claude"` | `claude` · `codex` · `gemini` · `pi` · `opencode` |
|
|
281
|
+
| `model` | string | `"claude-sonnet-4-20250514"` | Model name for the runner |
|
|
282
|
+
| `cwd` | string | `SANDAGENT_ROOT` | Working directory inside the sandbox |
|
|
283
|
+
| `systemPrompt` | string | — | Override system prompt |
|
|
284
|
+
| `maxTurns` | number | — | Max agent turns |
|
|
285
|
+
| `allowedTools` | string[] | — | Restrict which tools the agent can use |
|
|
286
|
+
| `resume` | string | — | Session ID to resume |
|
|
287
|
+
| `skillPaths` | string[] | — | Extra skill paths (pi runner) |
|
|
288
|
+
|
|
289
|
+
Example:
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
# Stream with curl (-N disables buffering)
|
|
293
|
+
curl -N -X POST http://localhost:3080/api/coding/run \
|
|
294
|
+
-H 'Content-Type: application/json' \
|
|
295
|
+
-d '{
|
|
296
|
+
"runner": "claude",
|
|
297
|
+
"userInput": "List all TypeScript files and summarize what each does",
|
|
298
|
+
"cwd": "/workspace/myproject"
|
|
299
|
+
}'
|
|
300
|
+
|
|
301
|
+
# Use pi runner with a different model
|
|
302
|
+
curl -N -X POST http://localhost:3080/api/coding/run \
|
|
303
|
+
-H 'Content-Type: application/json' \
|
|
304
|
+
-d '{
|
|
305
|
+
"runner": "pi",
|
|
306
|
+
"model": "gemini-2.0-flash",
|
|
307
|
+
"userInput": "Refactor this codebase to use async/await"
|
|
308
|
+
}'
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Response: `application/x-ndjson` chunked stream — each line is an AI SDK UI message, compatible with Vercel AI SDK `useChat` / `streamText`.
|
|
312
|
+
|
|
313
|
+
### Filesystem `/api/fs/*`
|
|
314
|
+
|
|
315
|
+
| Method | Path | Params |
|
|
316
|
+
|--------|------|--------|
|
|
317
|
+
| GET | `/api/fs/list` | `?path=src&volume=vol-001` |
|
|
318
|
+
| GET | `/api/fs/read` | `?path=file.txt` |
|
|
319
|
+
| GET | `/api/fs/stat` | `?path=file.txt` |
|
|
320
|
+
| GET | `/api/fs/exists` | `?path=file.txt` |
|
|
321
|
+
| GET | `/api/fs/find` | `?pattern=todo&limit=100` |
|
|
322
|
+
| POST | `/api/fs/write` | `{"path":"a.txt","content":"hello"}` |
|
|
323
|
+
| POST | `/api/fs/append` | `{"path":"log.txt","content":"line\n"}` |
|
|
324
|
+
| POST | `/api/fs/mkdir` | `{"path":"a/b/c"}` |
|
|
325
|
+
| POST | `/api/fs/remove` | `{"path":"tmp","recursive":true}` |
|
|
326
|
+
| POST | `/api/fs/move` | `{"from":"a.txt","to":"b.txt"}` |
|
|
327
|
+
| POST | `/api/fs/copy` | `{"from":"a.txt","to":"b.txt"}` |
|
|
328
|
+
|
|
329
|
+
All fs endpoints accept optional `volume` for multi-tenant isolation.
|
|
330
|
+
|
|
331
|
+
### Git `/api/git/*`
|
|
332
|
+
|
|
333
|
+
| Method | Path | Body |
|
|
334
|
+
|--------|------|------|
|
|
335
|
+
| POST | `/api/git/status` | `{"repo":"myrepo"}` |
|
|
336
|
+
| POST | `/api/git/exec` | `{"repo":"myrepo","args":["log","--oneline"]}` |
|
|
337
|
+
| POST | `/api/git/clone` | `{"repo_parent":".","url":"https://...","depth":1}` |
|
|
338
|
+
| POST | `/api/git/init` | `{"repo":"myrepo","initial_branch":"main"}` |
|
|
339
|
+
|
|
340
|
+
### Volumes `/api/volumes/*`
|
|
341
|
+
|
|
342
|
+
| Method | Path | Body |
|
|
343
|
+
|--------|------|------|
|
|
344
|
+
| GET | `/api/volumes/list` | |
|
|
345
|
+
| POST | `/api/volumes/ensure` | `{"volume":"vol-001"}` |
|
|
346
|
+
| POST | `/api/volumes/remove` | `{"volume":"vol-001"}` |
|
|
347
|
+
|
|
348
|
+
### Health
|
|
349
|
+
|
|
350
|
+
```
|
|
351
|
+
GET /healthz
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
## Environment Variables
|
|
357
|
+
|
|
358
|
+
| Variable | Default | Description |
|
|
359
|
+
|----------|---------|-------------|
|
|
360
|
+
| `SANDAGENT_DAEMON_PORT` | `3080` | Listen port |
|
|
361
|
+
| `SANDAGENT_ROOT` | `/workspace` | Filesystem root |
|
|
362
|
+
| `ANTHROPIC_API_KEY` | — | For claude runner |
|
|
363
|
+
| `GEMINI_API_KEY` | — | For gemini / pi runner |
|
|
364
|
+
| `OPENAI_API_KEY` | — | For codex runner |
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## Development
|
|
369
|
+
|
|
370
|
+
```bash
|
|
371
|
+
cd apps/sandagent-daemon
|
|
372
|
+
pnpm install && pnpm build
|
|
373
|
+
|
|
374
|
+
SANDAGENT_ROOT=/tmp/test sandagent-daemon
|
|
375
|
+
curl http://localhost:3080/healthz
|
|
376
|
+
|
|
377
|
+
pnpm test # 13 integration tests
|
|
378
|
+
```
|