File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33 "dev" : " deno run --watch main.ts"
44 },
55 "imports" : {
6- "@std/assert" : " jsr:@std/assert@1"
6+ "@std/assert" : " jsr:@std/assert@1" ,
7+ "@std/dotenv" : " jsr:@std/dotenv@0.225.5" ,
8+ "@deno/sandbox" : " jsr:@deno/sandbox@0.0.4"
79 }
810}
Original file line number Diff line number Diff line change 1- export function add ( a : number , b : number ) : number {
2- return a + b ;
3- }
4-
5- // Learn more at https://docs.deno.com/runtime/manual/examples/module_metadata#concepts
6- if ( import . meta. main ) {
7- console . log ( "Add 2 + 3 =" , add ( 2 , 3 ) ) ;
8- }
1+ // %%
2+ import { Sandbox } from "@deno/sandbox" ;
3+ import "@std/dotenv/load" ;
4+
5+ // %%
6+ await using sandbox = await Sandbox . create ( ) ;
7+
8+ // %%
9+ const result = await sandbox . eval ( `1 + 2` ) ;
10+ console . log ( "result:" , result ) ;
11+
12+ // %%
13+ let repl = await sandbox . repl ( ) ;
14+
15+ // %%
16+ await repl . eval ( `5` ) ;
17+
18+ // %%
19+ const result2 = await sandbox . eval ( `5` ) ;
20+ console . log ( "result:" , result2 ) ;
21+
22+ // %%
23+ await sandbox . close ( ) ;
You can’t perform that action at this time.
0 commit comments