Skip to content

Commit ee6242a

Browse files
expanded first steps
1 parent d78d150 commit ee6242a

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

sandboxes/getting_started.md

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,47 @@ yarn add jsr:@deno/sandbox
5454

5555
## 4. Create your first sandbox
5656

57-
```tsx
57+
```tsx title="main.ts"
5858
import { Sandbox } from "@deno/sandbox";
59+
await using sandbox = await Sandbox.create();
60+
await sandbox.sh`echo "Hello, world!"`;
61+
```
62+
63+
## 5. Run your sandbox code
5964

65+
This code will require access to the network to reach the Deploy edge where the
66+
sandbox will be created, and also access to the environment variables to
67+
authenticate with the Deploy API, so we'll pass in the `--allow-net` and
68+
`--allow-env` flags to the `deno run` command (or use the shorthand `-EN`).
69+
70+
```bash
71+
deno run -EN main.ts
72+
```
73+
74+
## 6. Configuring your sandbox
75+
76+
When creating a sandbox witb `Sandbox.create()`, you can configure it with the
77+
following options:
78+
79+
- `allowNet`: List of hosts that can receive outbound traffic from the sandbox.
80+
- `region`: Deploy region where the sandbox will be created.
81+
- `memoryMb`: Amount of memory allocated to the sandbox.
82+
- `lifetime`: Lifetime of the sandbox.
83+
- `id`: ID of the sandbox.
84+
85+
```tsx
6086
await using sandbox = await Sandbox.create({
6187
allowNet: ["api.stripe.com", "api.openai.com"],
6288
region: "sjc", // optional: choose the Deploy region
6389
memoryMb: 1024, // optional: pick the RAM size (768-4096)
6490
});
6591
```
6692

67-
This call provisions an isolated Linux microVM on the Deploy edge. By providing
68-
an `allowNet` list, you define the only hosts that can receive outbound traffic
69-
from that VM.
93+
Once again, this call provisions an isolated Linux microVM on the Deploy edge,
94+
but now by providing an `allowNet` list, you define the only hosts that can
95+
receive outbound traffic from that VM.
7096

71-
## 5. Run commands and scripts
97+
## 7. Running commands and scripts
7298

7399
Sandboxes expose familiar filesystem and process APIs to run commands, upload
74100
files, and spawn long-running services.
@@ -96,7 +122,7 @@ await proc.status;
96122
You can keep state between commands, stream stdout and stderr, or open an
97123
interactive REPL with `sandbox.repl()` for agent-style workflows.
98124

99-
## 7. Keep secrets and policies tight
125+
## 8. Keeping secrets and policies tight
100126

101127
Secrets never appear inside `/proc` or the sandbox environment variables.
102128
Instead, Deploy injects them only when the sandbox makes an outbound request to
@@ -111,7 +137,7 @@ confirms that user code cannot read your real credentials. Combine this with
111137
narrow `allowNet` rules, per-command timeouts, or `KillController` cancellation
112138
for a defense-in-depth posture.
113139

114-
## 8. Tune lifetime, cleanup, and reconnect
140+
## 9. Tuning lifetime, cleanup, and reconnect
115141

116142
- `lifetime: "session"` (default) destroys the VM once your script finishes.
117143
- Provide durations such as `"5m"` to keep the sandbox alive even after the

0 commit comments

Comments
 (0)