Workspace
Quickstart
This guide gets you from zero to a running cloud workspace in under 5 minutes.
Prerequisites
- An Oblien account (sign up free)
- Node.js 18+ installed
- Your API credentials (Client ID & Client Secret)
1. Install the SDK
npm install oblien2. Set your credentials
export OBLIEN_CLIENT_ID="your-client-id"
export OBLIEN_CLIENT_SECRET="your-client-secret"Get your credentials from Dashboard → Settings → API Credentials → Create API Key.
3. Create and use a workspace
Create a file called sandbox.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);
async function main() {
// 1. Create a workspace with Node.js 20
const workspace = await ws.create({
name: 'my-first-sandbox',
image: 'node-20',
config: {
cpus: 1,
memory_mb: 512,
},
});
console.log(`✓ Created workspace: ${workspace.id}`);
console.log(` Status: ${workspace.info.status}`);
console.log(` Image: ${workspace.image}`);
// 2. Execute a command
const result = await ws.exec(workspace.id, {
cmd: ['node', '-e', 'console.log(JSON.stringify({ node: process.version, arch: process.arch }))'],
});
console.log(`✓ Exec result:`, result.data);
// 3. Write a file
await ws.fs.write(workspace.id, {
path: '/app/hello.js',
content: Buffer.from('console.log("Hello from Oblien!")').toString('base64'),
});
// 4. Run the file
const output = await ws.exec(workspace.id, {
cmd: ['node', '/app/hello.js'],
});
console.log(`✓ Output: ${output.data}`);
// 5. Get live stats
const stats = await ws.stats(workspace.id);
console.log(`✓ CPU: ${stats.cpuUsage}% | Memory: ${stats.memoryUsedMB}/${stats.memoryTotalMB} MB`);
// 6. Clean up
await ws.delete(workspace.id);
console.log(`✓ Workspace deleted`);
}
main().catch(console.error);Run it:
npx tsx sandbox.tsExpected output:
✓ Created workspace: ws_a1b2c3d4
Status: running
Image: node-20
✓ Exec result: { node: "v20.18.0", arch: "x64" }
✓ Output: Hello from Oblien!
✓ CPU: 2.1% | Memory: 48/512 MB
✓ Workspace deleted4. Try the REST API directly
If you prefer HTTP calls:
# Create workspace
curl -X POST https://api.oblien.com/workspace \
-H "X-Client-ID: $OBLIEN_CLIENT_ID" \
-H "X-Client-Secret: $OBLIEN_CLIENT_SECRET" \
-H "Content-Type: application/json" \
-d '{
"name": "my-first-sandbox",
"image": "node-20",
"config": { "cpus": 1, "memory_mb": 512 }
}'
# Execute a command (replace {id} with workspace ID from above)
curl -X POST https://api.oblien.com/workspace/{id}/exec \
-H "X-Client-ID: $OBLIEN_CLIENT_ID" \
-H "X-Client-Secret: $OBLIEN_CLIENT_SECRET" \
-H "Content-Type: application/json" \
-d '{ "cmd": ["echo", "Hello from Oblien!"] }'
# Delete workspace
curl -X DELETE https://api.oblien.com/workspace/{id} \
-H "X-Client-ID: $OBLIEN_CLIENT_ID" \
-H "X-Client-Secret: $OBLIEN_CLIENT_SECRET"What to explore next
Now that you have the basics, try these: