Skip to content

Commit f7c59d6

Browse files
thisisjofrankphilhawksworthrylucacasonatomarvinhagemeister
authored
initial commit for sandboxes pages (#2754)
Co-authored-by: Phil Hawksworth <phil@deno.com> Co-authored-by: Ryan Dahl <ry@tinyclouds.org> Co-authored-by: Luca Casonato <hello@lcas.dev> Co-authored-by: Marvin Hagemeister <marvin@deno.com>
1 parent 4320be1 commit f7c59d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1775
-36
lines changed

_components/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function (
1111
const hrefIsInCurrentSection = (href: string, currentSection: string) => {
1212
return href.includes(currentSection) ||
1313
href === "/services/" &&
14-
["deploy", "subhosting", "services"].includes(
14+
["deploy", "subhosting", "services", "sandboxes"].includes(
1515
currentSection,
1616
);
1717
};

_config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ site.copy("deploy/images");
140140
site.copy("deploy/classic/images");
141141
site.copy("deploy/kv/images");
142142
site.copy("deploy/tutorials/images");
143+
site.copy("sandboxes/images");
143144
site.copy("runtime/fundamentals/images");
144145
site.copy("runtime/getting_started/images");
145146
site.copy("runtime/reference/images");

_includes/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export default function Layout(data: Lume.Data) {
1010
"In-depth documentation, guides, and reference materials for building secure, high-performance JavaScript and TypeScript applications with Deno";
1111
const isServicesPage = data.url.startsWith("/deploy") ||
1212
data.url.startsWith("/subhosting") ||
13-
data.url.startsWith("/services");
13+
data.url.startsWith("/services") ||
14+
data.url.startsWith("/sandboxes");
1415
const hasSubNav = isServicesPage;
1516

1617
return (

_includes/sandbox-example.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export const layout = "doc.tsx";
2+
3+
export default function Raw(data: Lume.Data) {
4+
return (
5+
<>
6+
<p className="italic">
7+
<a href="https://deno.com/deploy/sandboxes/">Deno Sandboxes</a>{" "}
8+
provide a sandboxed environment for evaluating JavaScript code. This is
9+
useful for evaluating code that is not trusted or for testing code that
10+
is not safe to run in the main runtime.
11+
</p>
12+
13+
{data.children}
14+
15+
<p className="my-8 block">
16+
For more information about Sandboxes, see the{" "}
17+
<a href="/sandboxes/">Sandboxes documentation</a>.
18+
</p>
19+
</>
20+
);
21+
}

deno.lock

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

deploy/_data.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ export const SidebarNav = [
153153
title: "Deno Deploy",
154154
href: "/deploy/",
155155
},
156+
{
157+
title: "Sandboxes",
158+
href: "/sandboxes/",
159+
},
156160
{
157161
title: "Deploy Classic",
158162
href: "/deploy/classic/",

deploy/classic/_data.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ export const SidebarNav = [
124124
title: "Deno Deploy",
125125
href: "/deploy/",
126126
},
127+
{
128+
title: "Sandboxes",
129+
href: "/sandboxes/",
130+
},
127131
{
128132
title: "Deploy Classic",
129133
href: "/deploy/classic/",

examples/_data.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,91 @@ export const sidebar = [
300300
},
301301
],
302302
},
303+
{
304+
title: "Sandboxes",
305+
items: [
306+
{
307+
title: "Evaluating JavaScript",
308+
href: "/examples/sandboxes_evaluating_javascript/",
309+
type: "example",
310+
},
311+
{
312+
title: "Spawn a subprocess",
313+
href: "/examples/sandboxes_spawn_subprocess/",
314+
type: "example",
315+
},
316+
{
317+
title: "Serve a web framework",
318+
href: "/examples/sandboxes_web_framework/",
319+
type: "example",
320+
},
321+
{
322+
title: "Privide SSH access to a sandbox",
323+
href: "/examples/sandboxes_ssh_access/",
324+
type: "example",
325+
},
326+
{
327+
title: "Intereactive JavaScript REPL",
328+
href: "/examples/sandboxes_javascript_repl/",
329+
type: "example",
330+
},
331+
{
332+
title: "Provide a VSCode instance in a sandbox",
333+
href: "/examples/sandboxes_vscode_instance/",
334+
type: "example",
335+
},
336+
{
337+
title: "Use template literals with variable interpolation",
338+
href: "/examples/sandboxes_template_literals/",
339+
type: "example",
340+
},
341+
{
342+
title: "Error handling",
343+
href: "/examples/sandboxes_error_handling/",
344+
type: "example",
345+
},
346+
{
347+
title: "Error handling with custom error classes",
348+
href: "/examples/sandboxes_custom_error_classes/",
349+
type: "example",
350+
},
351+
{
352+
title: "Command cancellation",
353+
href: "/examples/sandboxes_command_cancellation/",
354+
type: "example",
355+
},
356+
{
357+
title: "Access string and binary output",
358+
href: "/examples/sandboxes_access_output/",
359+
type: "example",
360+
},
361+
{
362+
title: "Set and get environment variables",
363+
href: "/examples/sandboxes_environment_variables/",
364+
type: "example",
365+
},
366+
{
367+
title: "Stream output to a local file",
368+
href: "/examples/sandboxes_stream_output/",
369+
type: "example",
370+
},
371+
{
372+
title: "Upload files and directories to a sandbox",
373+
href: "/examples/sandboxes_upload_files/",
374+
type: "example",
375+
},
376+
{
377+
title: "Control sandbox lifetime",
378+
href: "/examples/sandboxes_lifetime_control/",
379+
type: "example",
380+
},
381+
{
382+
title: "Configure sandbox memory",
383+
href: "/examples/sandboxes_memory/",
384+
type: "example",
385+
},
386+
],
387+
},
303388
{
304389
title: "Testing",
305390
items: [
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: "Access string and binary output"
3+
description: "Learn how to access string and binary output from commands in a sandbox."
4+
url: /examples/sandboxes_access_output/
5+
layout: sandbox-example.tsx
6+
---
7+
8+
You can access string and binary output from commands in a sandbox.
9+
10+
```ts
11+
import { Sandbox } from "@deno/sandbox";
12+
13+
await using sandbox = await Sandbox.create();
14+
15+
// Get both string and binary data
16+
const result = await sandbox.sh`cat binary-file.png`
17+
.stdout("piped");
18+
console.log("Binary length:", result.stdout!.length);
19+
console.log("Text length:", result.stdoutText!.length);
20+
21+
// Use the binary data
22+
import fs from "node:fs";
23+
fs.writeFileSync("output.png", result.stdout!);
24+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: "Command cancellation"
3+
description: "Learn how to cancel commands in a sandbox."
4+
url: /examples/sandboxes_command_cancellation/
5+
layout: sandbox-example.tsx
6+
---
7+
8+
You can cancel commands in a sandbox using the `KillController` class.
9+
10+
```ts
11+
import { KillController, Sandbox } from "@deno/sandbox";
12+
13+
await using sandbox = await Sandbox.create();
14+
15+
// Start a long-running command
16+
const controller = new KillController();
17+
const cmd = sandbox.sh`sleep 30`.signal(controller.signal);
18+
const promise = cmd.text();
19+
20+
// Cancel after 2 seconds
21+
setTimeout(() => {
22+
controller.kill(); // Kill the process
23+
}, 2000);
24+
25+
try {
26+
await promise;
27+
} catch (error) {
28+
console.log("Command was cancelled:", error);
29+
}
30+
```

0 commit comments

Comments
 (0)