Skip to content

Commit f70831a

Browse files
tweaking bits after docs meeting (#2896)
1 parent df77291 commit f70831a

File tree

8 files changed

+51
-54
lines changed

8 files changed

+51
-54
lines changed

examples/_data.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,18 +348,13 @@ export const sidebar = [
348348
href: "/examples/sandbox_error_handling/",
349349
type: "example",
350350
},
351-
{
352-
title: "Error handling with custom error classes",
353-
href: "/examples/sandbox_custom_error_classes/",
354-
type: "example",
355-
},
356351
{
357352
title: "Command cancellation",
358353
href: "/examples/sandbox_command_cancellation/",
359354
type: "example",
360355
},
361356
{
362-
title: "Access string and binary output",
357+
title: "Streaming access string and binary output",
363358
href: "/examples/sandbox_access_output/",
364359
type: "example",
365360
},
@@ -389,12 +384,12 @@ export const sidebar = [
389384
type: "example",
390385
},
391386
{
392-
title: "Add read-write block storage to your Sandbox",
387+
title: "Add read-write volumes to your Sandbox",
393388
href: "/examples/volumes_tutorial/",
394389
type: "example",
395390
},
396391
{
397-
title: "Boot instantly with read-only images",
392+
title: "Boot instantly with snapshots",
398393
href: "/examples/snapshots_tutorial/",
399394
type: "example",
400395
},

examples/sandbox/access_output.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: "Access string and binary output"
3-
description: "Learn how to access string and binary output from commands in a sandbox."
2+
title: "Streaming access string and binary output"
3+
description: "Learn how to stream string and binary output from commands in a sandbox."
44
url: /examples/sandbox_access_output/
55
layout: sandbox-example.tsx
66
---

examples/sandbox/custom_error_classes.md

Lines changed: 0 additions & 32 deletions
This file was deleted.

examples/sandbox/error_handling.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,31 @@ full status object, so you can branch on `status.code` or `status.success`, log
3535
diagnostics, or retry specific commands without losing context. This pattern is
3636
essential for robust automation where commands might fail due to user input,
3737
transient network issues, or missing dependencies.
38+
39+
## Custom error classes
40+
41+
You can handle errors with custom error classes in a sandbox.
42+
43+
Catching `SandboxCommandError` lets you differentiate sandbox command failures
44+
from other exceptions. When the error is the `SandboxCommandError` class, you
45+
can read structured fields such as `error.code` or format `error.message` to
46+
decide whether to retry, escalate, or map exit codes to your own domain-specific
47+
errors:
48+
49+
```ts
50+
import { Sandbox, SandboxCommandError } from "@deno/sandbox";
51+
52+
await using sandbox = await Sandbox.create();
53+
54+
try {
55+
await sandbox.sh`exit 42`;
56+
} catch (error) {
57+
if (error instanceof SandboxCommandError) {
58+
console.log("Exit code:", error.code); // → 42
59+
console.log("Error message:", error.message);
60+
}
61+
}
62+
```
63+
64+
This makes it easier to build higher-level automation that reacts intelligently
65+
to known failure modes instead of treating every thrown error the same.

examples/sandbox/memory.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ workloads or reduce memory for lighter tasks.
1313
import { Sandbox } from "@deno/sandbox";
1414

1515
// Create a sandbox with 1GB of memory
16-
await using sandbox = await Sandbox.create({ memoryMb: 1024 });
16+
await using sandbox = await Sandbox.create({ memory: 1024 });
1717
```
1818

1919
```ts
2020
import { Sandbox } from "@deno/sandbox";
2121

2222
// Create a sandbox with 4GB of memory for memory-intensive workloads
23-
await using sandbox = await Sandbox.create({ memoryMb: 4096 });
23+
await using sandbox = await Sandbox.create({ memory: 4096 });
2424

2525
// Check available memory
2626
const memInfo = await sandbox.deno.eval<{ total: number }>(
@@ -29,7 +29,7 @@ const memInfo = await sandbox.deno.eval<{ total: number }>(
2929
console.log("Total memory:", memInfo.total);
3030
```
3131

32-
Configuring memoryMb when creating the sandbox lets you tune resource usage per
32+
Configuring memory when creating the sandbox lets you tune resource usage per
3333
workload. Lightweight tasks can run in smaller sandboxes to conserve resources,
3434
while data-heavy scripts or compilations can request up to 4 GB to avoid
3535
out-of-memory failures.

examples/sandbox/spawn_subprocess.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import { Sandbox } from "@deno/sandbox";
1414

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

17-
const text = await sandbox.sh`pwd`.text();
18-
console.log("result:", text); // → "/home/sandbox\n"
17+
const cwd = await sandbox.sh`pwd`;
1918
```
2019

2120
For long‑running processes or large output, stream the stdout/stderr instead of

examples/sandbox/ssh_access.md

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

88
SSH access allows you to connect to a sandboxed environment securely over the
9-
SSH protocol. The `sandbox.exposeSsh()` method can be used to provide SSH access
10-
to a sandbox.
9+
SSH protocol. The `sandbox.create({ ssh: true })` method can be used to provide
10+
SSH access to a sandbox.
1111

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

15-
await using sandbox = await Sandbox.create();
15+
await using sandbox = await Sandbox.create({ ssh: true });
1616

17-
// Get SSH credentials
18-
const { hostname, username } = await sandbox.exposeSsh();
17+
// Wait for Deploy to provision SSH access information.
18+
const creds = sandbox.ssh ?? await sandbox.exposeSsh();
19+
if (!creds) {
20+
throw new Error("SSH credentials were not provisioned for this sandbox");
21+
}
22+
23+
const { hostname, username } = creds;
1924
console.log(`ssh ${username}@${hostname}`);
2025

2126
// Keep the process alive by sleeping, otherwise the sandbox will be destroyed

examples/sandbox/timeout_control.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ your script finishes or keep running for a set duration:
1313
import { Sandbox } from "@deno/sandbox";
1414

1515
// Default: "session" - sandbox shuts down when you close/dispose the client
16-
await using sandbox = await Sandbox.create({ timeout: "session" });
16+
await using sandbox = await Sandbox.create({ timeout: "10m" });
1717
```
1818

1919
Supported duration suffixes: `s` (seconds), `m` (minutes).
2020

21-
Examples: `"30s"`, `"5m"`, `"90s"` .
21+
Examples: `"30s"`, `"5m"`, `"90s"`. The default is `"session"`, which means the
22+
sandbox will automatically shut down when the client connection is closed or
23+
disposed.
2224

2325
```ts
2426
import { Sandbox } from "@deno/sandbox";

0 commit comments

Comments
 (0)