Skip to content
GitHub

Namespace

Deploy sandboxes on Namespace with ComputeSDK

Section titled “Deploy sandboxes on Namespace with ComputeSDK”

Deploy and manage containerized sandboxes on Namespace’s cloud infrastructure with ComputeSDK.


Namespace is a cloud compute platform that provides ephemeral container instances. With ComputeSDK’s Namespace provider, you can create isolated sandbox environments without managing infrastructure.


Prerequisites:



Install the ComputeSDK package in your application:

npm install computesdk

Add your credentials to a .env file:

# ComputeSDK credentials
COMPUTESDK_API_KEY=your_computesdk_api_key

# Namespace credentials
NSC_TOKEN=your_namespace_nsc_token

ComputeSDK auto-detects Namespace as your provider from the environment variables:

import { compute } from 'computesdk';

// Create a new sandbox
const sandbox = await compute.sandbox.create();
console.log(`Sandbox created: ${sandbox.sandboxId}`);

// Get sandbox info
const info = await sandbox.getInfo();
console.log(`Sandbox status: ${info.status}`);

// Clean up when done
await sandbox.destroy();

Your sandboxes are now running on Namespace’s cloud infrastructure!


Explicit provider configuration (optional)

Section titled “Explicit provider configuration (optional)”

If you prefer to configure the provider programmatically—useful for multi-provider setups or dynamic configuration—pass credentials directly:

import { compute } from 'computesdk';

compute.setConfig({
   computesdkApiKey: process.env.COMPUTESDK_API_KEY,
   provider: 'namespace',
   namespace: {
     token: process.env.NSC_TOKEN
   }
});

const sandbox = await compute.sandbox.create();

The Namespace provider accepts the following configuration options:

OptionEnvironment VariableRequiredDescription
tokenNSC_TOKENYesYour Namespace API token
virtualCpu-NoNumber of virtual CPU cores (default: 2)
memoryMegabytes-NoMemory allocation in MB (default: 4096)
machineArch-NoMachine architecture (default: ‘amd64’)
os-NoOperating system (default: ‘linux’)
interface NamespaceConfig {
  /** Namespace API token - if not provided, uses NSC_TOKEN env var */
  token?: string;
  /** Virtual CPU cores for the instance (default: 2) */
  virtualCpu?: number;
  /** Memory in megabytes for the instance (default: 4096) */
  memoryMegabytes?: number;
  /** Machine architecture (default: 'amd64') */
  machineArch?: string;
  /** Operating system (default: 'linux') */
  os?: string;
}

You can customize the compute resources allocated to your sandboxes:

import { compute } from 'computesdk';

compute.setConfig({
   computesdkApiKey: process.env.COMPUTESDK_API_KEY,
   provider: 'namespace',
   namespace: {
     token: process.env.NSC_TOKEN,
     virtualCpu: 4,
     memoryMegabytes: 8192
   }
});

const sandbox = await compute.sandbox.create();