Skip to content

Commit 354d120

Browse files
kt3kmagurotuna
andauthored
fix: update sandbox apis (#2829)
Co-authored-by: Yusuke Tanaka <wing0920@gmail.com>
1 parent a591091 commit 354d120

20 files changed

+91
-100
lines changed

examples/_data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ export const sidebar = [
374374
type: "example",
375375
},
376376
{
377-
title: "Control sandbox lifetime",
378-
href: "/examples/sandboxes_lifetime_control/",
377+
title: "Control sandbox timeout",
378+
href: "/examples/sandboxes_timeout_control/",
379379
type: "example",
380380
},
381381
{

examples/sandboxes/evaluating_javascript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Sandbox } from "@deno/sandbox";
1212

1313
await using sandbox = await Sandbox.create();
1414

15-
const result = await sandbox.eval(`
15+
const result = await sandbox.deno.eval(`
1616
const a = 1;
1717
const b = 2;
1818
a + b;

examples/sandboxes/javascript_repl.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
---
22
title: "Intereactive JavaScript REPL"
3-
description: "Learn how to provide an interactive JavaScript REPL in a sandbox."
3+
description: "Learn how to provide an interactive Deno REPL in a sandbox."
44
url: /examples/sandboxes_javascript_repl/
55
layout: sandbox-example.tsx
66
---
77

8-
The `sandbox.repl()` method can be used to provide an interactive JavaScript
9-
REPL in a sandbox.
8+
The `sandbox.deno.repl()` method can be used to provide an interactive Deno REPL
9+
in a sandbox.
1010

11-
This example shows how to start a JavaScript REPL in a sandbox and execute code
11+
This example shows how to start a Deno REPL in a sandbox and execute code
1212
interactively.
1313

1414
```ts
1515
import { Sandbox } from "@deno/sandbox";
1616

1717
await using sandbox = await Sandbox.create();
1818

19-
// Start a JavaScript REPL
20-
const repl = await sandbox.repl();
19+
// Start a Deno REPL
20+
const repl = await sandbox.deno.repl();
2121

2222
// Execute code interactively, maintaining state
2323
await repl.eval("const x = 42;");

examples/sandboxes/memory.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { Sandbox } from "@deno/sandbox";
2323
await using sandbox = await Sandbox.create({ memoryMb: 4096 });
2424

2525
// Check available memory
26-
const memInfo = await sandbox.eval<{ total: number }>(
26+
const memInfo = await sandbox.deno.eval<{ total: number }>(
2727
"Deno.systemMemoryInfo()",
2828
);
2929
console.log("Total memory:", memInfo.total);

examples/sandboxes/stream_output.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { Writable } from "node:stream";
2020
await using sandbox = await Sandbox.create();
2121

2222
// Create a large file in the sandbox
23-
await sandbox.writeTextFile("big.txt", "#".repeat(5_000_000));
23+
await sandbox.fs.writeTextFile("big.txt", "#".repeat(5_000_000));
2424

2525
// Stream it out to a local file
2626
const child = await sandbox.spawn("cat", {
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
2-
title: "Control sandbox lifetime"
3-
description: "Learn how to control how long your sandbox stays alive using the lifetime option."
4-
url: /examples/sandboxes_lifetime_control/
2+
title: "Control sandbox timeout"
3+
description: "Learn how to control how long your sandbox stays alive using the timeout option."
4+
url: /examples/sandboxes_timeout_control/
55
layout: sandbox-example.tsx
66
---
77

8-
You can control how long your sandbox stays alive using the lifetime option:
8+
You can control how long your sandbox stays alive using the timeout option:
99

1010
```ts
1111
import { Sandbox } from "@deno/sandbox";
1212

1313
// Default: "session" - sandbox shuts down when you close/dispose the client
14-
await using sandbox = await Sandbox.create({ lifetime: "session" });
14+
await using sandbox = await Sandbox.create({ timeout: "session" });
1515
```
1616

1717
Supported duration suffixes: `s` (seconds), `m` (minutes).
@@ -23,7 +23,7 @@ import { Sandbox } from "@deno/sandbox";
2323

2424
// Duration-based: keep sandbox alive for a specific time period
2525
// Useful when you want the sandbox to persist after the script exits
26-
const sandbox = await Sandbox.create({ lifetime: "5m" }); // 5 minutes
26+
const sandbox = await Sandbox.create({ timeout: "5m" }); // 5 minutes
2727
const id = sandbox.id;
2828
// Close the *connection* to the sandbox; the sandbox keeps running
2929
await sandbox.close();
@@ -32,10 +32,10 @@ await sandbox.close();
3232
const reconnected = await Sandbox.connect({ id });
3333
await reconnected.sh`echo 'Still alive!'`;
3434

35-
// You can still forcibly terminate it before its lifetime expires
35+
// You can still forcibly terminate it before its timeout elapses
3636
await reconnected.kill();
3737
// At this point, the sandbox is no longer reconnectable
3838
```
3939

40-
> Need other lifetime modes? Contact
40+
> Need other timeout modes? Contact
4141
> <a href="mailto:deploy@deno.com">deploy@deno.com</a>.

examples/sandboxes/upload_files.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ layout: sandbox-example.tsx
66
---
77

88
Copy files from your machine into the sandbox using
9-
`sandbox.upload(localPath, sandboxPath)`.
9+
`sandbox.fs.upload(localPath, sandboxPath)`.
1010

1111
```ts
1212
import { Sandbox } from "@deno/sandbox";
1313

1414
await using sandbox = await Sandbox.create();
1515

1616
// Upload a single file to a specific path in the sandbox
17-
await sandbox.upload("./README.md", "./readme-copy.md");
17+
await sandbox.fs.upload("./README.md", "./readme-copy.md");
1818

1919
// Upload a local directory tree into the sandbox current directory
20-
await sandbox.upload("./my-project", ".");
20+
await sandbox.fs.upload("./my-project", ".");
2121
```

examples/sandboxes/vscode_instance.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ url: /examples/sandboxes_vscode_instance/
55
layout: sandbox-example.tsx
66
---
77

8-
The `sandbox.vscode()` method can be used to provide a VSCode instance in a
9-
sandbox.
8+
The `sandbox.exposeVscode()` method can be used to provide a VSCode instance in
9+
a sandbox.
1010

1111
This example shows how to start a VSCode instance in a sandbox and print the url
1212
of the running instance which you can then open in your browser.
@@ -17,7 +17,7 @@ import { Sandbox } from "@deno/sandbox";
1717
await using sandbox = await Sandbox.create();
1818

1919
// Start a VSCode instance
20-
const vscode = await sandbox.vscode();
20+
const vscode = await sandbox.exposeVscode();
2121

2222
console.log(vscode.url); // print the url of the running instance
2323
await vscode.status; // wait until it exits

examples/sandboxes/web_framework.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ const PACKAGE_JSON = {
2323
type: "module",
2424
dependencies: { express: "^4.19.2" },
2525
};
26-
await sandbox.writeTextFile(
26+
await sandbox.fs.writeTextFile(
2727
"package.json",
2828
JSON.stringify(PACKAGE_JSON, null, 2),
2929
);
3030

31-
await sandbox.writeTextFile(
31+
await sandbox.fs.writeTextFile(
3232
"server.js",
3333
`import express from 'express';
3434
const app = express();
@@ -42,7 +42,7 @@ app.listen(3000, () => console.log('listening on :3000'));
4242
await sandbox.sh`deno install`;
4343

4444
// 3) Start the server
45-
const server = await sandbox.createJsRuntime({ entrypoint: "server.js" });
45+
const server = await sandbox.deno.run({ entrypoint: "server.js" });
4646

4747
// 4) Publish to the internet
4848
const publicUrl = await sandbox.exposeHttp({ port: 3000 });

sandboxes/_data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export const sidebar = [
3939
href: "/sandboxes/volumes/",
4040
},
4141
{
42-
title: "Lifetimes",
43-
href: "/sandboxes/lifetimes/",
42+
title: "Timeouts",
43+
href: "/sandboxes/timeouts/",
4444
},
4545
{
4646
title: "Security",

0 commit comments

Comments
 (0)