@cloudflare/sandbox 0.0.0-cbb7fcd → 0.0.0-daf68b5

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 CHANGED
@@ -1,19 +1,5 @@
1
1
  # @cloudflare/sandbox
2
2
 
3
- ## 0.0.5
4
-
5
- ### Patch Changes
6
-
7
- - [#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
8
-
9
- ## 0.0.4
10
-
11
- ### Patch Changes
12
-
13
- - [`c0d9d33`](https://github.com/cloudflare/sandbox-sdk/commit/c0d9d3396badee1eab45e6b4a73d48957f31409b) Thanks [@threepointone](https://github.com/threepointone)! - actually work
14
-
15
- - [`444d2da`](https://github.com/cloudflare/sandbox-sdk/commit/444d2dafde9a0f190e50c879b0e768da1b289b51) Thanks [@threepointone](https://github.com/threepointone)! - add experimental label
16
-
17
3
  ## 0.0.3
18
4
 
19
5
  ### Patch Changes
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  ## @cloudflare/sandbox
2
2
 
3
- > **⚠️ Experimental** - This library is currently experimental and we're actively seeking feedback. Please try it out and let us know what you think!
4
-
5
3
  A library to spin up a sandboxed environment.
6
4
 
7
5
  First, setup your wrangler.json to use the sandbox:
@@ -84,8 +84,6 @@ const server = serve({
84
84
  const url = new URL(req.url);
85
85
  const pathname = url.pathname;
86
86
 
87
- console.log(`[Container] Incoming ${req.method} request to ${pathname}`);
88
-
89
87
  // Handle CORS
90
88
  const corsHeaders = {
91
89
  "Access-Control-Allow-Headers": "Content-Type, Authorization",
@@ -95,13 +93,11 @@ const server = serve({
95
93
 
96
94
  // Handle preflight requests
97
95
  if (req.method === "OPTIONS") {
98
- console.log(`[Container] Handling CORS preflight for ${pathname}`);
99
96
  return new Response(null, { headers: corsHeaders, status: 200 });
100
97
  }
101
98
 
102
99
  try {
103
100
  // Handle different routes
104
- console.log(`[Container] Processing ${req.method} ${pathname}`);
105
101
  switch (pathname) {
106
102
  case "/":
107
103
  return new Response("Hello from Bun server! 🚀", {
@@ -356,14 +352,13 @@ const server = serve({
356
352
  break;
357
353
 
358
354
  default:
359
- console.log(`[Container] Route not found: ${pathname}`);
360
355
  return new Response("Not Found", {
361
356
  headers: corsHeaders,
362
357
  status: 404,
363
358
  });
364
359
  }
365
360
  } catch (error) {
366
- console.error(`[Container] Error handling ${req.method} ${pathname}:`, error);
361
+ console.error("[Server] Error handling request:", error);
367
362
  return new Response(
368
363
  JSON.stringify({
369
364
  error: "Internal server error",
@@ -379,7 +374,6 @@ const server = serve({
379
374
  );
380
375
  }
381
376
  },
382
- hostname: "0.0.0.0",
383
377
  port: 3000,
384
378
  } as any);
385
379
 
@@ -2880,7 +2874,7 @@ function executeMoveFile(
2880
2874
  });
2881
2875
  }
2882
2876
 
2883
- console.log(`🚀 Bun server running on http://0.0.0.0:${server.port}`);
2877
+ console.log(`🚀 Bun server running on http://localhost:${server.port}`);
2884
2878
  console.log(`📡 HTTP API endpoints available:`);
2885
2879
  console.log(` POST /api/session/create - Create a new session`);
2886
2880
  console.log(` GET /api/session/list - List all sessions`);
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@cloudflare/sandbox",
3
- "version": "0.0.0-cbb7fcd",
3
+ "version": "0.0.0-daf68b5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cloudflare/sandbox-sdk"
7
7
  },
8
8
  "description": "A sandboxed environment for running commands",
9
9
  "dependencies": {
10
- "@cloudflare/containers": "^0.0.13"
10
+ "@cloudflare/containers": "^0.0.12"
11
11
  },
12
12
  "tags": [
13
13
  "sandbox",
@@ -17,9 +17,7 @@
17
17
  "durable objects"
18
18
  ],
19
19
  "scripts": {
20
- "build": "rm -rf dist && tsup src/*.ts --outDir dist --dts --sourcemap --format esm",
21
- "docker:build": "docker build -t ghostwriternr/cloudflare-sandbox:$npm_package_version .",
22
- "docker:publish": "docker push docker.io/ghostwriternr/cloudflare-sandbox:$npm_package_version"
20
+ "build": "rm -rf dist && tsup src/*.ts --outDir dist --dts --sourcemap --format esm"
23
21
  },
24
22
  "exports": {
25
23
  ".": {
package/src/client.ts CHANGED
@@ -203,31 +203,10 @@ export class HttpClient {
203
203
  path: string,
204
204
  options?: RequestInit
205
205
  ): Promise<Response> {
206
- const url = this.options.stub ? `stub:${path}` : `${this.baseUrl}${path}`;
207
- const method = options?.method || "GET";
208
-
209
- console.log(`[HTTP Client] Making ${method} request to ${url}`);
210
-
211
- try {
212
- let response: Response;
213
-
214
- if (this.options.stub) {
215
- response = await this.options.stub.containerFetch(this.baseUrl + path, options, this.options.port);
216
- } else {
217
- response = await fetch(this.baseUrl + path, options);
218
- }
219
-
220
- console.log(`[HTTP Client] Response: ${response.status} ${response.statusText}`);
221
-
222
- if (!response.ok) {
223
- console.error(`[HTTP Client] Request failed: ${method} ${url} - ${response.status} ${response.statusText}`);
224
- }
225
-
226
- return response;
227
- } catch (error) {
228
- console.error(`[HTTP Client] Request error: ${method} ${url}`, error);
229
- throw error;
206
+ if (this.options.stub) {
207
+ return this.options.stub.containerFetch(path, options, this.options.port);
230
208
  }
209
+ return fetch(this.baseUrl + path, options);
231
210
  }
232
211
  // Public methods to set event handlers
233
212
  setOnOutput(
package/src/index.ts CHANGED
@@ -8,29 +8,24 @@ export function getSandbox(ns: DurableObjectNamespace<Sandbox>, id: string) {
8
8
  export class Sandbox<Env = unknown> extends Container<Env> {
9
9
  defaultPort = 3000; // The default port for the container to listen on
10
10
  sleepAfter = "3m"; // Sleep the sandbox if no requests are made in this timeframe
11
- client: HttpClient;
12
11
 
13
- constructor(ctx: DurableObjectState, env: Env) {
14
- super(ctx, env);
15
- this.client = new HttpClient({
16
- onCommandComplete: (success, exitCode, stdout, stderr, command, args) => {
17
- console.log(
18
- `[Container] Command completed: ${command}, Success: ${success}, Exit code: ${exitCode}`
19
- );
20
- },
21
- onCommandStart: (command, args) => {
22
- console.log(`[Container] Command started: ${command} ${args.join(" ")}`);
23
- },
24
- onError: (error, command, args) => {
25
- console.error(`[Container] Command error: ${error}`);
26
- },
27
- onOutput: (stream, data, command) => {
28
- console.log(`[Container] [${stream}] ${data}`);
29
- },
30
- port: this.defaultPort,
31
- stub: this,
32
- });
33
- }
12
+ client: HttpClient = new HttpClient({
13
+ onCommandComplete: (success, exitCode, stdout, stderr, command, args) => {
14
+ console.log(
15
+ `[Container] Command completed: ${command}, Success: ${success}, Exit code: ${exitCode}`
16
+ );
17
+ },
18
+ onCommandStart: (command, args) => {
19
+ console.log(`[Container] Command started: ${command} ${args.join(" ")}`);
20
+ },
21
+ onError: (error, command, args) => {
22
+ console.error(`[Container] Command error: ${error}`);
23
+ },
24
+ onOutput: (stream, data, command) => {
25
+ console.log(`[Container] [${stream}] ${data}`);
26
+ },
27
+ port: this.defaultPort,
28
+ });
34
29
 
35
30
  envVars = {
36
31
  MESSAGE: "I was passed in via the Sandbox class!",