Skip to content

Commit ba61554

Browse files
Make readme reflect current state of lib
1 parent 37f2ab5 commit ba61554

File tree

1 file changed

+7
-40
lines changed

1 file changed

+7
-40
lines changed

README.md

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,53 +27,20 @@ Create an API token by going to https://codesandbox.io/t/api, and clicking on th
2727
```javascript
2828
import { CodeSandbox } from "@codesandbox/sdk";
2929

30-
// Create the client with your token
31-
const sdk = new CodeSandbox(token);
30+
const sdk = new CodeSandbox(process.env.CSB_API_KEY);
31+
const sandbox = await sdk.sandboxes.create();
32+
const client = await sandbox.connect();
3233

33-
// This creates a new sandbox by forking our default template sandbox.
34-
// You can also pass in other template ids, or create your own template to fork from.
35-
const sandbox = await sdk.sandbox.create();
34+
const output = await client.commands.run("echo 'Hello World'");
3635

37-
// You can run JS code directly
38-
await sandbox.shells.js.run("console.log(1+1)");
39-
// Or Python code (if it's installed in the template)
40-
await sandbox.shells.python.run("print(1+1)");
41-
42-
// Or anything else
43-
await sandbox.shells.run("echo 'Hello, world!'");
44-
45-
// We have a FS API to interact with the filesystem
46-
await sandbox.fs.writeTextFile("./hello.txt", "world");
47-
48-
// And you can clone sandboxes! This does not only clone the filesystem, processes that are running in the original sandbox will also be cloned!
49-
const sandbox2 = await sandbox.fork();
50-
51-
// Check that the file is still there
52-
await sandbox2.fs.readTextFile("./hello.txt");
53-
54-
// You can also get the opened ports, with the URL to access those
55-
console.log(sandbox2.ports.getOpenedPorts());
56-
57-
// Getting metrics...
58-
const metrics = await sandbox2.getMetrics();
59-
console.log(
60-
`Memory: ${metrics.memory.usedKiB} KiB / ${metrics.memory.totalKiB} KiB`
61-
);
62-
console.log(`CPU: ${(metrics.cpu.used / metrics.cpu.cores) * 100}%`);
63-
64-
// Finally, you can hibernate a sandbox. This will snapshot the sandbox and stop it. Next time you start the sandbox, it will continue where it left off, as we created a memory snapshot.
65-
await sandbox.hibernate();
66-
await sandbox2.hibernate();
67-
68-
// Open the sandbox again
69-
const resumedSandbox = await sdk.sandbox.open(sandbox.id);
36+
console.log(output); // Hello World
7037
```
7138

7239
## CodeSandbox Integration
7340

7441
This SDK uses the API token from your workspace in CodeSandbox to authenticate and create sandboxes. Because of this, the sandboxes will be created inside your workspace, and the resources will be billed to your workspace.
7542

76-
You could, for example, create a private template in your workspace that has all the dependencies you need (even running servers), and then use that template to fork sandboxes from. This way, you can control the environment that the sandboxes run in.
43+
Build your own template that has all the dependencies you need (even running servers), and then use that template to create sandboxes from. This way, you can control the environment that the sandboxes run in.
7744

7845
## Example Use Cases
7946

@@ -83,6 +50,6 @@ Code interpretation: Run code in a sandbox to interpret it. This way, you can ru
8350

8451
Development environments: Create a sandbox for each developer, and run their code in the sandbox. This way, you can run multiple development environments in parallel without them interfering with each other.
8552

86-
AI Agents: Create a sandbox for each AI agent, and run the agent in the sandbox. This way, you can run multiple agents in parallel without them interfering with each other. Using the forking mechanism, you can also A/B test different agents.
53+
AI Agents: Create a sandbox for each AI agent, and run the agent in the sandbox. This way, you can run multiple agents in parallel without them interfering with each other.
8754

8855
CI/CD: Run tests inside a sandbox, and hibernate the sandbox when the tests are done. This way, you can quickly start the sandbox again when you need to run the tests again or evaluate the results.

0 commit comments

Comments
 (0)