@vercel/sandbox 2.0.0-beta.1 → 2.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -52,7 +52,9 @@ async function main() {
52
52
  resources: { vcpus: 4 },
53
53
  ports: [3000],
54
54
  runtime: "node24",
55
+ name: "vercel-sandbox-example",
55
56
  });
57
+ console.log(`Sandbox ${sandbox.name} created`);
56
58
 
57
59
  console.log(`Installing dependencies...`);
58
60
  const install = await sandbox.runCommand({
@@ -62,7 +64,7 @@ async function main() {
62
64
  stdout: process.stdout,
63
65
  });
64
66
 
65
- if (install.exitCode != 0) {
67
+ if (install.exitCode !== 0) {
66
68
  console.log("installing packages failed");
67
69
  process.exit(1);
68
70
  }
@@ -98,6 +100,43 @@ This will:
98
100
 
99
101
  All while streaming logs to your local terminal.
100
102
 
103
+ Sandboxes are persistent by default. To resume a sandbox with its previous state:
104
+
105
+ Create a `resume.mts` file:
106
+
107
+ ```ts
108
+ import { Sandbox } from "@vercel/sandbox";
109
+ import { setTimeout } from "timers/promises";
110
+ import { spawn } from "child_process";
111
+
112
+ async function main() {
113
+ const sandbox = await Sandbox.get({
114
+ name: "vercel-sandbox-example",
115
+ });
116
+ console.log(`Sandbox ${sandbox.name} resumed`);
117
+
118
+ console.log(`Starting the development server...`);
119
+ await sandbox.runCommand({
120
+ cmd: "npm",
121
+ args: ["run", "dev"],
122
+ stderr: process.stderr,
123
+ stdout: process.stdout,
124
+ detached: true,
125
+ });
126
+
127
+ await setTimeout(500);
128
+ spawn("open", [sandbox.domain(3000)]);
129
+ }
130
+
131
+ main().catch(console.error);
132
+ ```
133
+
134
+ Run it:
135
+
136
+ ```sh
137
+ node --experimental-strip-types --env-file .env.local resume.mts
138
+ ```
139
+
101
140
  ## Authentication
102
141
 
103
142
  ### Vercel OIDC token