Get started
Build an agent with TypeScript
Embed OpenMetal sandbox workflows with the published TypeScript SDK.
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. The key is shown once.
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"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.
Create the client
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
Submit the request, keep both accepted IDs, then wait for the operation.
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
Remove temporary capacity when your work finishes.
await metal.sandboxes.delete(sandbox.id, {
timeoutMs: 180_000,
});