@computesdk/namespace

中文文档
1.6.41发布于 2026/11/06MITTypeScriptESM + CJS构建来源已验证近 30 天下载 1.1万

Namespace provider for ComputeSDK - cloud-native sandboxes with optional GPU support

原始使用文档
文档目录9 节
  1. Installation
  2. Configuration
  3. Usage
  4. Passing Namespace API fields through
  5. Currently Implemented
  6. Sandbox Operations
  7. Configuration Options
  8. Notes
  9. Standard sizes (local discovery)

@computesdk/namespace

Namespace provider for ComputeSDK that enables creating and managing containerized sandboxes on Namespace's infrastructure.

Installation

npm install @computesdk/namespace

Configuration

The Namespace provider requires the following environment variable:

NSC_TOKEN=your_namespace_token

Usage

import { namespace } from '@computesdk/namespace';

const compute = namespace({
  token: 'your_token'
});

// Create a sandbox
const sandbox = await compute.instances.create();
console.log(`Created sandbox: ${sandbox.instanceId}`);

// List all sandboxes
const sandboxes = await compute.instances.list();

// Destroy the sandbox
await sandbox.destroy();

Passing Namespace API fields through

create() accepts raw Namespace API fields, merged as-is (snake_case) into the request. containerOptions goes into the container's ContainerRequest, and instanceOptions into CreateInstanceRequest. Fields the provider sets itself (shape, deadline, container name/args/env) take precedence, and the image is always chosen by image (image_ref/known_image_id in containerOptions are ignored).

// Inject the instance's workload token into the container at /var/run/nsc
const sandbox = await compute.instances.create({
  containerOptions: { nsc_state_path: '/var/run/nsc' },
});

Currently Implemented

Sandbox Operations

  • create() - Creates a new Namespace compute instance with container deployment
  • getById() - Retrieves a specific Namespace instance by ID
  • list() - Lists all Namespace instances in the account
  • destroy() - Deletes a Namespace instance

Configuration Options

  • token - Namespace API authentication token

Notes

  • Instances are automatically deployed upon creation
  • Instance names are generated automatically
  • All operations use Namespace's compute API
  • Environment variables take precedence over config options
  • Instances are immediately deleted when destroyed (no delayed deletion)

Standard sizes (local discovery)

provider.sizes.list() / resolve('sm', context?) declares exact sm, md, lg, and xl CPU/RAM requests for Linux amd64 only. create({ sizeClass: 'sm' }) requests instanceOptions.shape.virtual_cpu: 1 and memory_megabytes: 2048. Per-create standard requests override factory CPU/RAM defaults while preserving other instance options. Combining them with explicit native CPU/RAM fields is an error, even when the numbers match. Non-Linux/unverified architectures and xs/2xl remain unknown. Legacy native shape overrides are unchanged.

These are adapter-declared requests based on the documented Linux machine-shape catalog, not account/region availability checks or observed resources. Discovery never reads token files or calls Namespace. Successful standardized creates expose frozen instance.sizing request metadata.

Unit boundary: the official Namespace TypeScript SDK compute example explicitly describes 4 GiB using memoryMegabytes: 4 * 1024. Accordingly the resolver sends canonical MiB numbers unchanged to the corresponding native memory_megabytes field (2048/4096/8192/16384); no decimal-MB conversion is performed. This is documented request-unit evidence, not a measurement of delivered bytes or an inference solely from machine-shape “GB” labels. Factory CPU/RAM values are defaults overridden by sizeClass; explicit per-create CPU/RAM selectors, including ambiguous aliases, are rejected instead.

Standard platform context must use enumerable own data properties; present os/machine_arch selectors must be strings, not null/undefined. The resolved patch explicitly carries the verified Linux/amd64 platform into the native request, so a factory default cannot diverge from the declared mapping. Legacy creates without sizeClass retain their original descriptor behavior.

版本与发布记录

@computesdk/namespace 共发布 82 个版本,首次发布于 2025/12/06;过去 12 个月发布了 82 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.6.41latest2026/11/064 天前
1.6.402026/11/046 天前
1.6.392026/10/2812 天前
1.6.382026/10/2813 天前
1.6.372026/10/2714 天前
1.6.362026/10/2714 天前

关于 @computesdk/namespace 的常见问题

@computesdk/namespace 是什么?

Namespace provider for ComputeSDK - cloud-native sandboxes with optional GPU support

如何安装 @computesdk/namespace?

在项目目录运行 npm install @computesdk/namespace,或使用 pnpm add / yarn add / bun add。

@computesdk/namespace 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@computesdk/namespace 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@computesdk/namespace 可以商用吗?

@computesdk/namespace 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@computesdk/namespace 的下载量有多少?

根据 npm 官方下载统计,@computesdk/namespace 在 2026/10/11 – 2026/11/09 这 30 天内被下载 11,094 次,日均约 370 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@computesdk/namespace 还在维护吗?

最新版本 1.6.41 发布于 2026/11/06(4 天前);至今共发布 82 个版本,其中过去 12 个月发布了 82 个;首次发布于 2025/12/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。