@cloudflare/sandbox 0.0.0-91b21b1 → 0.0.0-9375c1e

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 (40) hide show
  1. package/CHANGELOG.md +187 -0
  2. package/Dockerfile +99 -11
  3. package/README.md +806 -23
  4. package/container_src/bun.lock +122 -0
  5. package/container_src/circuit-breaker.ts +121 -0
  6. package/container_src/control-process.ts +784 -0
  7. package/container_src/handler/exec.ts +185 -0
  8. package/container_src/handler/file.ts +406 -0
  9. package/container_src/handler/git.ts +130 -0
  10. package/container_src/handler/ports.ts +314 -0
  11. package/container_src/handler/process.ts +568 -0
  12. package/container_src/handler/session.ts +92 -0
  13. package/container_src/index.ts +441 -2740
  14. package/container_src/isolation.ts +1038 -0
  15. package/container_src/jupyter-server.ts +579 -0
  16. package/container_src/jupyter-service.ts +461 -0
  17. package/container_src/jupyter_config.py +48 -0
  18. package/container_src/mime-processor.ts +255 -0
  19. package/container_src/package.json +9 -0
  20. package/container_src/shell-escape.ts +42 -0
  21. package/container_src/startup.sh +84 -0
  22. package/container_src/types.ts +131 -0
  23. package/package.json +6 -8
  24. package/src/client.ts +442 -1362
  25. package/src/errors.ts +218 -0
  26. package/src/index.ts +63 -128
  27. package/src/interpreter-types.ts +383 -0
  28. package/src/interpreter.ts +150 -0
  29. package/src/jupyter-client.ts +349 -0
  30. package/src/request-handler.ts +144 -0
  31. package/src/sandbox.ts +747 -0
  32. package/src/security.ts +113 -0
  33. package/src/sse-parser.ts +147 -0
  34. package/src/types.ts +502 -0
  35. package/tsconfig.json +1 -1
  36. package/tests/client.example.ts +0 -308
  37. package/tests/connection-test.ts +0 -81
  38. package/tests/simple-test.ts +0 -81
  39. package/tests/test1.ts +0 -281
  40. package/tests/test2.ts +0 -929
package/CHANGELOG.md CHANGED
@@ -1,5 +1,192 @@
1
1
  # @cloudflare/sandbox
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#71](https://github.com/cloudflare/sandbox-sdk/pull/71) [`fb3c9c2`](https://github.com/cloudflare/sandbox-sdk/commit/fb3c9c22242d9d4f157c26f547f1e697ef7875f9) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Bump containers package version
8
+
9
+ - [#70](https://github.com/cloudflare/sandbox-sdk/pull/70) [`e1fa354`](https://github.com/cloudflare/sandbox-sdk/commit/e1fa354ab1bc7b0e89db4901b67028ebf1a93d0a) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Fix escaped quotes in file write operations
10
+
11
+ - [#68](https://github.com/cloudflare/sandbox-sdk/pull/68) [`69b91d1`](https://github.com/cloudflare/sandbox-sdk/commit/69b91d1a8f6afb63262cc381ea93e94a033ed5e8) Thanks [@CyrusNuevoDia](https://github.com/CyrusNuevoDia)! - Configurable timeouts via environment variables in isolation.ts
12
+
13
+ - [#66](https://github.com/cloudflare/sandbox-sdk/pull/66) [`eca93b9`](https://github.com/cloudflare/sandbox-sdk/commit/eca93b97e40fa0d3bd9dc27af2cc214ec355b696) Thanks [@peterp](https://github.com/peterp)! - Determine if the port is specified in the URL.
14
+
15
+ ## 0.3.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [#59](https://github.com/cloudflare/sandbox-sdk/pull/59) [`b6757f7`](https://github.com/cloudflare/sandbox-sdk/commit/b6757f730c34381d5a70d513944bbf9840f598ab) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Add process isolation for sandbox commands
20
+
21
+ Implements PID namespace isolation to protect control plane processes (Jupyter, Bun) from sandboxed code. Commands executed via `exec()` now run in isolated namespaces that cannot see or interact with system processes.
22
+
23
+ **Key security improvements:**
24
+
25
+ - Control plane processes are hidden from sandboxed commands
26
+ - Platform secrets in `/proc/1/environ` are inaccessible
27
+ - Ports 8888 (Jupyter) and 3000 (Bun) are protected from hijacking
28
+
29
+ **Breaking changes:**
30
+
31
+ 1. **Removed `sessionId` parameter**: The `sessionId` parameter has been removed from all methods (`exec()`, `execStream()`, `startProcess()`, etc.). Each sandbox now maintains its own persistent session automatically.
32
+
33
+ ```javascript
34
+ // Before: manual session management
35
+ await sandbox.exec("cd /app", { sessionId: "my-session" });
36
+
37
+ // After: automatic session per sandbox
38
+ await sandbox.exec("cd /app");
39
+ ```
40
+
41
+ 2. **Commands now maintain state**: Commands within the same sandbox now share state (working directory, environment variables, background processes). Previously each command was stateless.
42
+
43
+ ```javascript
44
+ // Before: each exec was independent
45
+ await sandbox.exec("cd /app");
46
+ await sandbox.exec("pwd"); // Output: /workspace
47
+
48
+ // After: state persists in session
49
+ await sandbox.exec("cd /app");
50
+ await sandbox.exec("pwd"); // Output: /app
51
+ ```
52
+
53
+ **Migration guide:**
54
+
55
+ - Remove `sessionId` from all method calls - each sandbox maintains its own session
56
+ - If you need isolated execution contexts within the same sandbox, use `sandbox.createSession()`:
57
+ ```javascript
58
+ // Create independent sessions with different environments
59
+ const buildSession = await sandbox.createSession({
60
+ name: "build",
61
+ env: { NODE_ENV: "production" },
62
+ cwd: "/build",
63
+ });
64
+ const testSession = await sandbox.createSession({
65
+ name: "test",
66
+ env: { NODE_ENV: "test" },
67
+ cwd: "/test",
68
+ });
69
+ ```
70
+ - Environment variables set in one command persist to the next
71
+ - Background processes remain active until explicitly killed
72
+ - Requires CAP_SYS_ADMIN (available in production, falls back gracefully in dev)
73
+
74
+ ### Patch Changes
75
+
76
+ - [#62](https://github.com/cloudflare/sandbox-sdk/pull/62) [`4bedc3a`](https://github.com/cloudflare/sandbox-sdk/commit/4bedc3aba347f3d4090a6efe2c9778bac00ce74a) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Fix broken build due to bun lockfile not being used
77
+
78
+ ## 0.2.4
79
+
80
+ ### Patch Changes
81
+
82
+ - [#57](https://github.com/cloudflare/sandbox-sdk/pull/57) [`12bbd12`](https://github.com/cloudflare/sandbox-sdk/commit/12bbd1229c07ef8c1c0bf58a4235a27938155b08) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Add listFiles method
83
+
84
+ ## 0.2.3
85
+
86
+ ### Patch Changes
87
+
88
+ - [#53](https://github.com/cloudflare/sandbox-sdk/pull/53) [`c87db11`](https://github.com/cloudflare/sandbox-sdk/commit/c87db117693a86cfb667bf09fb7720d6a6e0524d) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Improve jupyterlab config to speed up startup
89
+
90
+ ## 0.2.2
91
+
92
+ ### Patch Changes
93
+
94
+ - [#51](https://github.com/cloudflare/sandbox-sdk/pull/51) [`4aceb32`](https://github.com/cloudflare/sandbox-sdk/commit/4aceb3215c836f59afcb88b2b325016b3f623f46) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Handle intermittent interpreter failures and decouple jupyter startup
95
+
96
+ ## 0.2.1
97
+
98
+ ### Patch Changes
99
+
100
+ - [#49](https://github.com/cloudflare/sandbox-sdk/pull/49) [`d81d2a5`](https://github.com/cloudflare/sandbox-sdk/commit/d81d2a563c9af8947d5444019ed4d6156db563e3) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Implement code interpreter API
101
+
102
+ ## 0.2.0
103
+
104
+ ### Minor Changes
105
+
106
+ - [#47](https://github.com/cloudflare/sandbox-sdk/pull/47) [`8a93d0c`](https://github.com/cloudflare/sandbox-sdk/commit/8a93d0cae18a25bda6506b8b0a08d9e9eb3bb290) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Change default directory to a clean /workspace
107
+
108
+ ## 0.1.4
109
+
110
+ ### Patch Changes
111
+
112
+ - [#46](https://github.com/cloudflare/sandbox-sdk/pull/46) [`7de28be`](https://github.com/cloudflare/sandbox-sdk/commit/7de28be482d9634551572d548c7c4b5842df812d) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Update README
113
+
114
+ - [#44](https://github.com/cloudflare/sandbox-sdk/pull/44) [`215ab49`](https://github.com/cloudflare/sandbox-sdk/commit/215ab494427d7e2a92bb9a25384cb493a221c200) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Update example to use env & cwd
115
+
116
+ - [#42](https://github.com/cloudflare/sandbox-sdk/pull/42) [`bb72193`](https://github.com/cloudflare/sandbox-sdk/commit/bb72193ad75695979bd1132206f481e91fe37325) Thanks [@jonasnobile](https://github.com/jonasnobile)! - Propagate `cwd` and `env` options in `executeCommand`
117
+
118
+ - [#27](https://github.com/cloudflare/sandbox-sdk/pull/27) [`fd5ec7f`](https://github.com/cloudflare/sandbox-sdk/commit/fd5ec7f34bc12b06320a89356c4af07801f52d64) Thanks [@threepointone](https://github.com/threepointone)! - remove yarn and pnpm from the image
119
+
120
+ ## 0.1.3
121
+
122
+ ### Patch Changes
123
+
124
+ - [#32](https://github.com/cloudflare/sandbox-sdk/pull/32) [`1a42464`](https://github.com/cloudflare/sandbox-sdk/commit/1a4246479369c5d0160705caf192aa1816540d52) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Bring back package README
125
+
126
+ ## 0.1.2
127
+
128
+ ### Patch Changes
129
+
130
+ - [#30](https://github.com/cloudflare/sandbox-sdk/pull/30) [`30e5c25`](https://github.com/cloudflare/sandbox-sdk/commit/30e5c25cf7d4b07f9049724206c531e2d5d29d5c) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Remove actions timeout
131
+
132
+ - [#29](https://github.com/cloudflare/sandbox-sdk/pull/29) [`d78508f`](https://github.com/cloudflare/sandbox-sdk/commit/d78508f7287a59e0423edd2999c2c83e9e34ccfd) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Create multi-platform Docker image and switch to Cloudflare official repo
133
+
134
+ ## 0.1.1
135
+
136
+ ### Patch Changes
137
+
138
+ - [`157dde9`](https://github.com/cloudflare/sandbox-sdk/commit/157dde9b1f23e9bb6f3e9c3f0514b639a8813897) Thanks [@threepointone](https://github.com/threepointone)! - update deps
139
+
140
+ - [`a04f6b6`](https://github.com/cloudflare/sandbox-sdk/commit/a04f6b6c0b2ef9e3ce0851b53769f1c10d8c6de6) Thanks [@threepointone](https://github.com/threepointone)! - trigger a build with updated deps
141
+
142
+ ## 0.1.0
143
+
144
+ ### Minor Changes
145
+
146
+ - [#24](https://github.com/cloudflare/sandbox-sdk/pull/24) [`cecde0a`](https://github.com/cloudflare/sandbox-sdk/commit/cecde0a7530a87deffd8562fb8b01d66ee80ee19) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Redesign command execution API
147
+
148
+ ### Patch Changes
149
+
150
+ - [#22](https://github.com/cloudflare/sandbox-sdk/pull/22) [`f5fcd52`](https://github.com/cloudflare/sandbox-sdk/commit/f5fcd52025d1f7958a374e69d75e3fc590275f3f) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Allow setting env variables dynamically and remove command restrictions
151
+
152
+ ## 0.0.9
153
+
154
+ ### Patch Changes
155
+
156
+ - [#20](https://github.com/cloudflare/sandbox-sdk/pull/20) [`f106fda`](https://github.com/cloudflare/sandbox-sdk/commit/f106fdac98e7ef35677326290d45cbf3af88982c) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - add preview URLs and dynamic port forwarding
157
+
158
+ ## 0.0.8
159
+
160
+ ### Patch Changes
161
+
162
+ - [`60af265`](https://github.com/cloudflare/sandbox-sdk/commit/60af265d834e83fd30a921a3e1be232f13fe24da) Thanks [@threepointone](https://github.com/threepointone)! - update dependencies
163
+
164
+ ## 0.0.7
165
+
166
+ ### Patch Changes
167
+
168
+ - [`d1c7c99`](https://github.com/cloudflare/sandbox-sdk/commit/d1c7c99df6555eff71bcd59852e4b8eed2ad8cb6) Thanks [@threepointone](https://github.com/threepointone)! - fix file operations
169
+
170
+ ## 0.0.6
171
+
172
+ ### Patch Changes
173
+
174
+ - [#9](https://github.com/cloudflare/sandbox-sdk/pull/9) [`24f5470`](https://github.com/cloudflare/sandbox-sdk/commit/24f547048d5a26137de4656cea13d83ad2cc0b43) Thanks [@ItsWendell](https://github.com/ItsWendell)! - fix baseUrl for stub and stub forwarding
175
+
176
+ ## 0.0.5
177
+
178
+ ### Patch Changes
179
+
180
+ - [#5](https://github.com/cloudflare/sandbox-sdk/pull/5) [`7c15b81`](https://github.com/cloudflare/sandbox-sdk/commit/7c15b817899e4d9e1f25747aaf439e5e9e880d15) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Make package ready for deployment
181
+
182
+ ## 0.0.4
183
+
184
+ ### Patch Changes
185
+
186
+ - [`c0d9d33`](https://github.com/cloudflare/sandbox-sdk/commit/c0d9d3396badee1eab45e6b4a73d48957f31409b) Thanks [@threepointone](https://github.com/threepointone)! - actually work
187
+
188
+ - [`444d2da`](https://github.com/cloudflare/sandbox-sdk/commit/444d2dafde9a0f190e50c879b0e768da1b289b51) Thanks [@threepointone](https://github.com/threepointone)! - add experimental label
189
+
3
190
  ## 0.0.3
4
191
 
5
192
  ### Patch Changes
package/Dockerfile CHANGED
@@ -1,16 +1,104 @@
1
- # syntax=docker/dockerfile:1
1
+ # Sandbox base image with development tools, Python, Node.js, and Bun
2
+ FROM oven/bun:latest AS bun-source
3
+ FROM ubuntu:22.04
2
4
 
3
- FROM oven/bun:latest
4
- # Set destination for COPY
5
- WORKDIR /app
5
+ # Prevent interactive prompts during package installation
6
+ ENV DEBIAN_FRONTEND=noninteractive
6
7
 
7
- # Install git
8
- RUN apt-get update && apt-get install -y git
8
+ # Install essential system packages and development tools
9
+ RUN apt-get update && apt-get install -y \
10
+ # Basic utilities
11
+ curl \
12
+ wget \
13
+ git \
14
+ unzip \
15
+ zip \
16
+ # Process management
17
+ procps \
18
+ htop \
19
+ # Build tools
20
+ build-essential \
21
+ pkg-config \
22
+ # Network tools
23
+ net-tools \
24
+ iputils-ping \
25
+ dnsutils \
26
+ # Text processing
27
+ jq \
28
+ vim \
29
+ nano \
30
+ # Python dependencies
31
+ python3.11 \
32
+ python3.11-dev \
33
+ python3-pip \
34
+ python3.11-venv \
35
+ # Other useful tools
36
+ ca-certificates \
37
+ gnupg \
38
+ lsb-release \
39
+ strace \
40
+ && rm -rf /var/lib/apt/lists/*
9
41
 
10
- COPY container_src/* ./
11
- # RUN bun install
42
+ # Set Python 3.11 as default python3
43
+ RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1
12
44
 
13
- EXPOSE 3000
14
- # Run
15
- CMD ["bun", "index.ts"]
45
+ # Install Node.js 20 LTS using official NodeSource setup script
46
+ RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
47
+ && apt-get install -y nodejs \
48
+ && rm -rf /var/lib/apt/lists/*
16
49
 
50
+ # Install Bun from official image (avoids architecture compatibility issues)
51
+ COPY --from=bun-source /usr/local/bin/bun /usr/local/bin/bun
52
+ COPY --from=bun-source /usr/local/bin/bunx /usr/local/bin/bunx
53
+
54
+ # Install minimal Jupyter components
55
+ RUN pip3 install --no-cache-dir \
56
+ jupyter-server \
57
+ jupyter-client \
58
+ ipykernel \
59
+ orjson \
60
+ && python3 -m ipykernel install --user --name python3
61
+
62
+ # Install scientific packages
63
+ RUN pip3 install --no-cache-dir \
64
+ matplotlib \
65
+ numpy \
66
+ pandas \
67
+ seaborn
68
+
69
+ # Install JavaScript kernel (ijavascript) - using E2B's fork
70
+ RUN npm install -g git+https://github.com/e2b-dev/ijavascript.git \
71
+ && ijsinstall --install=global
72
+
73
+ # Set up container server directory
74
+ WORKDIR /container-server
75
+
76
+ # Verify installations
77
+ RUN python3 --version && \
78
+ node --version && \
79
+ npm --version && \
80
+ bun --version && \
81
+ jupyter --version && \
82
+ jupyter kernelspec list
83
+
84
+ # Copy container source files to server directory
85
+ COPY container_src/package.json container_src/bun.lock ./
86
+ RUN bun install --frozen-lockfile
87
+
88
+ COPY container_src/ ./
89
+
90
+ # Compile TypeScript control process
91
+ # Use npx -p typescript to ensure we get the right tsc command
92
+ RUN npx -p typescript tsc control-process.ts --outDir . --module commonjs --target es2020 --esModuleInterop --skipLibCheck
93
+
94
+ # Create clean workspace directory for users
95
+ RUN mkdir -p /workspace
96
+
97
+ # Expose the application port (3000 for control, 8888 for Jupyter)
98
+ EXPOSE 3000 8888
99
+
100
+ # Make startup script executable
101
+ RUN chmod +x startup.sh
102
+
103
+ # Use startup script
104
+ CMD ["./startup.sh"]