@cloudflare/sandbox 0.8.11 → 0.9.0
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/dist/bridge/index.js +8 -8
- package/dist/bridge/index.js.map +1 -1
- package/dist/{contexts-icMN26lE.d.ts → contexts-D6kt6WyG.d.ts} +7 -2
- package/dist/contexts-D6kt6WyG.d.ts.map +1 -0
- package/dist/{errors-Bz21XTBJ.js → errors-Dk2rApYI.js} +3 -1
- package/dist/errors-Dk2rApYI.js.map +1 -0
- package/dist/index.d.ts +14 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/openai/index.d.ts +1 -1
- package/dist/opencode/index.d.ts +2 -2
- package/dist/opencode/index.d.ts.map +1 -1
- package/dist/opencode/index.js +1 -1
- package/dist/{file-stream-Bn2PceyF.js → sandbox-Cf_Wjrzq.js} +1126 -886
- package/dist/sandbox-Cf_Wjrzq.js.map +1 -0
- package/dist/{sandbox-C0Tjs0dj.d.ts → sandbox-Chr1Ebo-.d.ts} +105 -22
- package/dist/sandbox-Chr1Ebo-.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/contexts-icMN26lE.d.ts.map +0 -1
- package/dist/errors-Bz21XTBJ.js.map +0 -1
- package/dist/file-stream-Bn2PceyF.js.map +0 -1
- package/dist/sandbox-C0Tjs0dj.d.ts.map +0 -1
package/dist/bridge/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../dist-Ilf8VjmX.js";
|
|
2
|
-
import "../errors-
|
|
3
|
-
import {
|
|
2
|
+
import "../errors-Dk2rApYI.js";
|
|
3
|
+
import { h as streamFile, n as getSandbox } from "../sandbox-Cf_Wjrzq.js";
|
|
4
4
|
import { DurableObject, env } from "cloudflare:workers";
|
|
5
5
|
import { Hono } from "hono";
|
|
6
6
|
|
|
@@ -74,7 +74,7 @@ function errorJson(error, code, status) {
|
|
|
74
74
|
*/
|
|
75
75
|
function shellQuote(arg) {
|
|
76
76
|
if (/^[A-Za-z0-9@%+=:,./-]+$/.test(arg)) return arg;
|
|
77
|
-
return
|
|
77
|
+
return `$'${arg.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t")}'`;
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* POSIX-normalise a path (resolve `.` / `..` segments) and verify it lives
|
|
@@ -89,7 +89,7 @@ function resolveWorkspacePath(userPath) {
|
|
|
89
89
|
if (seg === "..") parts.pop();
|
|
90
90
|
else parts.push(seg);
|
|
91
91
|
}
|
|
92
|
-
const resolved =
|
|
92
|
+
const resolved = `/${parts.join("/")}`;
|
|
93
93
|
if (resolved === "/workspace" || resolved.startsWith("/workspace/")) return resolved;
|
|
94
94
|
return null;
|
|
95
95
|
}
|
|
@@ -1759,7 +1759,7 @@ function createBridgeApp(config) {
|
|
|
1759
1759
|
const marker = `${apiPrefix}/sandbox/${sandboxId}/file/`;
|
|
1760
1760
|
const relativePath = fullPath.slice(marker.length);
|
|
1761
1761
|
if (!relativePath) return errorJson("file path must not be empty", "invalid_request", 400);
|
|
1762
|
-
const resolvedPath = resolveWorkspacePath(
|
|
1762
|
+
const resolvedPath = resolveWorkspacePath(`/${relativePath}`);
|
|
1763
1763
|
if (!resolvedPath) return errorJson("path must resolve to a location within /workspace", "invalid_request", 403);
|
|
1764
1764
|
const sandbox = getSandbox$1(getSandboxNs(c.env), c.get("containerUUID"));
|
|
1765
1765
|
const rawSessionId = c.req.header("Session-Id");
|
|
@@ -1786,7 +1786,7 @@ function createBridgeApp(config) {
|
|
|
1786
1786
|
const marker = `${apiPrefix}/sandbox/${sandboxId}/file/`;
|
|
1787
1787
|
const relativePath = fullPath.slice(marker.length);
|
|
1788
1788
|
if (!relativePath) return errorJson("file path must not be empty", "invalid_request", 400);
|
|
1789
|
-
const resolvedPath = resolveWorkspacePath(
|
|
1789
|
+
const resolvedPath = resolveWorkspacePath(`/${relativePath}`);
|
|
1790
1790
|
if (!resolvedPath) return errorJson("path must resolve to a location within /workspace", "invalid_request", 403);
|
|
1791
1791
|
const sandbox = getSandbox$1(getSandboxNs(c.env), c.get("containerUUID"));
|
|
1792
1792
|
const rawSessionId = c.req.header("Session-Id");
|
|
@@ -1853,7 +1853,7 @@ function createBridgeApp(config) {
|
|
|
1853
1853
|
for (const ex of excludes) if (ex.includes("..")) return errorJson("exclude paths must not contain \"..\"", "invalid_request", 400);
|
|
1854
1854
|
const sandbox = getSandbox$1(getSandboxNs(c.env), c.get("containerUUID"));
|
|
1855
1855
|
const tmpPath = `/tmp/sandbox-persist-${Date.now()}.tar`;
|
|
1856
|
-
const excludeArgs = excludes.map((rel) => `--exclude ${shellQuote(
|
|
1856
|
+
const excludeArgs = excludes.map((rel) => `--exclude ${shellQuote(`./${rel.replace(/^\.\//, "")}`)}`).join(" ");
|
|
1857
1857
|
const tarCmd = excludeArgs ? `tar cf ${shellQuote(tmpPath)} ${excludeArgs} -C ${shellQuote(root)} .` : `tar cf ${shellQuote(tmpPath)} -C ${shellQuote(root)} .`;
|
|
1858
1858
|
try {
|
|
1859
1859
|
const result = await sandbox.exec(tarCmd);
|
|
@@ -2483,7 +2483,7 @@ function bridge(worker, config) {
|
|
|
2483
2483
|
...passThrough,
|
|
2484
2484
|
async fetch(request, env$1, ctx) {
|
|
2485
2485
|
const url = new URL(request.url);
|
|
2486
|
-
if (url.pathname.startsWith(apiPrefix
|
|
2486
|
+
if (url.pathname.startsWith(`${apiPrefix}/`) || url.pathname === apiPrefix || url.pathname === healthPath) return app.fetch(request, env$1, ctx);
|
|
2487
2487
|
if (worker.fetch) return worker.fetch(request, env$1, ctx);
|
|
2488
2488
|
return new Response("Not Found", { status: 404 });
|
|
2489
2489
|
},
|