@cloudflare/sandbox 0.0.0-4aceb32 → 0.0.0-50bc24c

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 (66) hide show
  1. package/CHANGELOG.md +208 -0
  2. package/Dockerfile +107 -66
  3. package/README.md +87 -710
  4. package/dist/index.d.ts +1907 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +3159 -0
  7. package/dist/index.js.map +1 -0
  8. package/package.json +16 -8
  9. package/src/clients/base-client.ts +280 -0
  10. package/src/clients/command-client.ts +115 -0
  11. package/src/clients/file-client.ts +295 -0
  12. package/src/clients/git-client.ts +92 -0
  13. package/src/clients/index.ts +64 -0
  14. package/src/{jupyter-client.ts → clients/interpreter-client.ts} +148 -168
  15. package/src/clients/port-client.ts +105 -0
  16. package/src/clients/process-client.ts +177 -0
  17. package/src/clients/sandbox-client.ts +41 -0
  18. package/src/clients/types.ts +84 -0
  19. package/src/clients/utility-client.ts +119 -0
  20. package/src/errors/adapter.ts +180 -0
  21. package/src/errors/classes.ts +469 -0
  22. package/src/errors/index.ts +105 -0
  23. package/src/file-stream.ts +164 -0
  24. package/src/index.ts +87 -48
  25. package/src/interpreter.ts +22 -13
  26. package/src/request-handler.ts +80 -44
  27. package/src/sandbox.ts +767 -449
  28. package/src/security.ts +14 -23
  29. package/src/sse-parser.ts +4 -8
  30. package/src/version.ts +6 -0
  31. package/startup.sh +3 -0
  32. package/tests/base-client.test.ts +328 -0
  33. package/tests/command-client.test.ts +407 -0
  34. package/tests/file-client.test.ts +719 -0
  35. package/tests/file-stream.test.ts +306 -0
  36. package/tests/get-sandbox.test.ts +149 -0
  37. package/tests/git-client.test.ts +328 -0
  38. package/tests/port-client.test.ts +301 -0
  39. package/tests/process-client.test.ts +658 -0
  40. package/tests/request-handler.test.ts +240 -0
  41. package/tests/sandbox.test.ts +641 -0
  42. package/tests/sse-parser.test.ts +290 -0
  43. package/tests/utility-client.test.ts +332 -0
  44. package/tests/version.test.ts +16 -0
  45. package/tests/wrangler.jsonc +35 -0
  46. package/tsconfig.json +9 -1
  47. package/tsdown.config.ts +12 -0
  48. package/vitest.config.ts +31 -0
  49. package/container_src/bun.lock +0 -122
  50. package/container_src/circuit-breaker.ts +0 -121
  51. package/container_src/handler/exec.ts +0 -340
  52. package/container_src/handler/file.ts +0 -844
  53. package/container_src/handler/git.ts +0 -182
  54. package/container_src/handler/ports.ts +0 -314
  55. package/container_src/handler/process.ts +0 -640
  56. package/container_src/index.ts +0 -656
  57. package/container_src/jupyter-server.ts +0 -579
  58. package/container_src/jupyter-service.ts +0 -448
  59. package/container_src/mime-processor.ts +0 -255
  60. package/container_src/package.json +0 -18
  61. package/container_src/startup.sh +0 -83
  62. package/container_src/types.ts +0 -108
  63. package/src/client.ts +0 -1021
  64. package/src/errors.ts +0 -218
  65. package/src/interpreter-types.ts +0 -383
  66. package/src/types.ts +0 -401
@@ -1,18 +0,0 @@
1
- {
2
- "name": "sandbox-server",
3
- "version": "1.0.0",
4
- "description": "A server for the sandbox package",
5
- "main": "index.ts",
6
- "scripts": {
7
- "start": "bun run index.ts"
8
- },
9
- "dependencies": {
10
- "@jupyterlab/services": "^7.0.0",
11
- "ws": "^8.16.0",
12
- "uuid": "^9.0.1"
13
- },
14
- "devDependencies": {
15
- "@types/ws": "^8.5.10",
16
- "@types/uuid": "^9.0.7"
17
- }
18
- }
@@ -1,83 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Function to check if Jupyter is ready
4
- check_jupyter_ready() {
5
- curl -s http://localhost:8888/api > /dev/null 2>&1
6
- }
7
-
8
- # Function to notify Bun server that Jupyter is ready
9
- notify_jupyter_ready() {
10
- # Create a marker file that the Bun server can check
11
- touch /tmp/jupyter-ready
12
- echo "[Startup] Jupyter is ready, notified Bun server"
13
- }
14
-
15
- # Start Jupyter notebook server in background
16
- echo "[Startup] Starting Jupyter server..."
17
- jupyter notebook \
18
- --ip=0.0.0.0 \
19
- --port=8888 \
20
- --no-browser \
21
- --allow-root \
22
- --NotebookApp.token='' \
23
- --NotebookApp.password='' \
24
- --NotebookApp.allow_origin='*' \
25
- --NotebookApp.disable_check_xsrf=True \
26
- --NotebookApp.allow_remote_access=True \
27
- --NotebookApp.allow_credentials=True \
28
- > /tmp/jupyter.log 2>&1 &
29
-
30
- JUPYTER_PID=$!
31
-
32
- # Start Bun server immediately (parallel startup)
33
- echo "[Startup] Starting Bun server..."
34
- bun index.ts &
35
- BUN_PID=$!
36
-
37
- # Monitor Jupyter readiness in background
38
- (
39
- echo "[Startup] Monitoring Jupyter readiness in background..."
40
- MAX_ATTEMPTS=30
41
- ATTEMPT=0
42
- DELAY=0.5
43
- MAX_DELAY=5
44
-
45
- while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
46
- if check_jupyter_ready; then
47
- notify_jupyter_ready
48
- echo "[Startup] Jupyter server is ready after $ATTEMPT attempts"
49
- break
50
- fi
51
-
52
- # Check if Jupyter process is still running
53
- if ! kill -0 $JUPYTER_PID 2>/dev/null; then
54
- echo "[Startup] WARNING: Jupyter process died. Check /tmp/jupyter.log for details"
55
- cat /tmp/jupyter.log
56
- # Don't exit - let Bun server continue running in degraded mode
57
- break
58
- fi
59
-
60
- ATTEMPT=$((ATTEMPT + 1))
61
- echo "[Startup] Jupyter not ready yet (attempt $ATTEMPT/$MAX_ATTEMPTS, delay ${DELAY}s)"
62
-
63
- # Sleep with exponential backoff
64
- sleep $DELAY
65
-
66
- # Increase delay exponentially with jitter, cap at MAX_DELAY
67
- DELAY=$(awk "BEGIN {printf \"%.2f\", $DELAY * 1.5 + (rand() * 0.5)}")
68
- # Use awk for comparison since bc might not be available
69
- if [ $(awk "BEGIN {print ($DELAY > $MAX_DELAY)}") -eq 1 ]; then
70
- DELAY=$MAX_DELAY
71
- fi
72
- done
73
-
74
- if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
75
- echo "[Startup] WARNING: Jupyter failed to become ready within attempts"
76
- echo "[Startup] Jupyter logs:"
77
- cat /tmp/jupyter.log
78
- # Don't exit - let Bun server continue in degraded mode
79
- fi
80
- ) &
81
-
82
- # Wait for Bun server (main process)
83
- wait $BUN_PID
@@ -1,108 +0,0 @@
1
- import type { ChildProcess } from "node:child_process";
2
-
3
- // Process management types
4
- export type ProcessStatus =
5
- | 'starting'
6
- | 'running'
7
- | 'completed'
8
- | 'failed'
9
- | 'killed'
10
- | 'error';
11
-
12
- export interface ProcessRecord {
13
- id: string;
14
- pid?: number;
15
- command: string;
16
- status: ProcessStatus;
17
- startTime: Date;
18
- endTime?: Date;
19
- exitCode?: number;
20
- sessionId?: string;
21
- childProcess?: ChildProcess;
22
- stdout: string;
23
- stderr: string;
24
- outputListeners: Set<(stream: 'stdout' | 'stderr', data: string) => void>;
25
- statusListeners: Set<(status: ProcessStatus) => void>;
26
- }
27
-
28
- export interface StartProcessRequest {
29
- command: string;
30
- options?: {
31
- processId?: string;
32
- sessionId?: string;
33
- timeout?: number;
34
- env?: Record<string, string>;
35
- cwd?: string;
36
- encoding?: string;
37
- autoCleanup?: boolean;
38
- };
39
- }
40
-
41
- export interface ExecuteOptions {
42
- sessionId?: string | null;
43
- background?: boolean;
44
- cwd?: string | URL;
45
- env?: Record<string, string>;
46
- }
47
-
48
- export interface ExecuteRequest extends ExecuteOptions {
49
- command: string;
50
- }
51
-
52
- export interface GitCheckoutRequest {
53
- repoUrl: string;
54
- branch?: string;
55
- targetDir?: string;
56
- sessionId?: string;
57
- }
58
-
59
- export interface MkdirRequest {
60
- path: string;
61
- recursive?: boolean;
62
- sessionId?: string;
63
- }
64
-
65
- export interface WriteFileRequest {
66
- path: string;
67
- content: string;
68
- encoding?: string;
69
- sessionId?: string;
70
- }
71
-
72
- export interface ReadFileRequest {
73
- path: string;
74
- encoding?: string;
75
- sessionId?: string;
76
- }
77
-
78
- export interface DeleteFileRequest {
79
- path: string;
80
- sessionId?: string;
81
- }
82
-
83
- export interface RenameFileRequest {
84
- oldPath: string;
85
- newPath: string;
86
- sessionId?: string;
87
- }
88
-
89
- export interface MoveFileRequest {
90
- sourcePath: string;
91
- destinationPath: string;
92
- sessionId?: string;
93
- }
94
-
95
- export interface ExposePortRequest {
96
- port: number;
97
- name?: string;
98
- }
99
-
100
- export interface UnexposePortRequest {
101
- port: number;
102
- }
103
-
104
- export interface SessionData {
105
- sessionId: string;
106
- activeProcess: ChildProcess | null;
107
- createdAt: Date;
108
- }