Skip to content

Commit 21ef60e

Browse files
committed
add untrusted code example, swap example types to tutorial, make first sandbox example a runnable script
1 parent 58a6427 commit 21ef60e

File tree

4 files changed

+53
-43
lines changed

4 files changed

+53
-43
lines changed

examples/_data.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -321,82 +321,82 @@ export const sidebar = [
321321
{
322322
title: "Spawn a subprocess",
323323
href: "/examples/sandbox_spawn_subprocess/",
324-
type: "example",
324+
type: "tutorial",
325325
},
326326
{
327327
title: "Serve a web framework",
328328
href: "/examples/sandbox_web_framework/",
329-
type: "example",
329+
type: "tutorial",
330330
},
331331
{
332332
title: "Provide SSH access to a sandbox",
333333
href: "/examples/sandbox_ssh_access/",
334-
type: "example",
334+
type: "tutorial",
335335
},
336336
{
337337
title: "Interactive JavaScript REPL",
338338
href: "/examples/sandbox_javascript_repl/",
339-
type: "example",
339+
type: "tutorial",
340340
},
341341
{
342342
title: "Provide a VSCode instance in a sandbox",
343343
href: "/examples/sandbox_vscode_instance/",
344-
type: "example",
344+
type: "tutorial",
345345
},
346346
{
347347
title: "Use template literals with variable interpolation",
348348
href: "/examples/sandbox_template_literals/",
349-
type: "example",
349+
type: "tutorial",
350350
},
351351
{
352352
title: "Error handling",
353353
href: "/examples/sandbox_error_handling/",
354-
type: "example",
354+
type: "tutorial",
355355
},
356356
{
357357
title: "Command cancellation",
358358
href: "/examples/sandbox_command_cancellation/",
359-
type: "example",
359+
type: "tutorial",
360360
},
361361
{
362362
title: "Streaming access string and binary output",
363363
href: "/examples/sandbox_access_output/",
364-
type: "example",
364+
type: "tutorial",
365365
},
366366
{
367367
title: "Set and get environment variables",
368368
href: "/examples/sandbox_environment_variables/",
369-
type: "example",
369+
type: "tutorial",
370370
},
371371
{
372372
title: "Stream output to a local file",
373373
href: "/examples/sandbox_stream_output/",
374-
type: "example",
374+
type: "tutorial",
375375
},
376376
{
377377
title: "Upload files and directories to a sandbox",
378378
href: "/examples/sandbox_upload_files/",
379-
type: "example",
379+
type: "tutorial",
380380
},
381381
{
382382
title: "Control sandbox timeout",
383383
href: "/examples/sandbox_timeout_control/",
384-
type: "example",
384+
type: "tutorial",
385385
},
386386
{
387387
title: "Configure sandbox memory",
388388
href: "/examples/sandbox_memory/",
389-
type: "example",
389+
type: "tutorial",
390390
},
391391
{
392392
title: "Add read-write volumes to your Sandbox",
393393
href: "/examples/volumes_tutorial/",
394-
type: "example",
394+
type: "tutorial",
395395
},
396396
{
397397
title: "Boot instantly with snapshots",
398398
href: "/examples/snapshots_tutorial/",
399-
type: "example",
399+
type: "tutorial",
400400
},
401401
{
402402
title: "Boot a Python environment with snapshots",
@@ -408,6 +408,11 @@ export const sidebar = [
408408
href: "/examples/snapshot_python_tutorial/",
409409
type: "tutorial",
410410
},
411+
{
412+
title: "Run AI generated code",
413+
href: "/examples/sandbox_for_untrusted_code/",
414+
type: "example",
415+
},
411416
],
412417
},
413418
{

examples/sandbox/evaluating_javascript.md

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @title Evaluating JavaScript
3+
* @difficulty beginner
4+
* @tags sandbox
5+
* @run -A <url>
6+
* @resource {https://docs.deno.com/sandbox/} Deno Deploy Sandbox
7+
* @group Deno Deploy
8+
*
9+
* You can evaluate JavaScript code in a sandbox using the `eval` function.
10+
*
11+
* Calling `sandbox.deno.eval()` lets you run arbitrary JavaScript snippets
12+
* directly inside the sandbox’s Deno runtime without writing files or shelling * out. This is useful when you want to prototype logic, run small
13+
* computations, or inspect the sandbox environment itself quickly. Use it for
14+
* dynamic scripts or exploratory debugging where creating a full module would
15+
* be overkill.
16+
*/
17+
18+
// Import the Deno Sandbox SDK
19+
import { Sandbox } from "jsr:@deno/sandbox";
20+
// Create a sandbox
21+
await using sandbox = await Sandbox.create();
22+
// Run JS in the sandbox with eval
23+
const result = await sandbox.deno.eval(`
24+
const a = 1;
25+
const b = 2;
26+
a + b;
27+
`);
28+
console.log("result:", result);

examples/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export const TAGS = {
1111
title: "web",
1212
description: "Works in on the Web",
1313
},
14+
sandbox: {
15+
title: "sandbox",
16+
description: "Uses Deno Deploy Sandbox",
17+
},
1418
};
1519

1620
export const DIFFICULTIES = {

0 commit comments

Comments
 (0)