Quick start
In this quick start, you’ll learn how to:
- Set up your development environment
- Create your first computer
- Use the computer primitives like the filesystem and terminal
If you run into any challenges or have questions, shoot us an email.
Account setup
First, create a free Metallic account or sign in. Then, grab your API key from the dashboard or the "API keys" page. Make sure to save this somewhere safe, and do not share it publicly. Set the API key as an environment variable in your project.
export METALLIC_API_KEY="your-api-key"
Installation
Metallic provides Node.js and Python SDKs to easily and safely control virtual computers. Install the SDK by running the following command in your terminal.
npm install @metallichq/sdk
Create your first computer
Below is a minimal example of how to create a virtual computer, then wait for it to start, and finally stop it.
import { Computer } from "@metallichq/sdk";
// Create computer
const computer = await Computer.create();
console.log("Computer created! ID:", computer.id);
// Wait for computer to start
await computer.waitForState("started");
// Stop computer
await computer.stop();
Using the filesystem
Now that we've created our first computer, let's use the SDK to read and write files to the computer's filesystem.
import { Computer } from "@metallichq/sdk";
// Computer ID from previously created computer
const computerId = "your-computer-id";
// Start computer
const computer = await Computer.start(computerId);
// Wait for computer to start
await computer.waitForState("started");
// Write file
await computer.fs.writeFile("hello.txt", "Hello, world!");
// Read file
const fileContent = await computer.fs.readFile("hello.txt");
console.log(fileContent); // "Hello, world!"
// Stop computer
await computer.stop();
For a more comprehensive list of filesystem operations, see the Filesystem guide.
Using the terminal
Let's continue by running a terminal command on the computer.
import { Computer } from "@metallichq/sdk";
// Computer ID from previously created computer
const computerId = "your-computer-id";
// Start computer
const computer = await Computer.start(computerId);
// Wait for computer to start
await computer.waitForState("started");
// Run terminal command
const result = await computer.terminal.run("ls -l");
console.log(result);
// Stop computer
await computer.stop();
For a more detailed documentation on terminal usage, see the Terminal guide.