@computesdk/docker 1.2.45 → 1.2.47

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.
Files changed (2) hide show
  1. package/README.md +19 -79
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -35,26 +35,6 @@ Common environment variables (used by Docker/dockerode):
35
35
 
36
36
  ## Usage
37
37
 
38
- ### Gateway Mode (Recommended)
39
-
40
- Use the gateway for zero-config auto-detection:
41
-
42
- ```ts
43
- import { compute } from 'computesdk';
44
-
45
- // Auto-detects Docker (requires Docker daemon running)
46
- const sandbox = await compute.sandbox.create();
47
-
48
- const result = await sandbox.runCommand('python -c "print(\"Hello from Python\")"');
49
- console.log(result.stdout.trim()); // Hello from Python
50
-
51
- await sandbox.destroy();
52
- ```
53
-
54
- ### Direct Mode
55
-
56
- For direct SDK usage without the gateway:
57
-
58
38
  ```ts
59
39
  import { docker } from '@computesdk/docker';
60
40
 
@@ -90,7 +70,7 @@ const sandbox = await compute.sandbox.create();
90
70
  const result = await sandbox.runCommand('node -e "console.log(\"Hello, World!\")"');
91
71
  console.log(result.stdout.trim()); // Hello, World!
92
72
 
93
- const cmd = await sandbox.runCommand('sh', ['-lc', 'echo Hello from command']);
73
+ const cmd = await sandbox.runCommand('echo Hello from command');
94
74
  console.log(cmd.stdout.trim()); // Hello from command
95
75
 
96
76
  await sandbox.destroy();
@@ -186,24 +166,15 @@ Type: `DockerConfig`
186
166
 
187
167
  ## API Reference
188
168
 
189
- ### Code Execution
190
-
191
- ```ts
192
- sandbox.runCommand(code: string, runtime?: 'python' | 'node'): Promise<ExecutionResult>
193
- ```
194
-
195
- * If `runtime` omitted, the sandbox’s runtime (set at creation) is used.
196
- * Returns `{ stdout, stderr, exitCode, executionTime, sandboxId, provider }`
197
- * Syntax errors are **thrown** as `Error("Syntax error: …")`.
198
-
199
169
  ### Command Execution
200
170
 
201
171
  ```ts
202
- sandbox.runCommand(command: string, args?: string[], options?: { background?: boolean }): Promise<ExecutionResult>
172
+ sandbox.runCommand(command: string, options?: RunCommandOptions): Promise<CommandResult>
203
173
  ```
204
174
 
205
175
  * Runs via `/bin/sh -c "…"` with stdout/stderr capture.
206
- * Background returns `{ isBackground: true, pid?: number }`.
176
+ * Returns `{ stdout, stderr, exitCode, durationMs }`.
177
+ * Options: `{ cwd?, env?, timeout?, background? }`.
207
178
 
208
179
  ### Filesystem Operations
209
180
 
@@ -220,14 +191,14 @@ sandbox.filesystem.remove(path)
220
191
 
221
192
  ### Terminal Operations
222
193
 
223
- Interactive terminals aren’t exposed. Use `runCommand('sh', ['-lc', '…'])` for non-interactive sessions.
194
+ Interactive terminals aren’t exposed. Use `runCommand('…')` for non-interactive sessions.
224
195
 
225
196
  ### Sandbox Management
226
197
 
227
198
  ```ts
228
- const sandbox = await compute.sandbox.create({ runtime?: 'python' | 'node' });
199
+ const sandbox = await compute.sandbox.create();
229
200
 
230
- await sandbox.getInfo(); // { id, provider, runtime, status, createdAt, timeout, metadata }
201
+ await sandbox.getInfo(); // { id, provider, status, createdAt, timeout, metadata }
231
202
  await sandbox.getUrl({ port, protocol?: 'http' | 'https' });
232
203
  sandbox.getInstance(); // { docker: Docker, container: Container, ... }
233
204
  await sandbox.destroy();
@@ -235,25 +206,13 @@ await sandbox.destroy();
235
206
 
236
207
  ---
237
208
 
238
- ## Runtime Detection
239
-
240
- There’s **no auto-detection**. Resolution is:
241
-
242
- 1. provider `config.runtime`, else
243
- 2. fallback default in provider config
244
-
245
- Use `runCommand('python -c "..."')` or `runCommand('node -e "..."')` when you need language-specific execution.
246
-
247
- ---
248
-
249
209
  ## Error Handling
250
210
 
251
- * **Syntax errors** → **thrown** (`Error("Syntax error: …")`)
252
- * **Runtime/command errors** → returned as non-zero `exitCode` with `stderr`
211
+ * **Command errors** → returned as non-zero `exitCode` with `stderr`
253
212
  * **Docker errors** (pull/start/exec) → **thrown**
254
213
 
255
214
  ```ts
256
- const res = await sb.runCommand('sh', ['-lc', 'bad-command']);
215
+ const res = await sb.runCommand('bad-command');
257
216
  if (res.exitCode !== 0) {
258
217
  console.error('stderr:', res.stderr);
259
218
  }
@@ -261,55 +220,36 @@ if (res.exitCode !== 0) {
261
220
 
262
221
  ---
263
222
 
264
- ## Web Framework Integration
265
-
266
- ```ts
267
- import { handleComputeRequest } from 'computesdk';
268
- import { docker } from '@computesdk/docker';
269
-
270
- const compute = docker({
271
- runtime: 'node',
272
- image: { name: 'node:20-alpine' },
273
- });
274
-
275
- export async function POST(req: Request) {
276
- const body = await req.json(); // ComputeRequest
277
- return handleComputeRequest(body, compute);
278
- }
279
- ```
280
-
281
- ---
282
-
283
223
  ## Examples
284
224
 
285
225
  ### Data Science Workflow (Python)
286
226
 
287
227
  ```ts
288
- const sandbox = await compute.sandbox.create({ runtime: 'python' });
289
- await sandbox.runCommand('sh', ['-lc', 'python3 -m pip install --no-cache-dir pandas']);
228
+ const sandbox = await compute.sandbox.create();
229
+ await sandbox.runCommand('python3 -m pip install --no-cache-dir pandas');
290
230
  await sandbox.filesystem.writeFile('/workspace/app.py', `
291
231
  import pandas as pd
292
232
  print("rows:", len(pd.DataFrame({"x":[1,2,3]})))
293
233
  `);
294
- const run = await sandbox.runCommand('sh', ['-lc', 'python3 /workspace/app.py']);
234
+ const run = await sandbox.runCommand('python3 /workspace/app.py');
295
235
  console.log(run.stdout.trim()); // rows: 3
296
236
  await sandbox.destroy();
297
237
  ```
298
238
 
299
- ### Interactive-like Loop
239
+ ### Stateful Loop
300
240
 
301
241
  ```ts
302
- const sandbox = await compute.sandbox.create({ runtime: 'node' });
303
- await sandbox.runCommand('sh', ['-lc', 'echo boot > /tmp/state']);
304
- await sandbox.runCommand('sh', ['-lc', 'cat /tmp/state']); // 'boot'
242
+ const sandbox = await compute.sandbox.create();
243
+ await sandbox.runCommand('echo boot > /tmp/state');
244
+ const res = await sandbox.runCommand('cat /tmp/state'); // 'boot'
305
245
  await sandbox.destroy();
306
246
  ```
307
247
 
308
- ### Machine Learning Pipeline (Python + Ports)
248
+ ### Background Process + Ports
309
249
 
310
250
  ```ts
311
- const sandbox = await compute.sandbox.create({ runtime: 'python' });
312
- const bg = await sandbox.runCommand('sh', ['-lc', 'python3 -m http.server 8080'], { background: true });
251
+ const sandbox = await compute.sandbox.create();
252
+ await sandbox.runCommand('python3 -m http.server 8080', { background: true });
313
253
  const url = await sandbox.getUrl({ port: 8080 });
314
254
  console.log('Serving at', url);
315
255
  await sandbox.destroy();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@computesdk/docker",
3
- "version": "1.2.45",
3
+ "version": "1.2.47",
4
4
  "description": "Docker provider for ComputeSDK - local containerized sandboxes for development and testing",
5
5
  "author": "IberAI",
6
6
  "license": "MIT",
@@ -19,8 +19,8 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "dockerode": "^4.0.8",
22
- "@computesdk/provider": "2.0.0",
23
- "computesdk": "4.0.0"
22
+ "@computesdk/provider": "2.1.1",
23
+ "computesdk": "4.1.1"
24
24
  },
25
25
  "keywords": [
26
26
  "computesdk",