@chamvi/sandbox-local

中文文档
0.8.0发布于 2026/11/09Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 2854

Local sandbox provider for chamvi: workspaces in a temporary directory, no isolation.

原始使用文档
文档目录6 节
  1. Installation
  2. Usage
  3. What it does and does not do
  4. Options
  5. API
  6. License

@chamvi/sandbox-local

@chamvi/sandbox-local

Workspaces in a temporary directory, for development and tests.
Commands are spawned on the host as your user: no container, no isolation.
Use @chamvi/sandbox-docker or @chamvi/sandbox-k8s for anything a model may steer.

npm version CI License


Table of Contents

Installation

npm install @chamvi/sandbox-local @chamvi/sandbox @chamvi/core ai --save

ESM only, Node.js >=26.0.0, a POSIX host (Linux or macOS) with git on the PATH. @chamvi/core and @chamvi/sandbox are peer dependencies; there are no other runtime dependencies.

Usage

import { createWorkspaceManager } from '@chamvi/sandbox';
import type { IWorkspaceManager } from '@chamvi/sandbox';
import { createLocalSandbox } from '@chamvi/sandbox-local';

// no isolation: commands run as your user, for development and tests only
export function createDevWorkspaces(root?: string): IWorkspaceManager {
    return createWorkspaceManager({ provider: createLocalSandbox({ root }) });
}

Each workspace is a folder <root>/<id>/ (root defaults to <os tmpdir>/chamvi-workspaces) with repo/ (the model's /workspace), home/, tmp/ and a workspace.json record (run id, deployment, repository, ref, env, creation and expiry) that find rebuilds the workspace from and the garbage collection reads, so a restarted process reaches a run's workspace again. The create's env is written to that record on disk, so the folder is 0700 and the record 0600 (owner only). dispose() removes the folder.

What it does and does not do

No isolation. A command runs as the host user with the host's filesystem, network and processes in reach. /workspace paths in tool input are confined to the folder, symbolic links included (a path whose real path leaves the folder, say through a link the repository brings, is a ValidationError; checked before each call, so a command running at the same time can still swap a link in), but bash can cd / and read your SSH keys. Use it on your machine with models and repositories you trust, and in tests.

What it does enforce:

  • Environment: only the host PATH, HOME and TMPDIR inside the workspace folder, GIT_TERMINAL_PROMPT=0, GIT_CONFIG_NOSYSTEM=1 (a system gitconfig may name a credential helper such as macOS osxkeychain), NPM_CONFIG_UPDATE_NOTIFIER=false, CI=true, the package-cache variables (XDG_CACHE_HOME, npm_config_cache, PIP_CACHE_DIR, GOMODCACHE, GOCACHE, COMPOSER_CACHE_DIR) under <root>/.cache, shared by every workspace of the root (cache: false sets none), and the configured env. No other host variable (tokens, cloud credentials) reaches a command.
  • Timeouts and abort: every command starts its own process group (detached); a timeout, an abort or a dispose kills the whole group with SIGKILL, backgrounded grandchildren included. The kill timer is cleared when the child exits, so it never signals a reused pid. A command that exits while a background job it started still holds its output (node server.js & echo started) returns 2 s (KILL_GRACE_MS) after its exit with its own exit code and timedOut: false; the job keeps running until the workspace is disposed, as on Docker and Kubernetes, also with its output redirected (nohup node server.js > log 2>&1 &). The workspace remembers the process group of such a command and forgets it once the group ended (checked every second, LINGER_CHECK_MS; a group id is only reused after every member is gone), so the dispose kills the jobs but not a group that took the id over later. The one window left is a group that ends and whose id another process group takes within that second. Only the process that spawned a job knows its group, so the jobs die with that process too (on its exit, which the chamvi CLI reaches on SIGTERM and SIGINT): unlike a Docker or Kubernetes workspace, a local one found again after a restart keeps its files but has no background jobs, and a process killed with SIGKILL (or one that exits without an exit event, e.g. on an unhandled SIGTERM) leaves its jobs running, outside any later dispose.
  • Output caps: 64 KiB per stream, drained past the cap.
  • No images: a local workspace runs no container image, so create_workspace never offers image on this provider (a requested one is a ValidationError).
  • Lifetime: limits.maxLifetimeMs (default 7 days) is the expiry; collectGarbage({ deployment, isSettled }) deletes the deployment's expired workspace folders under root (also those of crashed processes) and, with isSettled, those of settled runs, disposing open ones first. Folders that are no workspace are left alone. A folder that cannot be deleted does not stop the pass: the others go, and one SandboxError with the count and the first failure is thrown at the end.

cpu, memory, storage and pids are not enforced, so limits takes maxLifetimeMs only.

Options

createLocalSandbox(options?):

OptionTypeDefaultDescription
rootstring<os tmpdir>/chamvi-workspacesDirectory holding one folder per workspace
envRecord<string, string>noneAdded to every workspace's environment (wins over the defaults)
limits{ maxLifetimeMs? }604_800_000The workspace's hard lifetime cap
cachebooleantruePoint the package caches into <root>/.cache
clockIClocksystemClockExpiry and timeouts

API

ExportKindPurpose
createLocalSandboxfunctionThe ISandboxProvider (name: 'local')

Types: LocalSandboxOptions.

License

Published under Apache License 2.0.

版本与发布记录

@chamvi/sandbox-local 共发布 15 个版本,首次发布于 2026/10/25;过去 12 个月发布了 15 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.8.0latest2026/11/09今天
0.7.32026/11/063 天前
0.7.22026/11/053 天前
0.7.12026/11/054 天前
0.7.02026/11/045 天前
0.6.12026/11/045 天前

关于 @chamvi/sandbox-local 的常见问题

@chamvi/sandbox-local 是什么?

Local sandbox provider for chamvi: workspaces in a temporary directory, no isolation.

如何安装 @chamvi/sandbox-local?

在项目目录运行 npm install @chamvi/sandbox-local,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@chamvi/core(^0.8.0)、@chamvi/sandbox(^0.8.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@chamvi/sandbox-local 支持 TypeScript 吗?

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

@chamvi/sandbox-local 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@chamvi/sandbox-local 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=26.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@chamvi/sandbox-local 可以商用吗?

@chamvi/sandbox-local 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@chamvi/sandbox-local 的下载量有多少?

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

@chamvi/sandbox-local 还在维护吗?

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