-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.ts
More file actions
43 lines (37 loc) · 1.09 KB
/
Copy pathindex.ts
File metadata and controls
43 lines (37 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Runloop } from "@runloop/api-client";
async function main() {
// Initialize the Runloop client
const runloop = new Runloop({
bearerToken: process.env.RUNLOOP_API_KEY!,
});
// Create a devbox and wait for it to be ready
console.log("Creating devbox...");
let devbox;
try {
devbox = await runloop.devboxes.createAndAwaitRunning({
name: "read-write-files-ts",
});
// Write a small text file
// All files are relative to /home/user
const file_path = "/home/user/example.txt";
const contents = "Hello from Runloop devbox!";
await runloop.devboxes.writeFileContents(devbox.id, {
file_path,
contents,
});
console.log(`Wrote content to ${file_path}`);
// Read the file back
const readContent = await runloop.devboxes.readFileContents(devbox.id, {
file_path,
});
console.log(`Read content from ${file_path}: ${readContent}`);
} catch (error) {
console.error(error);
} finally {
if (devbox) {
await runloop.devboxes.shutdown(devbox.id);
console.log("Devbox shutdown");
}
}
}
main();