@deepseek-ai/dsh-sandbox-local 0.0.1-rc.1 → 0.0.1-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +2 -2
- package/README.md +4 -2
- package/README.zh.md +4 -2
- package/lib/index.js +80 -92
- package/lib/types/index.d.ts +32 -52
- package/package.json +11 -11
package/README.i18n.yaml
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# pnpm run verify-translation-pairing --write packages/sandbox/sandbox-local/README.md
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: e43133c7c5b64d7779162b790ee6cab7806fd100
|
|
6
|
+
README.zh.md: 32743d1b0aba5bed41ee53d90c4ed44dc936161c
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
English | [中文](README.zh.md)
|
|
4
4
|
|
|
5
|
-
Local implementation of the [`dsh-sandbox`](../sandbox/) seam. It selects and caches one platform runner: Linux prefers a working `bwrap` then Landlock; macOS uses Seatbelt. Multiple candidates are probed in order, while a sole candidate is selected directly.
|
|
5
|
+
Local implementation of the [`dsh-sandbox`](../sandbox/) seam. It selects and caches one platform runner: Linux prefers a working `bwrap` then Landlock; macOS uses Seatbelt; Windows uses the ACL restricted-token runner. Multiple candidates are probed in order, while a sole candidate is selected directly.
|
|
6
6
|
|
|
7
7
|
The package root exports the default and named `LocalSandboxProvider` plugin and `Config`; platform profile builders stay internal.
|
|
8
8
|
|
|
@@ -12,6 +12,8 @@ Policy is per call; the provider stores only the mechanism and cached runner ver
|
|
|
12
12
|
|
|
13
13
|
The Seatbelt profile is allow-default with `(deny file-write*)` plus write allow-lists, so exactly the mode's promised file effects are governed: `read-only` grants the `/dev/null` literal alone; `workspace-write` adds the workspace root, `/tmp`, and the per-user darwin temp dir (`os.tmpdir()` — the platform's real temp area for mkstemp-family tools), every root canonicalized because Seatbelt matches resolved paths (`/tmp` IS `/private/tmp`). Apple marks the `sandbox-exec` CLI deprecated but ships it on every macOS; the functional probe is what fails closed if that ever changes.
|
|
14
14
|
|
|
15
|
+
The Windows rung keeps one deterministic write SID and standing ACE per workspace, but gives every live session/workspace pair a random private temp directory with a distinct SID and revocable ACE. Sessions sharing a workspace therefore share its intended write authority without inheriting one another's temp authority. A fresh provider always chooses a new temp path and SID, so crash residue cannot block or authorize a resumed session; agentless calls receive the same per-invocation isolation from the runner. A workspace equal to or containing the platform temp root fails before any ACL mutation because its inheritable workspace ACE would otherwise reach every private temp child.
|
|
16
|
+
|
|
15
17
|
[`@deepseek-ai/node-addon-landlock-run`](https://www.npmjs.com/package/@deepseek-ai/node-addon-landlock-run) supplies the platform launcher, functional probe, and CLI argument vocabulary. This provider owns only mode-to-grant mapping and runner selection. Keeping path resolution and probe parsing with the versioned binary prevents contract drift.
|
|
16
18
|
|
|
17
19
|
```yaml
|
|
@@ -31,7 +33,7 @@ No direct invalidation; the named consumer owns any request-prefix changes.
|
|
|
31
33
|
|
|
32
34
|
## Known Limitations and Deferred Work
|
|
33
35
|
|
|
34
|
-
- **Windows
|
|
36
|
+
- **Windows ACL enforcement is partial** — the restricted token must retain Everyone for process initialization, so external objects granting Everyone write access remain writable; NTFS hard links also alias one file object across workspace and external paths. The provider reports `enforcement: 'partial'` rather than overstating that boundary as full.
|
|
35
37
|
- **Landlock may be partial** — older supported kernel ABIs confine only the access classes they expose, reported as `enforcement: 'partial'` rather than overstated as full.
|
|
36
38
|
- **Seatbelt depends on deprecated `sandbox-exec`** — macOS still ships it, but this provider cannot replace or probe that private policy engine if Apple removes it.
|
|
37
39
|
- **Runner selection is cached for the provider lifetime** — installing, removing, or repairing a runner requires reloading the plugin before selection changes.
|
package/README.zh.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[English](README.md) | 中文
|
|
4
4
|
|
|
5
|
-
[`dsh-sandbox`](../sandbox/) seam 的本地实现。它选择并缓存一个平台 runner:Linux 优先选择可工作的 `bwrap`,否则选择 Landlock;macOS 使用 Seatbelt。多个候选项会按顺序探测,只有一个候选项时则直接选择。
|
|
5
|
+
[`dsh-sandbox`](../sandbox/) seam 的本地实现。它选择并缓存一个平台 runner:Linux 优先选择可工作的 `bwrap`,否则选择 Landlock;macOS 使用 Seatbelt;Windows 使用 ACL 受限令牌 runner。多个候选项会按顺序探测,只有一个候选项时则直接选择。
|
|
6
6
|
|
|
7
7
|
包根目录导出默认及命名的 `LocalSandboxProvider` 插件和 `Config`;平台 profile builder 仍为内部实现。
|
|
8
8
|
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
|
|
13
13
|
Seatbelt profile 默认允许,但带 `(deny file-write*)` 和写入 allow-list,因此恰好约束相应模式承诺的文件操作:`read-only` 只授予 `/dev/null` 字面路径;`workspace-write` 另加工作区根目录、`/tmp` 和逐用户 darwin 临时目录(`os.tmpdir()`,即平台供 mkstemp 家族工具使用的真实临时区域)。每个根目录都经过规范化,因为 Seatbelt 匹配解析后的路径(`/tmp` 就是 `/private/tmp`)。Apple 将 `sandbox-exec` CLI(命令行界面)标为 deprecated,但所有 macOS 系统仍会提供它;若情况发生变化,功能探测会使执行被拒绝。
|
|
14
14
|
|
|
15
|
+
Windows 档为每个工作区保留一个确定性写入 SID 和常驻 ACE,但为每个活跃的会话/工作区对分配一个随机私有临时目录,以及不同的 SID 和可回收 ACE。因此,共享工作区的会话会共享预期的写权限,却不会继承彼此的临时目录权限。新的提供方总会选择新的临时路径和 SID,因此崩溃残留既无法阻止恢复的会话,也无法向其授权;runner 会为无 agent(智能体)的调用提供同样的逐调用隔离。如果工作区等于或包含平台临时根目录,调用会在任何 ACL 改动发生前失败,因为否则其可继承的工作区 ACE 会延伸到每个私有临时子目录。
|
|
16
|
+
|
|
15
17
|
[`@deepseek-ai/node-addon-landlock-run`](https://www.npmjs.com/package/@deepseek-ai/node-addon-landlock-run)提供平台 launcher、功能探测和 CLI 参数词汇。该提供方只负责模式到授权的映射与 runner 选择。把路径解析和探测解析保留在带版本的 binary 中,可防止约定漂移。
|
|
16
18
|
|
|
17
19
|
```yaml
|
|
@@ -31,7 +33,7 @@ Seatbelt profile 默认允许,但带 `(deny file-write*)` 和写入 allow-list
|
|
|
31
33
|
|
|
32
34
|
## 已知限制与暂缓事项
|
|
33
35
|
|
|
34
|
-
- **Windows
|
|
36
|
+
- **Windows ACL 只能实现部分强制执行**:受限令牌必须保留 Everyone 以完成进程初始化,因此授予 Everyone 写访问的外部对象仍可写;NTFS 硬链接也会使工作区路径与外部路径指向同一个文件对象。提供方报告 `enforcement: 'partial'`,而不会把该边界夸大为完整强制执行。
|
|
35
37
|
- **Landlock 可能只实现部分强制执行**:较旧且受支持的内核 ABI 只能限制自身公开的访问类别,因此报告 `enforcement: 'partial'`,不会夸大为完整强制执行。
|
|
36
38
|
- **Seatbelt 依赖已弃用的 `sandbox-exec`**:macOS 仍会提供它,但若 Apple 移除该私有策略引擎,该提供方无法替换或探测。
|
|
37
39
|
- **runner 选择在提供方生命周期内缓存**:安装、移除或修复 runner 后,必须重载插件才能改变选择。
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import {
|
|
3
|
-
import { existsSync, mkdirSync, rmSync } from "node:fs";
|
|
2
|
+
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
4
3
|
import { tmpdir } from "node:os";
|
|
5
4
|
import { join } from "node:path";
|
|
6
5
|
import { fileURLToPath } from "node:url";
|
|
@@ -8,7 +7,7 @@ import { LAUNCHER_BIN, LAUNCHER_FAILURE_EXIT, grantArgs, launcherPath, probe } f
|
|
|
8
7
|
import z from "@deepseek-ai/schemastery";
|
|
9
8
|
import { assertNever } from "@deepseek-ai/dsh-llm";
|
|
10
9
|
import { SandboxProvider, SandboxUnavailableError, writableRoots } from "@deepseek-ai/dsh-sandbox";
|
|
11
|
-
import { AclWriteGrant, workspaceWriteSid } from "@deepseek-ai/dsh-sandbox-windows-acl";
|
|
10
|
+
import { AclWriteGrant, assertTempRootOutsideWorkspace, tempWriteSid, workspaceWriteSid } from "@deepseek-ai/dsh-sandbox-windows-acl";
|
|
12
11
|
//#region lib/types/profiles.js
|
|
13
12
|
/**
|
|
14
13
|
* Internal platform-profile builders for the local sandbox provider.
|
|
@@ -84,14 +83,16 @@ function seatbeltProfileArgs(policy) {
|
|
|
84
83
|
*
|
|
85
84
|
* The windows-acl rung additionally owns the write grants: the write SID is
|
|
86
85
|
* the per-WORKSPACE identity derived from the canonical workspace path
|
|
87
|
-
* (`workspaceWriteSid`),
|
|
88
|
-
*
|
|
86
|
+
* (`workspaceWriteSid`), while every live session receives a RANDOM private
|
|
87
|
+
* temp directory and its own derived capability (`tempWriteSid`). The
|
|
89
88
|
* workspace-root ACE materializes once per workspace per server lifetime
|
|
90
89
|
* and STANDS (the cross-session reuse cache — the exact-ACE skip makes
|
|
91
90
|
* every later provision O(1) instead of re-propagating the tree per
|
|
92
91
|
* session); the private-temp ACEs are revoked on dispose. The runner
|
|
93
|
-
* receives
|
|
94
|
-
*
|
|
92
|
+
* receives both SIDs (their presence marks the seam-managed contract) and
|
|
93
|
+
* stops managing DACLs itself. The rung reports partial enforcement because
|
|
94
|
+
* WRITE_RESTRICTED must retain Everyone in its
|
|
95
|
+
* restricting list and NTFS hard links alias one file object across paths.
|
|
95
96
|
* @module @deepseek-ai/dsh-sandbox-local
|
|
96
97
|
*/
|
|
97
98
|
/** Probe whether `bwrap` can create the profile; the provider caches the bounded result. */
|
|
@@ -163,24 +164,6 @@ function defaultProbeWindowsAcl(runnerInvocation, timeoutMs) {
|
|
|
163
164
|
}).status === 0;
|
|
164
165
|
}
|
|
165
166
|
/**
|
|
166
|
-
* The session's private temp subdirectory: `<tmpdir>\dsh-<16 hex>`, derived
|
|
167
|
-
* from the session id and its workspace instead of stored. The same session
|
|
168
|
-
* and workspace always name the same directory — a resumed session
|
|
169
|
-
* re-grants it (the exact-ACE skip keeps that O(1)) — while a fork's
|
|
170
|
-
* different session id names a fresh one. The name is predictable to anyone
|
|
171
|
-
* who knows the session id (the confined command sees it as
|
|
172
|
-
* `DSH_SESSION_ID`), so the provider creates the directory EXCLUSIVELY and
|
|
173
|
-
* rejects reparse points: a pre-placed entry fails the first confined run
|
|
174
|
-
* loudly, and cannot redirect the grant onto a foreign object.
|
|
175
|
-
* @param sessionId - the policy's calling-session identity.
|
|
176
|
-
* @param workspaceRoot - the resolved policy root.
|
|
177
|
-
* @returns the session's private temp subdirectory path.
|
|
178
|
-
*/
|
|
179
|
-
function sessionTempDir(sessionId, workspaceRoot) {
|
|
180
|
-
const digest = createHash("sha256").update(String(sessionId)).update("\0").update(workspaceRoot).digest("hex");
|
|
181
|
-
return join(tmpdir(), `dsh-${digest.slice(0, 16)}`);
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
167
|
* The runner chain per platform — selection is BY PLATFORM first, probes
|
|
185
168
|
* second: a platform's chain is probed in preference order only when it has
|
|
186
169
|
* MORE than one candidate (probing arbitrates; it does not re-validate a
|
|
@@ -207,7 +190,7 @@ const STATIC_ENFORCEMENT = {
|
|
|
207
190
|
bwrap: "full",
|
|
208
191
|
landlock: "full",
|
|
209
192
|
seatbelt: "full",
|
|
210
|
-
"windows-acl": "
|
|
193
|
+
"windows-acl": "partial"
|
|
211
194
|
};
|
|
212
195
|
/**
|
|
213
196
|
* A probe bound must be a positive finite number: Node treats
|
|
@@ -263,8 +246,9 @@ const RUNNER_FAILURE_RULES = {
|
|
|
263
246
|
* Local process-sandbox provider. Registers as `ctx.sandbox`. Caches the
|
|
264
247
|
* chain verdict and, on the windows-acl rung, the write grants
|
|
265
248
|
* ({@link AclWriteGrant}: the standing workspace-root grant per workspace
|
|
266
|
-
* and the revocable private-temp grant per session, the
|
|
267
|
-
* provider dispose); the one-time probes spawn nothing
|
|
249
|
+
* and the revocable private-temp grant per live session/workspace pair, the
|
|
250
|
+
* latter revoked on provider dispose); the one-time probes spawn nothing
|
|
251
|
+
* else.
|
|
268
252
|
*/
|
|
269
253
|
var LocalSandboxProvider = class extends SandboxProvider {
|
|
270
254
|
static Config = z.object({
|
|
@@ -283,12 +267,11 @@ var LocalSandboxProvider = class extends SandboxProvider {
|
|
|
283
267
|
* Server-lifetime write grants (windows-acl rung): the STANDING
|
|
284
268
|
* workspace-root grant per workspace (its ACE is the cross-session reuse
|
|
285
269
|
* cache and outlives the provider — never revoked) and the REVOCABLE
|
|
286
|
-
* private-temp grant per session (revoked on provider
|
|
270
|
+
* private-temp grant per live session/workspace pair (revoked on provider
|
|
271
|
+
* dispose).
|
|
287
272
|
*/
|
|
288
273
|
workspaceGrants = /* @__PURE__ */ new Map();
|
|
289
|
-
|
|
290
|
-
/** Session id → the private temp directory this provider created (removed on dispose). */
|
|
291
|
-
tempDirs = /* @__PURE__ */ new Map();
|
|
274
|
+
tempCapabilities = /* @__PURE__ */ new Map();
|
|
292
275
|
constructor(ctx, config) {
|
|
293
276
|
super(ctx);
|
|
294
277
|
const runner = config.runnerCommand;
|
|
@@ -351,20 +334,19 @@ var LocalSandboxProvider = class extends SandboxProvider {
|
|
|
351
334
|
}
|
|
352
335
|
/**
|
|
353
336
|
* The windows-acl runner argv for one policy. With a calling session (the
|
|
354
|
-
* policy's `sessionId`), the
|
|
355
|
-
* lifetime — the standing workspace-root grant per
|
|
356
|
-
* revocable private-temp
|
|
357
|
-
* `--write-sid`
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
* temp root and no `--write-sid`: the runner self-manages its DACLs.
|
|
337
|
+
* policy's `sessionId`) under workspace-write, the grants are materialized
|
|
338
|
+
* once per provider lifetime — the standing workspace-root grant per
|
|
339
|
+
* workspace and a revocable, RANDOM private-temp capability per live
|
|
340
|
+
* session/workspace pair. The runner receives `--write-sid` plus
|
|
341
|
+
* `--temp-write-sid` and grants nothing itself. Agentless workspace-write
|
|
342
|
+
* calls pass the ambient temp ROOT and no SID flags: the runner creates and
|
|
343
|
+
* removes a random private child directory for that one invocation.
|
|
362
344
|
* @param policy - the resolved per-call policy.
|
|
363
345
|
* @returns the runner invocation.
|
|
364
346
|
*/
|
|
365
347
|
windowsAclRunnerArgv(policy) {
|
|
366
348
|
const sessionId = policy.sessionId;
|
|
367
|
-
if (sessionId === void 0) return [
|
|
349
|
+
if (sessionId === void 0 || policy.mode === "read-only") return [
|
|
368
350
|
...this.windowsAclRunnerInvocation(),
|
|
369
351
|
"--workspace",
|
|
370
352
|
policy.workspaceRoot,
|
|
@@ -373,43 +355,37 @@ var LocalSandboxProvider = class extends SandboxProvider {
|
|
|
373
355
|
"--mode",
|
|
374
356
|
policy.mode
|
|
375
357
|
];
|
|
376
|
-
this.materializeAclGrant(sessionId, policy.workspaceRoot
|
|
358
|
+
const temp = this.materializeAclGrant(sessionId, policy.workspaceRoot);
|
|
377
359
|
return [
|
|
378
360
|
...this.windowsAclRunnerInvocation(),
|
|
379
361
|
"--workspace",
|
|
380
362
|
policy.workspaceRoot,
|
|
381
363
|
"--temp",
|
|
382
|
-
|
|
364
|
+
temp.dir,
|
|
383
365
|
"--mode",
|
|
384
366
|
policy.mode,
|
|
385
367
|
"--write-sid",
|
|
386
|
-
workspaceWriteSid(policy.workspaceRoot)
|
|
368
|
+
workspaceWriteSid(policy.workspaceRoot),
|
|
369
|
+
"--temp-write-sid",
|
|
370
|
+
temp.writeSid
|
|
387
371
|
];
|
|
388
372
|
}
|
|
389
373
|
/**
|
|
390
|
-
* Materialize
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
* never lands on a foreign object); read-only materializes NOTHING — its
|
|
399
|
-
* token alone restricts every write, and the standing grant from an
|
|
400
|
-
* earlier workspace-write period is KEPT through a downgrade (never
|
|
401
|
-
* revoked): the read-only restricted token carries no write SID (the
|
|
402
|
-
* read-only list), so the ACE is inert there, while the map hit keeps the
|
|
403
|
-
* re-upgrade free of re-propagation. Fail-closed: a half-materialized
|
|
404
|
-
* temp grant is revoked before the error propagates.
|
|
374
|
+
* Materialize one workspace-write policy's ACEs once per provider
|
|
375
|
+
* lifetime. The workspace SID and standing root grant are shared by the
|
|
376
|
+
* workspace. The temp directory is random and carries a distinct SID, so
|
|
377
|
+
* another session on the same workspace cannot use the shared workspace
|
|
378
|
+
* SID to enter it. A fresh provider always chooses a new path; crash
|
|
379
|
+
* residue therefore cannot collide with or authorize a resumed session.
|
|
380
|
+
* Fail-closed: a half-materialized temp grant is revoked and its directory
|
|
381
|
+
* removed before the error propagates.
|
|
405
382
|
* @param sessionId - the policy's calling-session identity.
|
|
406
383
|
* @param workspaceRoot - the resolved policy root.
|
|
407
|
-
* @
|
|
384
|
+
* @returns the pair's private temp directory and write capability.
|
|
408
385
|
*/
|
|
409
|
-
materializeAclGrant(sessionId, workspaceRoot
|
|
410
|
-
|
|
386
|
+
materializeAclGrant(sessionId, workspaceRoot) {
|
|
387
|
+
assertTempRootOutsideWorkspace(workspaceRoot, tmpdir());
|
|
411
388
|
const writeSid = workspaceWriteSid(workspaceRoot);
|
|
412
|
-
const tempDir = sessionTempDir(sessionId, workspaceRoot);
|
|
413
389
|
if (!this.workspaceGrants.has(workspaceRoot)) {
|
|
414
390
|
const grant = AclWriteGrant.create(writeSid);
|
|
415
391
|
try {
|
|
@@ -424,27 +400,37 @@ var LocalSandboxProvider = class extends SandboxProvider {
|
|
|
424
400
|
}
|
|
425
401
|
this.workspaceGrants.set(workspaceRoot, grant);
|
|
426
402
|
}
|
|
427
|
-
|
|
428
|
-
const
|
|
429
|
-
|
|
403
|
+
const key = JSON.stringify([String(sessionId), workspaceRoot]);
|
|
404
|
+
const existing = this.tempCapabilities.get(key);
|
|
405
|
+
if (existing !== void 0) return existing;
|
|
406
|
+
const tempDir = mkdtempSync(join(tmpdir(), "dsh-"));
|
|
407
|
+
const tempSid = tempWriteSid(tempDir);
|
|
408
|
+
let grant;
|
|
430
409
|
try {
|
|
431
|
-
|
|
432
|
-
created = true;
|
|
410
|
+
grant = AclWriteGrant.create(tempSid);
|
|
433
411
|
grant.add(tempDir);
|
|
434
412
|
} catch (error) {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
force: true
|
|
438
|
-
});
|
|
439
|
-
try {
|
|
413
|
+
const cleanupFailures = [];
|
|
414
|
+
if (grant !== void 0) try {
|
|
440
415
|
grant.dispose();
|
|
441
416
|
} catch (cleanupError) {
|
|
442
|
-
|
|
417
|
+
cleanupFailures.push(cleanupError);
|
|
418
|
+
}
|
|
419
|
+
try {
|
|
420
|
+
this.removeTempDir(tempDir);
|
|
421
|
+
} catch (cleanupError) {
|
|
422
|
+
cleanupFailures.push(cleanupError);
|
|
443
423
|
}
|
|
424
|
+
if (cleanupFailures.length > 0) throw new AggregateError([error, ...cleanupFailures], "sandbox-local windows-acl temp grant materialization failed and its cleanup also failed");
|
|
444
425
|
throw error;
|
|
445
426
|
}
|
|
446
|
-
|
|
447
|
-
|
|
427
|
+
const capability = {
|
|
428
|
+
dir: tempDir,
|
|
429
|
+
writeSid: tempSid,
|
|
430
|
+
grant
|
|
431
|
+
};
|
|
432
|
+
this.tempCapabilities.set(key, capability);
|
|
433
|
+
return capability;
|
|
448
434
|
}
|
|
449
435
|
/**
|
|
450
436
|
* Dispose every write grant (provider dispose): the revocable temp ACEs
|
|
@@ -452,36 +438,38 @@ var LocalSandboxProvider = class extends SandboxProvider {
|
|
|
452
438
|
* removed, and every SID allocation is freed; the standing workspace ACEs
|
|
453
439
|
* stay (the reuse cache). Cleanup failures are reported, not thrown:
|
|
454
440
|
* cordis teardown must not be aborted by grant cleanup. A crash skips all
|
|
455
|
-
* of it
|
|
456
|
-
* OS temp hygiene (or manual removal)
|
|
441
|
+
* of it, but a new provider never reuses the residue's random path or SID;
|
|
442
|
+
* OS temp hygiene (or manual removal) eventually reclaims it.
|
|
457
443
|
*/
|
|
458
444
|
revokeAclGrants() {
|
|
459
|
-
if (this.workspaceGrants.size === 0 && this.
|
|
445
|
+
if (this.workspaceGrants.size === 0 && this.tempCapabilities.size === 0) return;
|
|
460
446
|
const failures = [];
|
|
461
|
-
for (const grant of [...this.workspaceGrants.values(), ...this.
|
|
447
|
+
for (const grant of [...this.workspaceGrants.values(), ...[...this.tempCapabilities.values()].map((capability) => capability.grant)]) try {
|
|
462
448
|
grant.dispose();
|
|
463
449
|
} catch (error) {
|
|
464
450
|
failures.push(error);
|
|
465
451
|
}
|
|
466
|
-
const
|
|
467
|
-
|
|
468
|
-
recursive: true,
|
|
469
|
-
force: true
|
|
470
|
-
});
|
|
471
|
-
});
|
|
472
|
-
for (const dir of this.tempDirs.values()) try {
|
|
473
|
-
rmTempDir(dir);
|
|
452
|
+
for (const { dir } of this.tempCapabilities.values()) try {
|
|
453
|
+
this.removeTempDir(dir);
|
|
474
454
|
} catch (error) {
|
|
475
455
|
failures.push(error);
|
|
476
456
|
}
|
|
477
457
|
this.workspaceGrants.clear();
|
|
478
|
-
this.
|
|
479
|
-
this.tempDirs.clear();
|
|
458
|
+
this.tempCapabilities.clear();
|
|
480
459
|
if (failures.length > 0) {
|
|
481
460
|
this.ctx.logger.warn(`sandbox-local: windows-acl grant cleanup completed with ${failures.length} failure(s)`);
|
|
482
461
|
for (const error of failures) this.ctx.logger.warn(error);
|
|
483
462
|
}
|
|
484
463
|
}
|
|
464
|
+
/** Remove one provider-owned private temp directory (injectable for cleanup tests). */
|
|
465
|
+
removeTempDir(dir) {
|
|
466
|
+
(this.internals.rmTempDir ?? ((path) => {
|
|
467
|
+
rmSync(path, {
|
|
468
|
+
recursive: true,
|
|
469
|
+
force: true
|
|
470
|
+
});
|
|
471
|
+
}))(dir);
|
|
472
|
+
}
|
|
485
473
|
/**
|
|
486
474
|
* Resolve which runner confines commands, once, for the provider's
|
|
487
475
|
* lifetime: this platform's chain ({@link PLATFORM_CHAINS}), its sole
|
|
@@ -518,7 +506,7 @@ var LocalSandboxProvider = class extends SandboxProvider {
|
|
|
518
506
|
case "bwrap": return (this.internals.probeBwrap ?? (() => defaultProbeBwrap(this.probeTimeoutMs)))() ? "full" : "unusable";
|
|
519
507
|
case "landlock": return (this.internals.probeLandlock ?? ((launcher) => probe(launcher, { timeoutMs: this.probeTimeoutMs })))(this.landlockLauncher());
|
|
520
508
|
case "seatbelt": return (this.internals.probeSeatbelt ?? ((exec) => defaultProbeSeatbelt(exec, this.probeTimeoutMs)))(this.seatbeltExec()) ? "full" : "unusable";
|
|
521
|
-
case "windows-acl": return (this.internals.probeWindowsAcl ?? (() => defaultProbeWindowsAcl(this.windowsAclRunnerInvocation(), this.probeTimeoutMs)))() ? "
|
|
509
|
+
case "windows-acl": return (this.internals.probeWindowsAcl ?? (() => defaultProbeWindowsAcl(this.windowsAclRunnerInvocation(), this.probeTimeoutMs)))() ? "partial" : "unusable";
|
|
522
510
|
default: return assertNever(runner);
|
|
523
511
|
}
|
|
524
512
|
}
|
|
@@ -551,4 +539,4 @@ var LocalSandboxProvider = class extends SandboxProvider {
|
|
|
551
539
|
}
|
|
552
540
|
};
|
|
553
541
|
//#endregion
|
|
554
|
-
export { LocalSandboxProvider, LocalSandboxProvider as default
|
|
542
|
+
export { LocalSandboxProvider, LocalSandboxProvider as default };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -7,21 +7,22 @@
|
|
|
7
7
|
*
|
|
8
8
|
* The windows-acl rung additionally owns the write grants: the write SID is
|
|
9
9
|
* the per-WORKSPACE identity derived from the canonical workspace path
|
|
10
|
-
* (`workspaceWriteSid`),
|
|
11
|
-
*
|
|
10
|
+
* (`workspaceWriteSid`), while every live session receives a RANDOM private
|
|
11
|
+
* temp directory and its own derived capability (`tempWriteSid`). The
|
|
12
12
|
* workspace-root ACE materializes once per workspace per server lifetime
|
|
13
13
|
* and STANDS (the cross-session reuse cache — the exact-ACE skip makes
|
|
14
14
|
* every later provision O(1) instead of re-propagating the tree per
|
|
15
15
|
* session); the private-temp ACEs are revoked on dispose. The runner
|
|
16
|
-
* receives
|
|
17
|
-
*
|
|
16
|
+
* receives both SIDs (their presence marks the seam-managed contract) and
|
|
17
|
+
* stops managing DACLs itself. The rung reports partial enforcement because
|
|
18
|
+
* WRITE_RESTRICTED must retain Everyone in its
|
|
19
|
+
* restricting list and NTFS hard links alias one file object across paths.
|
|
18
20
|
* @module @deepseek-ai/dsh-sandbox-local
|
|
19
21
|
*/
|
|
20
22
|
import { Context } from '@deepseek-ai/cordis';
|
|
21
23
|
import z from '@deepseek-ai/schemastery';
|
|
22
24
|
import { SandboxProvider } from '@deepseek-ai/dsh-sandbox';
|
|
23
25
|
import type { ConfinedArgv, SandboxEnforcement, SandboxPolicy } from '@deepseek-ai/dsh-sandbox';
|
|
24
|
-
import type { SessionId } from '@deepseek-ai/dsh-session';
|
|
25
26
|
/** Plugin config. All optional — `static Config` supplies the defaults. */
|
|
26
27
|
export interface Config {
|
|
27
28
|
/**
|
|
@@ -45,21 +46,6 @@ export interface Config {
|
|
|
45
46
|
/** Positive timeout for each functional probe; zero would mean unbounded to Node. */
|
|
46
47
|
probeTimeoutMs?: number;
|
|
47
48
|
}
|
|
48
|
-
/**
|
|
49
|
-
* The session's private temp subdirectory: `<tmpdir>\dsh-<16 hex>`, derived
|
|
50
|
-
* from the session id and its workspace instead of stored. The same session
|
|
51
|
-
* and workspace always name the same directory — a resumed session
|
|
52
|
-
* re-grants it (the exact-ACE skip keeps that O(1)) — while a fork's
|
|
53
|
-
* different session id names a fresh one. The name is predictable to anyone
|
|
54
|
-
* who knows the session id (the confined command sees it as
|
|
55
|
-
* `DSH_SESSION_ID`), so the provider creates the directory EXCLUSIVELY and
|
|
56
|
-
* rejects reparse points: a pre-placed entry fails the first confined run
|
|
57
|
-
* loudly, and cannot redirect the grant onto a foreign object.
|
|
58
|
-
* @param sessionId - the policy's calling-session identity.
|
|
59
|
-
* @param workspaceRoot - the resolved policy root.
|
|
60
|
-
* @returns the session's private temp subdirectory path.
|
|
61
|
-
*/
|
|
62
|
-
export declare function sessionTempDir(sessionId: SessionId, workspaceRoot: string): string;
|
|
63
49
|
/** Test hook: inject probe verdicts / a fake launcher / a platform without real runners. */
|
|
64
50
|
export interface SandboxInternals {
|
|
65
51
|
/** Replaces `process.platform` for chain selection (exercise any platform's chain from any host). */
|
|
@@ -94,8 +80,9 @@ type SelectedRunner = {
|
|
|
94
80
|
* Local process-sandbox provider. Registers as `ctx.sandbox`. Caches the
|
|
95
81
|
* chain verdict and, on the windows-acl rung, the write grants
|
|
96
82
|
* ({@link AclWriteGrant}: the standing workspace-root grant per workspace
|
|
97
|
-
* and the revocable private-temp grant per session, the
|
|
98
|
-
* provider dispose); the one-time probes spawn nothing
|
|
83
|
+
* and the revocable private-temp grant per live session/workspace pair, the
|
|
84
|
+
* latter revoked on provider dispose); the one-time probes spawn nothing
|
|
85
|
+
* else.
|
|
99
86
|
*/
|
|
100
87
|
export declare class LocalSandboxProvider extends SandboxProvider {
|
|
101
88
|
static Config: z<Config>;
|
|
@@ -110,12 +97,11 @@ export declare class LocalSandboxProvider extends SandboxProvider {
|
|
|
110
97
|
* Server-lifetime write grants (windows-acl rung): the STANDING
|
|
111
98
|
* workspace-root grant per workspace (its ACE is the cross-session reuse
|
|
112
99
|
* cache and outlives the provider — never revoked) and the REVOCABLE
|
|
113
|
-
* private-temp grant per session (revoked on provider
|
|
100
|
+
* private-temp grant per live session/workspace pair (revoked on provider
|
|
101
|
+
* dispose).
|
|
114
102
|
*/
|
|
115
103
|
private readonly workspaceGrants;
|
|
116
|
-
private readonly
|
|
117
|
-
/** Session id → the private temp directory this provider created (removed on dispose). */
|
|
118
|
-
private readonly tempDirs;
|
|
104
|
+
private readonly tempCapabilities;
|
|
119
105
|
constructor(ctx: Context, config: Config);
|
|
120
106
|
/**
|
|
121
107
|
* Wrap `argv` in the selected runner's invocation for `policy` — the configured
|
|
@@ -133,37 +119,29 @@ export declare class LocalSandboxProvider extends SandboxProvider {
|
|
|
133
119
|
private runnerArgv;
|
|
134
120
|
/**
|
|
135
121
|
* The windows-acl runner argv for one policy. With a calling session (the
|
|
136
|
-
* policy's `sessionId`), the
|
|
137
|
-
* lifetime — the standing workspace-root grant per
|
|
138
|
-
* revocable private-temp
|
|
139
|
-
* `--write-sid`
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* temp root and no `--write-sid`: the runner self-manages its DACLs.
|
|
122
|
+
* policy's `sessionId`) under workspace-write, the grants are materialized
|
|
123
|
+
* once per provider lifetime — the standing workspace-root grant per
|
|
124
|
+
* workspace and a revocable, RANDOM private-temp capability per live
|
|
125
|
+
* session/workspace pair. The runner receives `--write-sid` plus
|
|
126
|
+
* `--temp-write-sid` and grants nothing itself. Agentless workspace-write
|
|
127
|
+
* calls pass the ambient temp ROOT and no SID flags: the runner creates and
|
|
128
|
+
* removes a random private child directory for that one invocation.
|
|
144
129
|
* @param policy - the resolved per-call policy.
|
|
145
130
|
* @returns the runner invocation.
|
|
146
131
|
*/
|
|
147
132
|
private windowsAclRunnerArgv;
|
|
148
133
|
/**
|
|
149
|
-
* Materialize
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* never lands on a foreign object); read-only materializes NOTHING — its
|
|
158
|
-
* token alone restricts every write, and the standing grant from an
|
|
159
|
-
* earlier workspace-write period is KEPT through a downgrade (never
|
|
160
|
-
* revoked): the read-only restricted token carries no write SID (the
|
|
161
|
-
* read-only list), so the ACE is inert there, while the map hit keeps the
|
|
162
|
-
* re-upgrade free of re-propagation. Fail-closed: a half-materialized
|
|
163
|
-
* temp grant is revoked before the error propagates.
|
|
134
|
+
* Materialize one workspace-write policy's ACEs once per provider
|
|
135
|
+
* lifetime. The workspace SID and standing root grant are shared by the
|
|
136
|
+
* workspace. The temp directory is random and carries a distinct SID, so
|
|
137
|
+
* another session on the same workspace cannot use the shared workspace
|
|
138
|
+
* SID to enter it. A fresh provider always chooses a new path; crash
|
|
139
|
+
* residue therefore cannot collide with or authorize a resumed session.
|
|
140
|
+
* Fail-closed: a half-materialized temp grant is revoked and its directory
|
|
141
|
+
* removed before the error propagates.
|
|
164
142
|
* @param sessionId - the policy's calling-session identity.
|
|
165
143
|
* @param workspaceRoot - the resolved policy root.
|
|
166
|
-
* @
|
|
144
|
+
* @returns the pair's private temp directory and write capability.
|
|
167
145
|
*/
|
|
168
146
|
private materializeAclGrant;
|
|
169
147
|
/**
|
|
@@ -172,10 +150,12 @@ export declare class LocalSandboxProvider extends SandboxProvider {
|
|
|
172
150
|
* removed, and every SID allocation is freed; the standing workspace ACEs
|
|
173
151
|
* stay (the reuse cache). Cleanup failures are reported, not thrown:
|
|
174
152
|
* cordis teardown must not be aborted by grant cleanup. A crash skips all
|
|
175
|
-
* of it
|
|
176
|
-
* OS temp hygiene (or manual removal)
|
|
153
|
+
* of it, but a new provider never reuses the residue's random path or SID;
|
|
154
|
+
* OS temp hygiene (or manual removal) eventually reclaims it.
|
|
177
155
|
*/
|
|
178
156
|
private revokeAclGrants;
|
|
157
|
+
/** Remove one provider-owned private temp directory (injectable for cleanup tests). */
|
|
158
|
+
private removeTempDir;
|
|
179
159
|
/**
|
|
180
160
|
* Resolve which runner confines commands, once, for the provider's
|
|
181
161
|
* lifetime: this platform's chain ({@link PLATFORM_CHAINS}), its sole
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-sandbox-local",
|
|
3
3
|
"description": "Local process-sandbox backends for the DeepSeek Harness sandbox seam: bwrap, the npm-distributed landlock-run launcher, macOS Seatbelt, or the Windows ACL restricted-token runner — functionally probed, fail-closed",
|
|
4
|
-
"version": "0.0.1-rc.
|
|
4
|
+
"version": "0.0.1-rc.2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "restricted"
|
|
7
7
|
},
|
|
@@ -32,22 +32,22 @@
|
|
|
32
32
|
],
|
|
33
33
|
"license": "BSD-3-Clause",
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@deepseek-ai/dsh-invariants": "^0.0.1-rc.
|
|
36
|
-
"@deepseek-ai/dsh-llm": "^0.0.1-rc.
|
|
37
|
-
"@deepseek-ai/dsh-
|
|
38
|
-
"@deepseek-ai/dsh-
|
|
35
|
+
"@deepseek-ai/dsh-invariants": "^0.0.1-rc.2",
|
|
36
|
+
"@deepseek-ai/dsh-llm": "^0.0.1-rc.2",
|
|
37
|
+
"@deepseek-ai/dsh-session": "^0.0.1-rc.2",
|
|
38
|
+
"@deepseek-ai/dsh-sandbox": "^0.0.1-rc.2",
|
|
39
39
|
"@deepseek-ai/cordis": "^4.0.1-rc.1"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
+
"@deepseek-ai/dsh-sandbox-windows-acl": "^0.0.1-rc.2",
|
|
42
43
|
"@deepseek-ai/node-addon-landlock-run": "0.0.1",
|
|
43
|
-
"@deepseek-ai/schemastery": "^3.18.1-rc.1"
|
|
44
|
-
"@deepseek-ai/dsh-sandbox-windows-acl": "^0.0.1-rc.1"
|
|
44
|
+
"@deepseek-ai/schemastery": "^3.18.1-rc.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@deepseek-ai/dsh-invariants": "^0.0.1-rc.
|
|
48
|
-
"@deepseek-ai/dsh-llm": "^0.0.1-rc.
|
|
49
|
-
"@deepseek-ai/dsh-
|
|
47
|
+
"@deepseek-ai/dsh-invariants": "^0.0.1-rc.2",
|
|
48
|
+
"@deepseek-ai/dsh-llm": "^0.0.1-rc.2",
|
|
49
|
+
"@deepseek-ai/dsh-sandbox": "^0.0.1-rc.2",
|
|
50
50
|
"@deepseek-ai/cordis": "^4.0.1-rc.1",
|
|
51
|
-
"@deepseek-ai/dsh-
|
|
51
|
+
"@deepseek-ai/dsh-session": "^0.0.1-rc.2"
|
|
52
52
|
}
|
|
53
53
|
}
|