# Build an agent with TypeScript (/get-started/typescript)



## Before you begin [#before-you-begin]

You need Node.js 22 or later, an OpenMetal project, and a project API key. Keep the project ID and
key in environment variables.

Create an account, organization, project, and key from the
[OpenMetal dashboard](https://www.openmetal.sh/dashboard). The key is shown once.

```bash
npm install @openmetal/sdk

export OPENMETAL_API_URL="https://api.openmetal.sh"
export OPENMETAL_PROJECT_ID="prj_your_project"
export OPENMETAL_API_KEY="metal_sk_your_key"
```

<Callout type="warn" title="Keep keys out of source control">
  A project API key grants access to sandboxes in its project. Never expose it in browser code,
  logs, or a sandbox request.
</Callout>

## Create the client [#create-the-client]

```ts
import { MetalClient } from "@openmetal/sdk";

const metal = new MetalClient({
  baseUrl: process.env.OPENMETAL_API_URL!,
  projectId: process.env.OPENMETAL_PROJECT_ID!,
  accessToken: () => process.env.OPENMETAL_API_KEY,
  timeoutMs: 10_000,
});
```

## Create a sandbox [#create-a-sandbox]

Submit the request, keep both accepted IDs, then wait for the operation.

```ts
const mutation = await metal.sandboxes.createAsync({
  provider: "auto",
  source: {
    kind: "environment",
    environment: "metal/node",
    version: "latest",
  },
  resources: {
    vcpu: 2,
    memory_mb: 4096,
    architecture: "any",
  },
  lifecycle: {
    runtime_timeout_seconds: 1800,
    on_runtime_timeout: "destroy",
  },
});

const operation = await metal.operations.wait(mutation.operation, {
  timeoutMs: 180_000,
});

if (operation.state !== "succeeded") {
  throw new Error(operation.error?.message ?? `Create ${operation.state}`);
}

const sandbox = await metal.sandboxes.get(mutation.sandbox.id);
console.log(sandbox.id, sandbox.state);
```

The sandbox is usable when its state is `ready`.

## Clean up [#clean-up]

Remove temporary capacity when your work finishes.

```ts
await metal.sandboxes.delete(sandbox.id, {
  timeoutMs: 180_000,
});
```

## Next steps [#next-steps]

<Cards>
  <Card title="Run a process" href="/guides/run-process" />

  <Card title="Upload a file" href="/guides/filesystem" />

  <Card title="Understand operations" href="/concepts/operations" />
</Cards>
