Commit 0a2cb93
authored
Optimize Docker image size with lean and Python variants (#259)
* fix: exclude src and tsconfig from npm package
Add files field to package.json to explicitly list published files.
Fixes linting errors for users whose IDEs try to resolve the
workspace-only @repo/typescript-config reference in tsconfig.json.
* build: bundle sandbox-container with Bun
Replace tsc compilation with Bun.build() bundling. This inlines all
dependencies (@repo/shared, zod, async-mutex) into single files,
eliminating the need for node_modules in the container image.
* feat: transpile TypeScript in process-pool using Bun.Transpiler
Move TypeScript transpilation from the executor to process-pool.ts.
This allows us to use Bun's built-in transpiler (since process-pool
runs on Bun) and send plain JavaScript to the Node-based executor.
* refactor: consolidate JS and TS to single executor
TypeScript is now transpiled in process-pool.ts before execution,
so both JS and TS can use the same node_executor. This simplifies
the codebase and removes the need for the separate ts_executor.
* chore: remove esbuild dependency
esbuild is no longer needed since TypeScript transpilation now uses
Bun's built-in Bun.Transpiler instead.
* build: remove node_modules from Docker image
Use bundled output instead of copying node_modules. The container
server and JS executor are now self-contained bundles with all
dependencies inlined. Reduces image size by ~670MB.
* feat: add Python-not-available error for lean image
When PYTHON_POOL_MIN_SIZE=0, return a helpful error message directing
users to the -python image variant instead of failing cryptically.
* feat: add multi-target Dockerfile for image variants
- default: lean image without Python (~600-800MB)
- python: full image with Python + data science packages (~1.3GB)
Users can choose the appropriate variant based on their needs.
The default image is suitable for most use cases (shell commands,
file operations, JS/TS code interpreter). The python variant adds
Python code interpreter with matplotlib, numpy, pandas, ipython.
* build: update docker scripts to build both variants
docker:local, docker:publish, and docker:publish:beta now build
both the default and -python image variants.
* fix: proper Python detection and CI updates for image variants
- Python check now invokes python3 binary instead of checking env var
- E2E test-worker and integration Dockerfiles use -python variant
- CI workflows build python target for E2E tests
- Release workflow pushes both default and -python variants
- Remove unused docker:publish scripts (CI handles publishing)
* chore: add changeset for image optimization
* build: update pkg-pr-new workflow for image variants
Build and push both default and -python Docker image variants.
Update PR comment to show both image options.
* fix: check Python availability before reserving executor
Move Python availability check earlier in the flow so context creation
fails with a helpful error message before trying to spawn python3.
* test: add E2E test for base image Python error
Add E2E test validating the Python-not-available error message when
using the base image variant. Updates CI to build both image variants
and auto-regenerates wrangler.jsonc from template before E2E tests.
* chore: simplify changeset description
* Add PYTHON_NOT_AVAILABLE error code with proper HTTP 501 status
When Python is unavailable in the base image, the error now returns
HTTP 501 with the PYTHON_NOT_AVAILABLE error code instead of a generic
500 INTERNAL_ERROR. The interpreter service detects this specific error
and propagates the correct code through the error handling chain.
Also fixes an untyped array in ensureMinimumPool and strengthens the
changeset breaking change warning for Python users.
* Run JS tests on base image and use dynamic version in error message
JavaScript-only E2E tests now run against the base image to validate
the lean image works correctly for non-Python workloads. This provides
coverage for the bundled JS executor without requiring Python.
The Python unavailable error message now uses SANDBOX_VERSION env var
when available, falling back to <version> placeholder. This gives users
the exact version to use in production while keeping the placeholder
for development.
* Refactor container naming: base image default, Python explicit
- Rename SandboxBase → SandboxPython in test worker
- Flip header logic: X-Sandbox-Type: python selects Python image
- Default (no header) now uses base image (smaller, no Python)
- Update cleanup script for -python suffix
- Remove per-run CI cleanup (resources persist until PR closes)
* Fix Docker comment update to match plural 'Images'
* Fix Python unavailable test to expect 500 status1 parent 458d140 commit 0a2cb93
File tree
24 files changed
+438
-786
lines changed- .changeset
- .github/workflows
- packages
- sandbox-container
- src
- runtime
- executors/typescript
- services
- sandbox
- scripts
- tests
- e2e
- helpers
- test-worker
- integration
24 files changed
+438
-786
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
89 | | - | |
90 | | - | |
91 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
92 | 109 | | |
93 | 110 | | |
94 | 111 | | |
| |||
100 | 117 | | |
101 | 118 | | |
102 | 119 | | |
103 | | - | |
104 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
105 | 123 | | |
106 | 124 | | |
107 | 125 | | |
| |||
112 | 130 | | |
113 | 131 | | |
114 | 132 | | |
115 | | - | |
| 133 | + | |
116 | 134 | | |
117 | 135 | | |
118 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
129 | 128 | | |
130 | 129 | | |
131 | 130 | | |
| |||
161 | 160 | | |
162 | 161 | | |
163 | 162 | | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
174 | 167 | | |
175 | 168 | | |
176 | 169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
112 | 113 | | |
113 | 114 | | |
114 | | - | |
| 115 | + | |
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
| |||
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
180 | | - | |
| 181 | + | |
181 | 182 | | |
182 | 183 | | |
183 | 184 | | |
184 | 185 | | |
| 186 | + | |
185 | 187 | | |
186 | 188 | | |
187 | 189 | | |
188 | | - | |
189 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
190 | 206 | | |
191 | 207 | | |
192 | 208 | | |
| |||
0 commit comments