@cloudflare/sandbox 0.1.4 → 0.2.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/CHANGELOG.md +6 -0
- package/Dockerfile +7 -5
- package/README.md +4 -4
- package/container_src/handler/exec.ts +4 -2
- package/container_src/handler/process.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @cloudflare/sandbox
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
|
|
3
9
|
## 0.1.4
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/Dockerfile
CHANGED
|
@@ -56,21 +56,23 @@ COPY --from=bun-source /usr/local/bin/bun /usr/local/bin/bun
|
|
|
56
56
|
COPY --from=bun-source /usr/local/bin/bunx /usr/local/bin/bunx
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
# Set up
|
|
60
|
-
WORKDIR /
|
|
59
|
+
# Set up container server directory
|
|
60
|
+
WORKDIR /container-server
|
|
61
61
|
|
|
62
62
|
# Verify installations
|
|
63
63
|
RUN python3 --version && \
|
|
64
64
|
node --version && \
|
|
65
65
|
npm --version && \
|
|
66
66
|
bun --version
|
|
67
|
-
|
|
68
67
|
|
|
69
|
-
# Copy container source files
|
|
68
|
+
# Copy container source files to server directory
|
|
70
69
|
COPY container_src/ ./
|
|
71
70
|
|
|
71
|
+
# Create clean workspace directory for users
|
|
72
|
+
RUN mkdir -p /workspace
|
|
73
|
+
|
|
72
74
|
# Expose the application port
|
|
73
75
|
EXPOSE 3000
|
|
74
76
|
|
|
75
|
-
# Run the application
|
|
77
|
+
# Run the application from container server directory
|
|
76
78
|
CMD ["bun", "index.ts"]
|
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ npm install @cloudflare/sandbox
|
|
|
64
64
|
1. **Create a Dockerfile** (temporary requirement, will be removed in future releases):
|
|
65
65
|
|
|
66
66
|
```dockerfile
|
|
67
|
-
FROM docker.io/cloudflare/sandbox:0.
|
|
67
|
+
FROM docker.io/cloudflare/sandbox:0.2.0
|
|
68
68
|
|
|
69
69
|
# Expose the ports you want to expose
|
|
70
70
|
EXPOSE 3000
|
|
@@ -176,7 +176,7 @@ for await (const log of parseSSEStream<LogEvent>(logStream)) {
|
|
|
176
176
|
Write content to a file.
|
|
177
177
|
|
|
178
178
|
```typescript
|
|
179
|
-
await sandbox.writeFile("/app.js", "console.log('Hello!');");
|
|
179
|
+
await sandbox.writeFile("/workspace/app.js", "console.log('Hello!');");
|
|
180
180
|
```
|
|
181
181
|
|
|
182
182
|
#### `readFile(path, options?)`
|
|
@@ -314,7 +314,7 @@ const sandbox = getSandbox(env.Sandbox, "node-app");
|
|
|
314
314
|
|
|
315
315
|
// Write a simple Express server
|
|
316
316
|
await sandbox.writeFile(
|
|
317
|
-
"/app.js",
|
|
317
|
+
"/workspace/app.js",
|
|
318
318
|
`
|
|
319
319
|
const express = require('express');
|
|
320
320
|
const app = express();
|
|
@@ -498,7 +498,7 @@ Maintain context across commands:
|
|
|
498
498
|
const sessionId = crypto.randomUUID();
|
|
499
499
|
|
|
500
500
|
// Commands in the same session share working directory
|
|
501
|
-
await sandbox.exec("cd /
|
|
501
|
+
await sandbox.exec("cd /workspace", { sessionId });
|
|
502
502
|
await sandbox.exec("npm install", { sessionId });
|
|
503
503
|
const app = await sandbox.startProcess("npm start", { sessionId });
|
|
504
504
|
```
|
|
@@ -16,7 +16,7 @@ function executeCommand(
|
|
|
16
16
|
shell: true,
|
|
17
17
|
stdio: ["pipe", "pipe", "pipe"] as const,
|
|
18
18
|
detached: options.background || false,
|
|
19
|
-
cwd: options.cwd,
|
|
19
|
+
cwd: options.cwd || "/workspace", // Default to clean /workspace directory
|
|
20
20
|
env: options.env ? { ...process.env, ...options.env } : process.env
|
|
21
21
|
};
|
|
22
22
|
|
|
@@ -159,7 +159,7 @@ export async function handleStreamingExecuteRequest(
|
|
|
159
159
|
): Promise<Response> {
|
|
160
160
|
try {
|
|
161
161
|
const body = (await req.json()) as ExecuteRequest;
|
|
162
|
-
const { command, sessionId, background } = body;
|
|
162
|
+
const { command, sessionId, background, cwd, env } = body;
|
|
163
163
|
|
|
164
164
|
if (!command || typeof command !== "string") {
|
|
165
165
|
return new Response(
|
|
@@ -186,6 +186,8 @@ export async function handleStreamingExecuteRequest(
|
|
|
186
186
|
shell: true,
|
|
187
187
|
stdio: ["pipe", "pipe", "pipe"] as const,
|
|
188
188
|
detached: background || false,
|
|
189
|
+
cwd: cwd || "/workspace", // Default to clean /workspace directory
|
|
190
|
+
env: env ? { ...process.env, ...env } : process.env
|
|
189
191
|
};
|
|
190
192
|
|
|
191
193
|
const child = spawn(command, spawnOptions);
|
|
@@ -72,7 +72,7 @@ export async function handleStartProcessRequest(
|
|
|
72
72
|
// Start the actual process
|
|
73
73
|
try {
|
|
74
74
|
const spawnOptions: SpawnOptions = {
|
|
75
|
-
cwd: options.cwd ||
|
|
75
|
+
cwd: options.cwd || "/workspace", // Default to /workspace for consistency with exec commands
|
|
76
76
|
env: { ...process.env, ...options.env },
|
|
77
77
|
detached: false,
|
|
78
78
|
shell: true,
|