@unionstreet/apple-sandboxes 0.1.0
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 +113 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +101 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +58 -0
- package/dist/client.js +73 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/paths.d.ts +10 -0
- package/dist/paths.js +16 -0
- package/dist/paths.js.map +1 -0
- package/dist/runtime.d.ts +61 -0
- package/dist/runtime.js +407 -0
- package/dist/runtime.js.map +1 -0
- package/dist/server.d.ts +13 -0
- package/dist/server.js +105 -0
- package/dist/server.js.map +1 -0
- package/dist/store.d.ts +23 -0
- package/dist/store.js +71 -0
- package/dist/store.js.map +1 -0
- package/dist/types.d.ts +128 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/util.d.ts +15 -0
- package/dist/util.js +63 -0
- package/dist/util.js.map +1 -0
- package/docs/architecture.md +130 -0
- package/package.json +59 -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 describing the origin of the Work and
|
|
141
|
+
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 accept and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
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 2026 Union Street AI
|
|
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,113 @@
|
|
|
1
|
+
# apple-sandboxes
|
|
2
|
+
|
|
3
|
+
Local dev and agent sandboxes for Apple Silicon Macs, built on Apple's native [`container`](https://github.com/apple/container) runtime.
|
|
4
|
+
|
|
5
|
+
It gives you long-lived Linux containers with a stable `/workspace`, command execution, snapshots, volumes, lifecycle limits, an HTTP API, a TypeScript SDK, and a CLI.
|
|
6
|
+
|
|
7
|
+
It is not a microVM security boundary. It is a lightweight Apple-container-native layer for local development and agent workloads.
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- macOS on Apple Silicon
|
|
12
|
+
- Node.js 20+
|
|
13
|
+
- Apple `container`
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
container system status
|
|
17
|
+
container run --rm --platform linux/arm64 alpine:3.20 uname -a
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install -g @unionstreet/apple-sandboxes
|
|
24
|
+
apple-sandboxes serve
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The server listens on `127.0.0.1:9102` by default.
|
|
28
|
+
|
|
29
|
+
For Tailscale, LAN, or public access, require an API key:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
APPLE_SANDBOXES_API_KEY="$(openssl rand -hex 32)" \
|
|
33
|
+
apple-sandboxes serve --host 0.0.0.0
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## CLI
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npx @unionstreet/apple-sandboxes serve
|
|
40
|
+
|
|
41
|
+
apple-sandboxes image create ubuntu-base ubuntu:24.04
|
|
42
|
+
apple-sandboxes sandbox create --name dev --image-id ubuntu-base
|
|
43
|
+
apple-sandboxes sandbox exec dev 'uname -a; pwd; echo hello > hello.txt'
|
|
44
|
+
apple-sandboxes snapshot create baseline dev
|
|
45
|
+
apple-sandboxes sandbox create --name forked --snapshot-id baseline
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## SDK
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { AppleSandboxes } from '@unionstreet/apple-sandboxes'
|
|
52
|
+
|
|
53
|
+
const client = new AppleSandboxes('http://127.0.0.1:9102', process.env.APPLE_SANDBOXES_API_KEY)
|
|
54
|
+
|
|
55
|
+
const image = await client.images.create({
|
|
56
|
+
name: 'ubuntu-base',
|
|
57
|
+
image: 'ubuntu:24.04',
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const sandbox = await client.sandboxes.create({
|
|
61
|
+
name: 'dev',
|
|
62
|
+
imageId: image.id,
|
|
63
|
+
cpus: 2,
|
|
64
|
+
memory: '2G',
|
|
65
|
+
network: false,
|
|
66
|
+
idleTimeoutSeconds: 900,
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const result = await client.sandboxes.exec(sandbox.id, {
|
|
70
|
+
command: 'python3 --version',
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
console.log(result.stdout)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Primitives
|
|
77
|
+
|
|
78
|
+
- **Image**: a named OCI image ref or Dockerfile/Containerfile definition built with `container build`.
|
|
79
|
+
- **Sandbox**: a long-lived Apple container with a host-backed `/workspace`.
|
|
80
|
+
- **Snapshot**: a reusable `/workspace` archive used to fork new sandboxes.
|
|
81
|
+
- **Volume**: a named persistent host directory mounted into sandboxes.
|
|
82
|
+
- **Lifecycle policy**: idle, max-lifetime, and auto-delete limits enforced by the server reaper.
|
|
83
|
+
|
|
84
|
+
## HTTP API
|
|
85
|
+
|
|
86
|
+
```text
|
|
87
|
+
GET /health (always public)
|
|
88
|
+
GET /openapi.json (always public)
|
|
89
|
+
|
|
90
|
+
/v1/images create, list, build, delete image definitions
|
|
91
|
+
/v1/volumes create, list, delete persistent host volumes
|
|
92
|
+
/v1/snapshots create, list, delete workspace snapshots
|
|
93
|
+
/v1/sandboxes create, list, start, stop, exec, delete
|
|
94
|
+
/v1/sandboxes/:id/files/* read and write workspace files
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## State
|
|
98
|
+
|
|
99
|
+
State lives in `~/.apple-sandboxes` unless `APPLE_SANDBOXES_HOME` is set.
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
APPLE_SANDBOXES_HOME=/path/to/state apple-sandboxes serve
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Limits
|
|
106
|
+
|
|
107
|
+
- Network policy is currently `deny` or `open`.
|
|
108
|
+
- SSH, PTY sessions, service ingress, and secret policy are not implemented yet.
|
|
109
|
+
- `/openapi.json` is a route index, not a full schema contract yet.
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
Apache-2.0
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import { AppleSandboxes } from './client.js';
|
|
5
|
+
import { serve } from './server.js';
|
|
6
|
+
const program = new Command();
|
|
7
|
+
program.name('apple-sandboxes').description('Sandbox API for Apple container').version('0.1.0');
|
|
8
|
+
program
|
|
9
|
+
.command('serve')
|
|
10
|
+
.option('--host <host>', 'listen host', '127.0.0.1')
|
|
11
|
+
.option('--port <port>', 'listen port', '9102')
|
|
12
|
+
.option('--root <path>', 'state root')
|
|
13
|
+
.option('--api-key <key>', 'require bearer or x-api-key authentication')
|
|
14
|
+
.option('--no-reaper', 'disable lifecycle reaper')
|
|
15
|
+
.option('--reaper-interval-ms <ms>', 'lifecycle reaper interval', '30000')
|
|
16
|
+
.action(async (opts) => {
|
|
17
|
+
const { host, port } = await serve({
|
|
18
|
+
host: opts.host,
|
|
19
|
+
port: Number(opts.port),
|
|
20
|
+
root: opts.root,
|
|
21
|
+
apiKey: opts.apiKey,
|
|
22
|
+
reaper: opts.reaper,
|
|
23
|
+
reaperIntervalMs: Number(opts.reaperIntervalMs),
|
|
24
|
+
});
|
|
25
|
+
console.log(`apple-sandboxes listening on http://${host}:${port}`);
|
|
26
|
+
});
|
|
27
|
+
const image = program.command('image');
|
|
28
|
+
image
|
|
29
|
+
.command('create <name> <image>')
|
|
30
|
+
.option('--build', 'build if Dockerfile is provided')
|
|
31
|
+
.action(async (name, imageRef, opts) => {
|
|
32
|
+
const client = new AppleSandboxes();
|
|
33
|
+
console.log(JSON.stringify(await client.images.create({ name, image: imageRef, build: opts.build }), null, 2));
|
|
34
|
+
});
|
|
35
|
+
image
|
|
36
|
+
.command('from-dockerfile <name> <dockerfile>')
|
|
37
|
+
.option('--build', 'build immediately')
|
|
38
|
+
.action(async (name, dockerfile, opts) => {
|
|
39
|
+
const client = new AppleSandboxes();
|
|
40
|
+
console.log(JSON.stringify(await client.images.create({ name, dockerfile: await fs.readFile(dockerfile, 'utf8'), build: opts.build }), null, 2));
|
|
41
|
+
});
|
|
42
|
+
image.command('list').action(async () => console.log(JSON.stringify(await new AppleSandboxes().images.list(), null, 2)));
|
|
43
|
+
image.command('get <id>').action(async (id) => console.log(JSON.stringify(await new AppleSandboxes().images.get(id), null, 2)));
|
|
44
|
+
image.command('build <id>').action(async (id) => console.log(JSON.stringify(await new AppleSandboxes().images.build(id), null, 2)));
|
|
45
|
+
image.command('delete <id>').action(async (id) => console.log(JSON.stringify(await new AppleSandboxes().images.delete(id), null, 2)));
|
|
46
|
+
const volume = program.command('volume');
|
|
47
|
+
volume.command('create <name>').action(async (name) => console.log(JSON.stringify(await new AppleSandboxes().volumes.create({ name }), null, 2)));
|
|
48
|
+
volume.command('list').action(async () => console.log(JSON.stringify(await new AppleSandboxes().volumes.list(), null, 2)));
|
|
49
|
+
volume.command('delete <id>').action(async (id) => console.log(JSON.stringify(await new AppleSandboxes().volumes.delete(id), null, 2)));
|
|
50
|
+
const sandbox = program.command('sandbox');
|
|
51
|
+
sandbox
|
|
52
|
+
.command('create')
|
|
53
|
+
.option('--name <name>')
|
|
54
|
+
.option('--image <image>', 'image ref', 'ubuntu:24.04')
|
|
55
|
+
.option('--image-id <id>')
|
|
56
|
+
.option('--snapshot-id <id>')
|
|
57
|
+
.option('--cpus <n>', 'cpus', '2')
|
|
58
|
+
.option('--memory <value>', 'memory', '2G')
|
|
59
|
+
.option('--network', 'enable open network')
|
|
60
|
+
.action(async (opts) => {
|
|
61
|
+
const client = new AppleSandboxes();
|
|
62
|
+
const hasRef = Boolean(opts.imageId || opts.snapshotId);
|
|
63
|
+
console.log(JSON.stringify(await client.sandboxes.create({
|
|
64
|
+
name: opts.name,
|
|
65
|
+
image: hasRef ? undefined : opts.image,
|
|
66
|
+
imageId: opts.imageId,
|
|
67
|
+
snapshotId: opts.snapshotId,
|
|
68
|
+
cpus: Number(opts.cpus),
|
|
69
|
+
memory: opts.memory,
|
|
70
|
+
network: Boolean(opts.network),
|
|
71
|
+
}), null, 2));
|
|
72
|
+
});
|
|
73
|
+
sandbox.command('list').action(async () => console.log(JSON.stringify(await new AppleSandboxes().sandboxes.list(), null, 2)));
|
|
74
|
+
sandbox.command('get <id>').action(async (id) => console.log(JSON.stringify(await new AppleSandboxes().sandboxes.get(id), null, 2)));
|
|
75
|
+
sandbox
|
|
76
|
+
.command('exec <id> <command...>')
|
|
77
|
+
.option('--timeout <seconds>', 'timeout seconds', '300')
|
|
78
|
+
.action(async (id, command, opts) => {
|
|
79
|
+
const result = await new AppleSandboxes().sandboxes.exec(id, { command: command.join(' '), timeoutSeconds: Number(opts.timeout) });
|
|
80
|
+
process.stdout.write(result.stdout || '');
|
|
81
|
+
process.stderr.write(result.stderr || '');
|
|
82
|
+
if (result.status === 'timed_out')
|
|
83
|
+
process.exitCode = 124;
|
|
84
|
+
else if (result.exitCode)
|
|
85
|
+
process.exitCode = result.exitCode;
|
|
86
|
+
});
|
|
87
|
+
sandbox.command('start <id>').action(async (id) => console.log(JSON.stringify(await new AppleSandboxes().sandboxes.start(id), null, 2)));
|
|
88
|
+
sandbox.command('stop <id>').action(async (id) => console.log(JSON.stringify(await new AppleSandboxes().sandboxes.stop(id), null, 2)));
|
|
89
|
+
sandbox.command('delete <id>').action(async (id) => console.log(JSON.stringify(await new AppleSandboxes().sandboxes.delete(id), null, 2)));
|
|
90
|
+
const snapshot = program.command('snapshot');
|
|
91
|
+
snapshot
|
|
92
|
+
.command('create <name> <sandbox-id>')
|
|
93
|
+
.action(async (name, sandboxId) => console.log(JSON.stringify(await new AppleSandboxes().snapshots.create({ name, sandboxId }), null, 2)));
|
|
94
|
+
snapshot.command('list').action(async () => console.log(JSON.stringify(await new AppleSandboxes().snapshots.list(), null, 2)));
|
|
95
|
+
snapshot.command('get <id>').action(async (id) => console.log(JSON.stringify(await new AppleSandboxes().snapshots.get(id), null, 2)));
|
|
96
|
+
snapshot.command('delete <id>').action(async (id) => console.log(JSON.stringify(await new AppleSandboxes().snapshots.delete(id), null, 2)));
|
|
97
|
+
program.parseAsync().catch((error) => {
|
|
98
|
+
console.error(error.message || error);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
});
|
|
101
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,kBAAkB,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAEnC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAA;AAC7B,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,WAAW,CAAC,iCAAiC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAE/F,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,MAAM,CAAC,eAAe,EAAE,aAAa,EAAE,WAAW,CAAC;KACnD,MAAM,CAAC,eAAe,EAAE,aAAa,EAAE,MAAM,CAAC;KAC9C,MAAM,CAAC,eAAe,EAAE,YAAY,CAAC;KACrC,MAAM,CAAC,iBAAiB,EAAE,4CAA4C,CAAC;KACvE,MAA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AC,GAAG,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;AACrI,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,IAAI,cAAc,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;AAE3I,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACnC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,CAAA;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAC,CAAA"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { CreateImageRequest, CreateSandboxRequest, CreateSnapshotRequest, CreateVolumeRequest, ExecRequest, ExecResult, ImageDefinition, Sandbox, Snapshot, Volume } from './types.js';
|
|
2
|
+
export declare class AppleSandboxes {
|
|
3
|
+
readonly baseUrl: string;
|
|
4
|
+
readonly apiKey: string | undefined;
|
|
5
|
+
constructor(baseUrl?: string, apiKey?: string | undefined);
|
|
6
|
+
request<T>(path: string, init?: RequestInit): Promise<T>;
|
|
7
|
+
filePath(path: string): string;
|
|
8
|
+
health(): Promise<unknown>;
|
|
9
|
+
images: {
|
|
10
|
+
create: (body: CreateImageRequest) => Promise<ImageDefinition>;
|
|
11
|
+
list: () => Promise<{
|
|
12
|
+
images: ImageDefinition[];
|
|
13
|
+
}>;
|
|
14
|
+
get: (id: string) => Promise<ImageDefinition>;
|
|
15
|
+
build: (id: string) => Promise<ImageDefinition>;
|
|
16
|
+
delete: (id: string) => Promise<{
|
|
17
|
+
deleted: string;
|
|
18
|
+
}>;
|
|
19
|
+
};
|
|
20
|
+
volumes: {
|
|
21
|
+
create: (body: CreateVolumeRequest) => Promise<Volume>;
|
|
22
|
+
list: () => Promise<{
|
|
23
|
+
volumes: Volume[];
|
|
24
|
+
}>;
|
|
25
|
+
get: (id: string) => Promise<Volume>;
|
|
26
|
+
delete: (id: string) => Promise<{
|
|
27
|
+
deleted: string;
|
|
28
|
+
}>;
|
|
29
|
+
};
|
|
30
|
+
snapshots: {
|
|
31
|
+
create: (body: CreateSnapshotRequest) => Promise<Snapshot>;
|
|
32
|
+
list: () => Promise<{
|
|
33
|
+
snapshots: Snapshot[];
|
|
34
|
+
}>;
|
|
35
|
+
get: (id: string) => Promise<Snapshot>;
|
|
36
|
+
delete: (id: string) => Promise<{
|
|
37
|
+
deleted: string;
|
|
38
|
+
}>;
|
|
39
|
+
};
|
|
40
|
+
sandboxes: {
|
|
41
|
+
create: (body: CreateSandboxRequest) => Promise<Sandbox>;
|
|
42
|
+
list: () => Promise<{
|
|
43
|
+
sandboxes: Sandbox[];
|
|
44
|
+
}>;
|
|
45
|
+
get: (id: string) => Promise<Sandbox>;
|
|
46
|
+
start: (id: string) => Promise<Sandbox>;
|
|
47
|
+
stop: (id: string) => Promise<Sandbox>;
|
|
48
|
+
delete: (id: string) => Promise<{
|
|
49
|
+
deleted: string;
|
|
50
|
+
}>;
|
|
51
|
+
exec: (id: string, body: ExecRequest) => Promise<ExecResult>;
|
|
52
|
+
readFile: (id: string, filePath: string) => Promise<Buffer<ArrayBuffer>>;
|
|
53
|
+
writeFile: (id: string, filePath: string, body: Buffer | string) => Promise<{
|
|
54
|
+
path: string;
|
|
55
|
+
bytes: number;
|
|
56
|
+
}>;
|
|
57
|
+
};
|
|
58
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export class AppleSandboxes {
|
|
2
|
+
baseUrl;
|
|
3
|
+
apiKey;
|
|
4
|
+
constructor(baseUrl = process.env.APPLE_SANDBOXES_URL || 'http://127.0.0.1:9102', apiKey = process.env.APPLE_SANDBOXES_API_KEY) {
|
|
5
|
+
this.baseUrl = baseUrl;
|
|
6
|
+
this.apiKey = apiKey;
|
|
7
|
+
}
|
|
8
|
+
async request(path, init = {}) {
|
|
9
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
10
|
+
...init,
|
|
11
|
+
headers: {
|
|
12
|
+
...(init.body && typeof init.body === 'string' ? { 'content-type': 'application/json' } : {}),
|
|
13
|
+
...(this.apiKey ? { authorization: `Bearer ${this.apiKey}` } : {}),
|
|
14
|
+
...(init.headers || {}),
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
if (!res.ok)
|
|
18
|
+
throw new Error(`${res.status} ${await res.text()}`);
|
|
19
|
+
return res.json();
|
|
20
|
+
}
|
|
21
|
+
filePath(path) {
|
|
22
|
+
return path
|
|
23
|
+
.split('/')
|
|
24
|
+
.filter((segment) => segment.length > 0)
|
|
25
|
+
.map(encodeURIComponent)
|
|
26
|
+
.join('/');
|
|
27
|
+
}
|
|
28
|
+
health() {
|
|
29
|
+
return this.request('/health');
|
|
30
|
+
}
|
|
31
|
+
images = {
|
|
32
|
+
create: (body) => this.request('/v1/images', { method: 'POST', body: JSON.stringify(body) }),
|
|
33
|
+
list: () => this.request('/v1/images'),
|
|
34
|
+
get: (id) => this.request(`/v1/images/${encodeURIComponent(id)}`),
|
|
35
|
+
build: (id) => this.request(`/v1/images/${encodeURIComponent(id)}/build`, { method: 'POST' }),
|
|
36
|
+
delete: (id) => this.request(`/v1/images/${encodeURIComponent(id)}`, { method: 'DELETE' }),
|
|
37
|
+
};
|
|
38
|
+
volumes = {
|
|
39
|
+
create: (body) => this.request('/v1/volumes', { method: 'POST', body: JSON.stringify(body) }),
|
|
40
|
+
list: () => this.request('/v1/volumes'),
|
|
41
|
+
get: (id) => this.request(`/v1/volumes/${encodeURIComponent(id)}`),
|
|
42
|
+
delete: (id) => this.request(`/v1/volumes/${encodeURIComponent(id)}`, { method: 'DELETE' }),
|
|
43
|
+
};
|
|
44
|
+
snapshots = {
|
|
45
|
+
create: (body) => this.request('/v1/snapshots', { method: 'POST', body: JSON.stringify(body) }),
|
|
46
|
+
list: () => this.request('/v1/snapshots'),
|
|
47
|
+
get: (id) => this.request(`/v1/snapshots/${encodeURIComponent(id)}`),
|
|
48
|
+
delete: (id) => this.request(`/v1/snapshots/${encodeURIComponent(id)}`, { method: 'DELETE' }),
|
|
49
|
+
};
|
|
50
|
+
sandboxes = {
|
|
51
|
+
create: (body) => this.request('/v1/sandboxes', { method: 'POST', body: JSON.stringify(body) }),
|
|
52
|
+
list: () => this.request('/v1/sandboxes'),
|
|
53
|
+
get: (id) => this.request(`/v1/sandboxes/${encodeURIComponent(id)}`),
|
|
54
|
+
start: (id) => this.request(`/v1/sandboxes/${encodeURIComponent(id)}/start`, { method: 'POST' }),
|
|
55
|
+
stop: (id) => this.request(`/v1/sandboxes/${encodeURIComponent(id)}/stop`, { method: 'POST' }),
|
|
56
|
+
delete: (id) => this.request(`/v1/sandboxes/${encodeURIComponent(id)}`, { method: 'DELETE' }),
|
|
57
|
+
exec: (id, body) => this.request(`/v1/sandboxes/${encodeURIComponent(id)}/exec`, { method: 'POST', body: JSON.stringify(body) }),
|
|
58
|
+
readFile: async (id, filePath) => {
|
|
59
|
+
const res = await fetch(`${this.baseUrl}/v1/sandboxes/${encodeURIComponent(id)}/files/${this.filePath(filePath)}`, {
|
|
60
|
+
headers: this.apiKey ? { authorization: `Bearer ${this.apiKey}` } : {},
|
|
61
|
+
});
|
|
62
|
+
if (!res.ok)
|
|
63
|
+
throw new Error(`${res.status} ${await res.text()}`);
|
|
64
|
+
return Buffer.from(await res.arrayBuffer());
|
|
65
|
+
},
|
|
66
|
+
writeFile: (id, filePath, body) => this.request(`/v1/sandboxes/${encodeURIComponent(id)}/files/${this.filePath(filePath)}`, {
|
|
67
|
+
method: 'PUT',
|
|
68
|
+
headers: { 'content-type': 'application/octet-stream' },
|
|
69
|
+
body,
|
|
70
|
+
}),
|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A;QAC7C,CAAC;QACD,SAAS,EAAE,CAAC,EAAU,EAAE,QAAgB,EAAE,IAAqB,EAAE,EAAE,CACjE,IAAI,CAAC,OAAO,CAAkC,iBAAiB,kBAAkB,CAAC,EAAE,CAAC,UAAU,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE;YACxH,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,EAAE,cAAc,EAAE,0BAA0B,EAAE;YACvD,IAAI;SACL,CAAC;KACL,CAAA;CACF"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC9C,cAAc,YAAY,CAAA"}
|
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface StorePaths {
|
|
2
|
+
root: string;
|
|
3
|
+
sandboxes: string;
|
|
4
|
+
images: string;
|
|
5
|
+
snapshots: string;
|
|
6
|
+
volumes: string;
|
|
7
|
+
events: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function defaultRoot(): string;
|
|
10
|
+
export declare function storePaths(root?: string): StorePaths;
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export function defaultRoot() {
|
|
4
|
+
return process.env.APPLE_SANDBOXES_HOME || path.join(os.homedir(), '.apple-sandboxes');
|
|
5
|
+
}
|
|
6
|
+
export function storePaths(root = defaultRoot()) {
|
|
7
|
+
return {
|
|
8
|
+
root,
|
|
9
|
+
sandboxes: path.join(root, 'sandboxes'),
|
|
10
|
+
images: path.join(root, 'images'),
|
|
11
|
+
snapshots: path.join(root, 'snapshots'),
|
|
12
|
+
volumes: path.join(root, 'volumes'),
|
|
13
|
+
events: path.join(root, 'events'),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAW5B,MAAM,UAAU,WAAW;IACzB,OAAO,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,kBAAkB,CAAC,CAAA;AACxF,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAI,GAAG,WAAW,EAAE;IAC7C,OAAO;QACL,IAAI;QACJ,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC;QACvC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC;QACjC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC;QACvC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC;QACnC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC;KAClC,CAAA;AACH,CAAC"}
|