Skip to content

Commit f5fcd52

Browse files
Allow setting env variables dynamically and remove command restrictions (#22)
* Bump containers package version * Remove rudimentary dangerous commands check * Allow dynamically setting env vars * Add changeset
1 parent 6f16c81 commit f5fcd52

File tree

5 files changed

+16
-61
lines changed

5 files changed

+16
-61
lines changed

.changeset/thin-plums-hammer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/sandbox": patch
3+
---
4+
5+
Allow setting env variables dynamically and remove command restrictions

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sandbox/container_src/index.ts

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -400,34 +400,6 @@ async function handleExecuteRequest(
400400
);
401401
}
402402

403-
// Basic safety check - prevent dangerous commands
404-
const dangerousCommands = [
405-
"rm",
406-
"rmdir",
407-
"del",
408-
"format",
409-
"shutdown",
410-
"reboot",
411-
];
412-
const lowerCommand = command.toLowerCase();
413-
414-
if (
415-
dangerousCommands.some((dangerous) => lowerCommand.includes(dangerous))
416-
) {
417-
return new Response(
418-
JSON.stringify({
419-
error: "Dangerous command not allowed",
420-
}),
421-
{
422-
headers: {
423-
"Content-Type": "application/json",
424-
...corsHeaders,
425-
},
426-
status: 400,
427-
}
428-
);
429-
}
430-
431403
console.log(`[Server] Executing command: ${command} ${args.join(" ")}`);
432404

433405
const result = await executeCommand(command, args, sessionId, background);
@@ -490,34 +462,6 @@ async function handleStreamingExecuteRequest(
490462
);
491463
}
492464

493-
// Basic safety check - prevent dangerous commands
494-
const dangerousCommands = [
495-
"rm",
496-
"rmdir",
497-
"del",
498-
"format",
499-
"shutdown",
500-
"reboot",
501-
];
502-
const lowerCommand = command.toLowerCase();
503-
504-
if (
505-
dangerousCommands.some((dangerous) => lowerCommand.includes(dangerous))
506-
) {
507-
return new Response(
508-
JSON.stringify({
509-
error: "Dangerous command not allowed",
510-
}),
511-
{
512-
headers: {
513-
"Content-Type": "application/json",
514-
...corsHeaders,
515-
},
516-
status: 400,
517-
}
518-
);
519-
}
520-
521465
console.log(
522466
`[Server] Executing streaming command: ${command} ${args.join(" ")}`
523467
);

packages/sandbox/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"description": "A sandboxed environment for running commands",
99
"dependencies": {
10-
"@cloudflare/containers": "^0.0.23"
10+
"@cloudflare/containers": "^0.0.24"
1111
},
1212
"tags": [
1313
"sandbox",

packages/sandbox/src/sandbox.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ export class Sandbox<Env = unknown> extends Container<Env> {
5555
}
5656
}
5757

58+
// RPC method to set environment variables
59+
async setEnvVars(envVars: Record<string, string>): Promise<void> {
60+
this.envVars = { ...this.envVars, ...envVars };
61+
console.log(`[Sandbox] Updated environment variables`);
62+
}
63+
5864
override onStart() {
5965
console.log("Sandbox successfully started");
6066
}

0 commit comments

Comments
 (0)