sandboxedjs 0.1.55 → 0.1.57
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/README.md +22 -2
- package/dist/index.cjs +23 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +23 -2
- package/dist/index.js.map +1 -1
- package/dist/python/python.data +278 -268
- package/dist/python/python.js +1 -1
- package/dist/python/python.wasm +0 -0
- package/dist/python/runtime.json +3 -3
- package/dist/python/wheels/index.json +42 -0
- package/dist/python/wheels/pydantic_core-2.23.2-cp313-cp313-emscripten_5_0_6_wasm32.whl +0 -0
- package/dist/python/wheels/pydantic_core-2.46.5-cp313-cp313-emscripten_5_0_6_wasm32.whl +0 -0
- package/dist/python/wheels/sbx_c_probe-1.0.0-cp313-cp313-emscripten_5_0_6_wasm32.whl +0 -0
- package/dist/python/wheels/sbx_rust_probe-1.0.0-cp313-cp313-emscripten_5_0_6_wasm32.whl +0 -0
- package/dist/python-abi.cjs +6 -0
- package/dist/python-abi.cjs.map +1 -1
- package/dist/python-abi.d.cts +2 -0
- package/dist/python-abi.d.ts +2 -0
- package/dist/python-abi.js +6 -0
- package/dist/python-abi.js.map +1 -1
- package/dist/python-worker.js +80 -5
- package/dist/python-worker.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -729,6 +729,23 @@ await box.exec("python3 -c 'import sqlite3; print(sqlite3.sqlite_version)'");
|
|
|
729
729
|
Python never falls back to a host interpreter. When selecting the optional
|
|
730
730
|
Pyodide backend, its module and asset directory must use the same version.
|
|
731
731
|
|
|
732
|
+
### Python wheels with Vite
|
|
733
|
+
|
|
734
|
+
Vite prebundles JavaScript dependencies into `.vite/deps`, but it does not
|
|
735
|
+
serve binary package assets next to that optimized module. Copy
|
|
736
|
+
`node_modules/sandboxedjs/dist/python/wheels` to your app's public directory
|
|
737
|
+
at build time, then configure the public URL before creating a container:
|
|
738
|
+
|
|
739
|
+
```ts
|
|
740
|
+
import { configurePython } from "sandboxedjs";
|
|
741
|
+
|
|
742
|
+
configurePython({ wheelIndex: "/python/wheels" });
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
The directory must contain `index.json` and every wheel named by it. Once this
|
|
746
|
+
is configured, `pip install fastapi` resolves Pydantic 2 and the bundled
|
|
747
|
+
WASM-compatible `pydantic-core` rather than falling back to Pydantic 1.
|
|
748
|
+
|
|
732
749
|
## Uploading files
|
|
733
750
|
|
|
734
751
|
A file picker in a browser never hands over a path — it hands over the file's bytes. So getting a
|
|
@@ -977,8 +994,11 @@ Honest list of what does not work:
|
|
|
977
994
|
that `request()` talks to directly, so servers work; raw sockets do not.
|
|
978
995
|
- **Python is source-built CPython/WASM.** Each program gets its own interpreter
|
|
979
996
|
process worker. Pure-Python wheels install normally; native extensions must
|
|
980
|
-
be linked or published for Emscripten.
|
|
981
|
-
|
|
997
|
+
be linked or published for Emscripten. The bundled wheel index includes the
|
|
998
|
+
ABI-matched `pydantic-core` builds required by Pydantic 2, so FastAPI resolves
|
|
999
|
+
against Pydantic 2 by default. Virtual environments and CPython's real pip
|
|
1000
|
+
are not implemented; the sandbox `pip` installs into one shared site-packages
|
|
1001
|
+
directory, so use a fresh container for dependency isolation.
|
|
982
1002
|
- **No real sockets.** HTTP servers work through the request proxy; raw TCP/UDP does not.
|
|
983
1003
|
- **No real processes.** Processes are cooperative async tasks: `kill -9` cannot interrupt a
|
|
984
1004
|
tight synchronous loop, and `SIGSTOP` only marks state.
|
package/dist/index.cjs
CHANGED
|
@@ -17935,7 +17935,15 @@ var bundledManifest = {
|
|
|
17935
17935
|
persistence: "memory"
|
|
17936
17936
|
}
|
|
17937
17937
|
};
|
|
17938
|
-
var
|
|
17938
|
+
var bundledWheelIndex = (typeof process !== "undefined" && process.versions?.node ? new URL(
|
|
17939
|
+
(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)).includes("/src/runtime/python/") ? "../../../dist/python/wheels/" : "./python/wheels/",
|
|
17940
|
+
(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))
|
|
17941
|
+
) : new URL("/python/wheels/", globalThis.location?.href ?? (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)))).href;
|
|
17942
|
+
var config = {
|
|
17943
|
+
backend: "sbx-cpython-wasm",
|
|
17944
|
+
manifest: bundledManifest,
|
|
17945
|
+
wheelIndex: bundledWheelIndex
|
|
17946
|
+
};
|
|
17939
17947
|
function setPythonBackend(options) {
|
|
17940
17948
|
if (options.wheelIndex !== void 0) config.wheelIndex = options.wheelIndex;
|
|
17941
17949
|
if (options.manifest !== void 0) config.manifest = validateManifest(options.manifest);
|
|
@@ -20404,6 +20412,17 @@ environments. A package with no usable wheel is an error, never a silent skip.`,
|
|
|
20404
20412
|
}
|
|
20405
20413
|
const cache = /* @__PURE__ */ new Map();
|
|
20406
20414
|
const request = async (url, timeoutMs, read) => {
|
|
20415
|
+
if (url.startsWith("file:")) {
|
|
20416
|
+
try {
|
|
20417
|
+
const [{ readFile }, { fileURLToPath: fileURLToPath2 }] = await Promise.all([
|
|
20418
|
+
nodeBuiltin("fs/promises"),
|
|
20419
|
+
nodeBuiltin("url")
|
|
20420
|
+
]);
|
|
20421
|
+
return await read(new Response(await readFile(fileURLToPath2(url))));
|
|
20422
|
+
} catch (error) {
|
|
20423
|
+
throw new Error(`could not read bundled wheel asset ${url}: ${error.message}`);
|
|
20424
|
+
}
|
|
20425
|
+
}
|
|
20407
20426
|
const controller = new AbortController();
|
|
20408
20427
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
20409
20428
|
try {
|
|
@@ -20440,7 +20459,9 @@ environments. A package with no usable wheel is an error, never a silent skip.`,
|
|
|
20440
20459
|
const loaded = await client.json(`${url}/index.json`);
|
|
20441
20460
|
index = { baseUrl: url, wheels: loaded.wheels ?? [] };
|
|
20442
20461
|
} catch (error) {
|
|
20443
|
-
return ctx.fail(
|
|
20462
|
+
return ctx.fail(
|
|
20463
|
+
`could not read the wheel index at ${configured}: ${error.message}. When running under a bundler such as Vite, publish dist/python/wheels as a static asset and configurePython({ wheelIndex: '/python/wheels' }) before creating the container.`
|
|
20464
|
+
);
|
|
20444
20465
|
}
|
|
20445
20466
|
} else if (configured) {
|
|
20446
20467
|
index = configured;
|