Workspace

SDK Setup

The Oblien SDK provides a typed, ergonomic interface for the full Workspace API. It handles authentication, request formatting, error handling, and streaming for you.

Installation

npm install oblien
# or with your preferred package manager
yarn add oblien
pnpm add oblien

Initialize the client

import { OblienClient } from 'oblien';
import { Workspace } from 'oblien/workspace';

const client = new OblienClient({
  clientId: process.env.OBLIEN_CLIENT_ID!,
  clientSecret: process.env.OBLIEN_CLIENT_SECRET!,
});

const ws = new Workspace(client);

The Workspace instance gives you access to all workspace operations through these namespaces:

SDK structure

const ws = new Workspace(client);

// ── Core CRUD ──────────────────────────────────────
ws.create(options)              // Create a workspace
ws.list(options?)               // List workspaces
ws.get(workspaceId)             // Get workspace details
ws.update(workspaceId, data)    // Update workspace
ws.delete(workspaceId)          // Delete workspace
ws.details(workspaceId)         // Aggregated details (stats + SSH + lifecycle + config)
ws.quota()                      // Get your resource quota

// ── Power ──────────────────────────────────────────
ws.start(workspaceId)           // Start workspace
ws.stop(workspaceId)            // Stop workspace
ws.restart(workspaceId)         // Restart workspace
ws.pause(workspaceId)           // Pause (freeze) workspace
ws.resume(workspaceId)          // Resume paused workspace

// ── Execution ──────────────────────────────────────
ws.exec(workspaceId, options)   // Execute a command

// ── Lifecycle ──────────────────────────────────────
ws.lifecycle                    // .get(), .makePermanent(), .makeTemporary(), .updateTTL(), .ping()

// ── Tasks ──────────────────────────────────────────
ws.tasks                        // .create(), .list(), .get(), .sendInput(), .stream()

// ── Terminal ───────────────────────────────────────
ws.terminal                     // .create(), .list(), .close(), .scrollback(), .reconnect()

// ── Network ────────────────────────────────────────
ws.network                      // .get(), .update(), .replace(), .applyOutboundIp()

// ── SSH ────────────────────────────────────────────
ws.ssh                          // .status(), .enable(), .disable(), .setPassword(), .setKey()

// ── Public Access ──────────────────────────────────
ws.publicAccess                 // .list(), .expose(), .revoke()

// ── Filesystem ─────────────────────────────────────
ws.fs                           // .list(), .read(), .write(), .usage(), .resize(), .sync()

// ── Resources ──────────────────────────────────────
ws.resources                    // .get(), .update()

// ── Snapshots ──────────────────────────────────────
ws.snapshots                    // .create(), .restore()
ws.archives                     // .create(), .list(), .get(), .delete(), .deleteAll()

// ── Workloads ──────────────────────────────────────
ws.workloads                    // .create(), .list(), .get(), .update(), .delete(), .deleteAll()
                                // .start(), .stop(), .status(), .logs(), .streamLogs()

// ── Monitoring ─────────────────────────────────────
ws.stats(workspaceId)           // Current stats
ws.statsStream(workspaceId)     // SSE stream of live stats
ws.info(workspaceId)            // Raw VM info
ws.config(workspaceId)          // Raw VM config

// ── Usage ──────────────────────────────────────────
ws.usage                        // .get(), .totals(), .creditsChart(), .startTracking(), .stopTracking(), .wipe()
ws.activity(options?)           // Global activity history

// ── Metadata ───────────────────────────────────────
ws.metadata                     // .get(), .update()

// ── API Access ─────────────────────────────────────
ws.apiAccess                    // .token(), .enable(), .disable(), .refreshToken()

// ── Logs ───────────────────────────────────────────
ws.logs                         // .get(), .clear(), .list(), .file(), .streamBoot(), .streamCmd()

// ── Images ─────────────────────────────────────────
ws.images                       // .list()

Configuration options

const client = new OblienClient({
  // Required
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',

  // Optional
  baseUrl: 'https://api.oblien.com',   // Custom base URL (for testing/self-hosted)
  timeout: 30000,                       // Request timeout in ms (default: 30s)
});

TypeScript support

The SDK is fully typed. All request params and responses have TypeScript interfaces:

import type {
  CreateWorkspaceOptions,
  WorkspaceResponse,
  ExecOptions,
  ExecResult,
  NetworkConfig,
  TerminalSession,
  WorkspaceStats,
} from 'oblien/workspace';

Error handling

The SDK throws typed errors you can catch and inspect:

import { OblienError } from 'oblien';

try {
  await ws.create({ image: 'node-20' });
} catch (err) {
  if (err instanceof OblienError) {
    console.log(err.code);    // 'SANDBOX_LIMIT_REACHED'
    console.log(err.status);  // 402
    console.log(err.message); // 'Workspace limit reached for your plan'
  }
}

Common error codes are documented in the Errors Reference.

Framework examples

Next.js API route

// app/api/sandbox/route.ts
import { OblienClient } from 'oblien';
import { Workspace } from 'oblien/workspace';

const client = new OblienClient({
  clientId: process.env.OBLIEN_CLIENT_ID!,
  clientSecret: process.env.OBLIEN_CLIENT_SECRET!,
});
const ws = new Workspace(client);

export async function POST(req: Request) {
  const { code } = await req.json();

  const workspace = await ws.create({
    image: 'node-20',
    config: { cpus: 1, memory_mb: 256, ttl: '5m', remove_on_exit: true },
  });

  const result = await ws.exec(workspace.id, {
    cmd: ['node', '-e', code],
    timeout_seconds: 10,
  });

  return Response.json(result);
}

Express middleware

import { OblienClient } from 'oblien';
import { Workspace } from 'oblien/workspace';

const client = new OblienClient({
  clientId: process.env.OBLIEN_CLIENT_ID!,
  clientSecret: process.env.OBLIEN_CLIENT_SECRET!,
});
const ws = new Workspace(client);

// Attach to request context
app.use((req, res, next) => {
  req.workspace = ws;
  next();
});

app.post('/run', async (req, res) => {
  const sandbox = await req.workspace.create({
    image: 'python-3.12',
    config: { ttl: '2m', remove_on_exit: true },
  });

  const result = await req.workspace.exec(sandbox.id, {
    cmd: ['python3', '-c', req.body.code],
  });

  res.json(result);
});

Next steps