@saikrishnaambeti/docker-sandbox 1.0.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 +21 -0
- package/README.md +178 -0
- package/dist/cli/cpufeatures-h04yv4n7.node +0 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +52803 -0
- package/dist/cli/sshcrypto-npryzwb9.node +0 -0
- package/dist/cpufeatures-h04yv4n7.node +0 -0
- package/dist/index-rff3tvyv.js +21 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/sdk/index.d.ts +67 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/index.js +128 -0
- package/dist/server/index.d.ts +18 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +52727 -0
- package/dist/sshcrypto-npryzwb9.node +0 -0
- package/package.json +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# docker-sandbox
|
|
2
|
+
|
|
3
|
+
A Docker-based sandbox for running isolated code execution environments. Start a server with one `npx` command and use the SDK to create and manage sandboxes.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🐳 Create isolated Docker containers for code execution
|
|
8
|
+
- 🔄 Clone Git repositories into sandboxes
|
|
9
|
+
- 🔌 Expose and map container ports
|
|
10
|
+
- 📡 Stream command output in real-time
|
|
11
|
+
- 🎯 Simple SDK for programmatic control
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
### Start the Server
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# Using npx (no installation required)
|
|
19
|
+
npx docker-sandbox
|
|
20
|
+
|
|
21
|
+
# Or with a custom port
|
|
22
|
+
npx docker-sandbox --port 8080
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Install the SDK
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Using npm
|
|
29
|
+
npm install docker-sandbox
|
|
30
|
+
|
|
31
|
+
# Using bun
|
|
32
|
+
bun add docker-sandbox
|
|
33
|
+
|
|
34
|
+
# Using yarn
|
|
35
|
+
yarn add docker-sandbox
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Use the SDK
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { Sandbox, createLogStream } from "docker-sandbox";
|
|
42
|
+
|
|
43
|
+
async function main() {
|
|
44
|
+
// Create a sandbox
|
|
45
|
+
const sandbox = await Sandbox.create({
|
|
46
|
+
runtime: "node22",
|
|
47
|
+
ports: [3000],
|
|
48
|
+
source: {
|
|
49
|
+
url: "https://github.com/your/repo.git",
|
|
50
|
+
type: "git",
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Run commands
|
|
55
|
+
await sandbox.runCommand({
|
|
56
|
+
cmd: "npm",
|
|
57
|
+
args: ["install"],
|
|
58
|
+
stdout: createLogStream(process.stdout),
|
|
59
|
+
stderr: createLogStream(process.stderr),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Start a dev server (detached)
|
|
63
|
+
await sandbox.runCommand({
|
|
64
|
+
cmd: "npm",
|
|
65
|
+
args: ["run", "dev"],
|
|
66
|
+
detached: true,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Get the URL for the exposed port
|
|
70
|
+
const url = sandbox.domain(3000);
|
|
71
|
+
console.log(`Server running at: ${url}`);
|
|
72
|
+
|
|
73
|
+
// Clean up when done
|
|
74
|
+
await sandbox.destroy();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
main();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## CLI Options
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
Usage:
|
|
84
|
+
docker-sandbox [options]
|
|
85
|
+
|
|
86
|
+
Options:
|
|
87
|
+
-p, --port <port> Port to run the server on (default: 4000)
|
|
88
|
+
-h, --help Show help message
|
|
89
|
+
-v, --version Show version
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## SDK API
|
|
93
|
+
|
|
94
|
+
### `Sandbox.create(options)`
|
|
95
|
+
|
|
96
|
+
Create a new sandbox container.
|
|
97
|
+
|
|
98
|
+
**Options:**
|
|
99
|
+
|
|
100
|
+
- `serverUrl?: string` - Server URL (default: `http://localhost:4000`)
|
|
101
|
+
- `source?: { url: string, type: "git" }` - Git repository to clone
|
|
102
|
+
- `timeout?: number` - Timeout in milliseconds
|
|
103
|
+
- `ports?: number[]` - Ports to expose from the container
|
|
104
|
+
- `runtime?: string` - Runtime environment (e.g., `"node22"`)
|
|
105
|
+
|
|
106
|
+
**Returns:** `Promise<Sandbox>`
|
|
107
|
+
|
|
108
|
+
### `sandbox.runCommand(options)`
|
|
109
|
+
|
|
110
|
+
Run a command in the sandbox.
|
|
111
|
+
|
|
112
|
+
**Options:**
|
|
113
|
+
|
|
114
|
+
- `cmd: string` - Command to run
|
|
115
|
+
- `args: string[]` - Arguments for the command
|
|
116
|
+
- `env?: Record<string, string>` - Environment variables
|
|
117
|
+
- `stdout?: WritableStream<Uint8Array>` - Stream for stdout
|
|
118
|
+
- `stderr?: WritableStream<Uint8Array>` - Stream for stderr
|
|
119
|
+
- `detached?: boolean` - Run in background
|
|
120
|
+
|
|
121
|
+
**Returns:** `Promise<{ exitCode: number }>`
|
|
122
|
+
|
|
123
|
+
### `sandbox.domain(port)`
|
|
124
|
+
|
|
125
|
+
Get the URL for an exposed port.
|
|
126
|
+
|
|
127
|
+
**Returns:** `string` (e.g., `http://localhost:32789`)
|
|
128
|
+
|
|
129
|
+
### `sandbox.getInfo()`
|
|
130
|
+
|
|
131
|
+
Get container information.
|
|
132
|
+
|
|
133
|
+
**Returns:** `Promise<unknown>`
|
|
134
|
+
|
|
135
|
+
### `sandbox.destroy()`
|
|
136
|
+
|
|
137
|
+
Stop and remove the sandbox container.
|
|
138
|
+
|
|
139
|
+
**Returns:** `Promise<void>`
|
|
140
|
+
|
|
141
|
+
### `createLogStream(stream)`
|
|
142
|
+
|
|
143
|
+
Helper to create a `WritableStream` from Node.js `stdout`/`stderr`.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { createLogStream } from "docker-sandbox";
|
|
147
|
+
|
|
148
|
+
await sandbox.runCommand({
|
|
149
|
+
cmd: "echo",
|
|
150
|
+
args: ["hello"],
|
|
151
|
+
stdout: createLogStream(process.stdout),
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Development
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
# Install dependencies
|
|
159
|
+
bun install
|
|
160
|
+
|
|
161
|
+
# Run the server in development mode
|
|
162
|
+
bun run dev
|
|
163
|
+
|
|
164
|
+
# Build the package
|
|
165
|
+
bun run build
|
|
166
|
+
|
|
167
|
+
# Run the example
|
|
168
|
+
bun run example
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Requirements
|
|
172
|
+
|
|
173
|
+
- Docker must be installed and running
|
|
174
|
+
- Node.js 18+ or Bun
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
MIT
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":""}
|