@backendkit-labs/agent-sandbox 0.0.0-stage → 0.1.1

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.md CHANGED
@@ -1,3 +1,116 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # @backendkit-labs/agent-sandbox
2
+
3
+ Confinement and permissions for what an agent runs. One policy decides, per call, how much of the host a command may touch; swappable backends enforce it; if the required confinement cannot be enforced on this host, the call **fails** instead of running unconfined.
4
+
5
+ > **Wired into the coding engine.** `createCodingEngine({ sandbox: { preset: 'ask' } })` (agent-coding) or `createBaseEngine({ sandbox })` (agent-core) put every `run_command` behind this service. Without `sandbox`, `run_command` keeps its old behaviour: the host, or the deprecated `BK_RUN_COMMAND_SANDBOX=docker`, now translated to the equivalent policy of this package.
6
+
7
+ ```bash
8
+ npm i @backendkit-labs/agent-sandbox
9
+ ```
10
+
11
+ ## Modes
12
+
13
+ | Mode | Meaning |
14
+ |---|---|
15
+ | `read-only` | nothing can be written, anywhere |
16
+ | `workspace-write` | writes only inside the workspace |
17
+ | `danger-full-access` | no confinement |
18
+
19
+ Each call also has a network setting: `none` (default for the first two modes) or `allow`.
20
+
21
+ ## Fail closed
22
+
23
+ ```ts
24
+ import { createSandboxPolicy, createSandboxService, DockerBackend, NoneBackend } from '@backendkit-labs/agent-sandbox';
25
+
26
+ const sandbox = createSandboxService({
27
+ policy: createSandboxPolicy({ preset: 'ask' }), // workspace-write, network none
28
+ backends: [new DockerBackend({ image: 'node:22' }), new NoneBackend()],
29
+ });
30
+
31
+ const out = await sandbox.run({ agentId: 'coder', sessionId: 's1' }, { tool: 'run_command', command: 'npm test', cwd: dir });
32
+ if (!out.ok) {
33
+ out.code; // 'SANDBOX_DENIED' | 'SANDBOX_UNAVAILABLE'
34
+ out.reason; // why, and which backend was skipped for what reason
35
+ }
36
+ ```
37
+
38
+ The service picks the first backend that can really **enforce** the mode:
39
+
40
+ - `docker` enforces `read-only` and `workspace-write` (never `danger-full-access`: a container is not full access). If the daemon does not answer you get `SANDBOX_UNAVAILABLE`, not a run on the host.
41
+ - `none` (the host) claims only `danger-full-access` with the network open. Checking that a directory is inside the workspace is not confinement, so it does not claim anything stricter.
42
+
43
+ ## Presets
44
+
45
+ | Preset | Mode | Needs a human for |
46
+ |---|---|---|
47
+ | `read-only` | `read-only` | nothing (nothing writes) |
48
+ | `ask` (default) | `workspace-write` | file writes and commands |
49
+ | `auto-edit` | `workspace-write` | commands |
50
+ | `full` | `danger-full-access` | nothing |
51
+
52
+ `auto-edit` differs from the SPEC-0006 table: the command allowlist of `run_command` is still a hard block, so "auto-edit" means edits run and every command asks. `needsApproval(level, kind)` and `matchPreset(mode, approval)` are exported; a combination that matches no preset is reported as `custom`.
53
+
54
+ ## The policy is data
55
+
56
+ `SandboxPolicyConfig` is plain JSON, so it can come from a file or a control request:
57
+
58
+ ```ts
59
+ const policy = createSandboxPolicy({
60
+ preset: 'ask',
61
+ roots: ['/data/shared'], // extra working directories besides the workspace
62
+ rules: [ // the first match wins
63
+ { agentId: 'reviewer', mode: 'read-only' },
64
+ { tool: 'run_command', network: 'allow' },
65
+ ],
66
+ env: { allow: ['GH_TOKEN'] },
67
+ writeTools: ['write_file', 'edit_file'], // refused outright while read-only
68
+ });
69
+
70
+ policy.snapshot(); // a copy of the configuration
71
+ policy.set(newConfig); // validated; takes effect on the NEXT call, never mid-call; throws and keeps the old one if invalid
72
+ policy.version; // increments on every successful set
73
+ parsePolicyConfig(untrusted); // validates a YAML/JSON object and names the path of the problem
74
+ ```
75
+
76
+ ## In an engine
77
+
78
+ ```ts
79
+ const engine = createCodingEngine({
80
+ providers, defaultProvider: 'deepseek', transport,
81
+ sandbox: { preset: 'ask' }, // or { preset: 'read-only' | 'auto-edit' | 'full', policy: {...}, backends: ['docker', 'none'], docker: { image: 'node:22' }, auditLog: 'logs/sandbox.ndjson' }
82
+ onToolApproval, // the preset says WHICH tools ask; this is who answers
83
+ });
84
+ (engine.sandbox as SandboxService).policy.set({ preset: 'read-only' }); // takes effect on the next call
85
+ ```
86
+
87
+ - `run_command` goes through the service; an unmet confinement comes back as `Error: SANDBOX_UNAVAILABLE: …` and nothing runs.
88
+ - In `read-only` the engine refuses the write tools by name (`write_file`, `edit_file`), whatever the approval gate says. The memory tools keep working: they write the agent's own store, outside the workspace.
89
+ - The preset replaces the engine's built-in list of tools that ask. **If a tool needs approval and no `onToolApproval` is set, it is refused** (`SANDBOX_DENIED`): an unattended flow, trigger or fleet agent can never run what nobody approved.
90
+ - Every decision is a `sandbox` event on the transport and a line in the engine's audit log.
91
+ - File tools (`write_file`, `edit_file`) still enforce the workspace with their own path check; moving them behind the service is the next delivery.
92
+ - Containers run as your uid:gid on Linux and macOS (not root), so the files they create are yours.
93
+
94
+ ## Observability
95
+
96
+ Every decision (allowed, denied, unavailable) is structured:
97
+
98
+ ```ts
99
+ sandbox.onDecision(d => console.log(d.agentId, d.tool, d.mode, d.backend, d.outcome, d.reason));
100
+ createSandboxService({ policy, backends, auditLog: 'logs/sandbox.ndjson' }); // one JSON line per decision, in order
101
+ ```
102
+
103
+ ## Environment hygiene
104
+
105
+ Host processes start from a scrubbed environment: names matching `KEY`, `SECRET`, `TOKEN`, `PASSWORD`, `PASSWD` or `CREDENTIAL` (case-insensitive) are dropped. It is a denylist on purpose (Windows needs `SystemRoot`, `ComSpec`, `PATHEXT`). Let specific ones through with `env.allow` (`GH_TOKEN`, or `DEEPSEEK_*`), drop more with `env.deny`. Containers never inherit the host environment.
106
+
107
+ ## What it does not confine
108
+
109
+ - **Tools that start processes on their own.** Only calls that go through `ctx.sandbox.run(...)` are confined (`run_command` does). A custom or MCP tool that spawns a process itself is outside the sandbox: write it against `ctx.sandbox`.
110
+ - **`read-only` refuses tools by name.** It refuses exactly the tools listed in `writeTools` (the coding set lists `write_file` and `edit_file`). MCP tools and your own tools that write are not blocked unless you list them.
111
+ - **File tools run in the host process**, so they are not confined by a backend: the service judges the path instead (`authorizePath`). It follows symlinks and junctions, so a link inside the workspace cannot reach outside; the tool's own workspace check stays as the floor, even in full access. A tool that does its own I/O must call `ctx.sandbox.authorizePath(...)` itself.
112
+ - **Several engines may share one service**: each engine reports only the decisions of its own calls on its transport and audit log. `sandbox.onDecision(...)` on the service sees all of them.
113
+
114
+ ## Not here yet
115
+
116
+ `request_escalation` (S2), a terminal tool through the service (there is none in this repo yet), `bwrap`/`landlock`, Windows and `ssh` backends (S4), private temp directories and waiting for child exit after a kill.
@@ -0,0 +1,56 @@
1
+ import type { SandboxMode, SandboxNetwork } from '@backendkit-labs/agent-core';
2
+ import type { BackendExecRequest, SandboxBackend } from './types';
3
+ export interface DockerBackendOptions {
4
+ /** Docker CLI to call. Default `docker`. */
5
+ bin?: string;
6
+ /** Image the command runs in; it must ship the tools the command needs. Default `node:22`. */
7
+ image?: string;
8
+ /** Memory limit. Default `2g`. */
9
+ memory?: string;
10
+ /** Process limit. Default 512. */
11
+ pidsLimit?: number;
12
+ /**
13
+ * User the command runs as inside the container (`uid:gid`). Default on POSIX: the uid and gid of this process,
14
+ * so the command is not root and the files it creates belong to you. With all capabilities dropped, a root
15
+ * container cannot touch host files owned by another user, which is the usual case on Linux. Pass `false`
16
+ * to leave the image's default user. On Windows there is no uid and nothing is passed.
17
+ */
18
+ user?: string | false;
19
+ /** Replace the availability probe (tests, or an already known state). */
20
+ probe?: () => Promise<boolean>;
21
+ /** How long a negative probe result is trusted before asking the daemon again. Default 5 s. */
22
+ negativeTtlMs?: number;
23
+ }
24
+ /**
25
+ * Arguments of `docker run` for one confined command: all capabilities dropped, no new privileges,
26
+ * memory and process limits, only the workspace mounted (read-only in `read-only` mode).
27
+ */
28
+ export declare function buildDockerArgs(name: string, req: Pick<BackendExecRequest, 'command' | 'cwd' | 'workspace' | 'mode' | 'network'>, opts: {
29
+ image: string;
30
+ memory: string;
31
+ pidsLimit: number;
32
+ user?: string;
33
+ }): string[];
34
+ /**
35
+ * Container confinement. `read-only` mounts the workspace read-only (and the container root); `workspace-write`
36
+ * writes only inside the workspace; the network is `none` unless the policy allows it. It never claims
37
+ * `danger-full-access` (a container is not full access), and when the daemon does not answer the service
38
+ * reports SANDBOX_UNAVAILABLE instead of running on the host.
39
+ */
40
+ export declare class DockerBackend implements SandboxBackend {
41
+ readonly name = "docker";
42
+ private readonly bin;
43
+ private readonly image;
44
+ private readonly memory;
45
+ private readonly pidsLimit;
46
+ private readonly user;
47
+ private readonly probe;
48
+ private readonly negativeTtlMs;
49
+ private cached?;
50
+ constructor(opts?: DockerBackendOptions);
51
+ supports(mode: SandboxMode, _network: SandboxNetwork): boolean;
52
+ available(): Promise<boolean>;
53
+ unavailableReason(): string;
54
+ exec(req: BackendExecRequest): Promise<import("@backendkit-labs/agent-core").SandboxExecResult>;
55
+ }
56
+ //# sourceMappingURL=docker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docker.d.ts","sourceRoot":"","sources":["../../src/backends/docker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAElE,MAAM,WAAW,oBAAoB;IACjC,4CAA4C;IAC5C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,8FAA8F;IAC9F,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kCAAkC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACtB,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/B,+FAA+F;IAC/F,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAeD;;;GAGG;AACH,wBAAgB,eAAe,CAC3B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,IAAI,CAAC,kBAAkB,EAAE,SAAS,GAAG,KAAK,GAAG,WAAW,GAAG,MAAM,GAAG,SAAS,CAAC,EACnF,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1E,MAAM,EAAE,CAiBV;AAED;;;;;GAKG;AACH,qBAAa,aAAc,YAAW,cAAc;IAChD,QAAQ,CAAC,IAAI,YAAY;IACzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqB;IAC1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyB;IAC/C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,MAAM,CAAC,CAA8B;gBAEjC,IAAI,GAAE,oBAAyB;IAW3C,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO;IAIxD,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAQnC,iBAAiB,IAAI,MAAM;IAI3B,IAAI,CAAC,GAAG,EAAE,kBAAkB;CAW/B"}
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.DockerBackend = void 0;
37
+ exports.buildDockerArgs = buildDockerArgs;
38
+ const child_process_1 = require("child_process");
39
+ const path = __importStar(require("path"));
40
+ const process_1 = require("../process");
41
+ function defaultProbe(bin) {
42
+ return new Promise(resolve => {
43
+ let done = false;
44
+ const finish = (ok) => { if (!done) {
45
+ done = true;
46
+ clearTimeout(timer);
47
+ resolve(ok);
48
+ } };
49
+ let proc;
50
+ try {
51
+ proc = (0, child_process_1.spawn)(bin, ['version', '--format', '{{.Server.Version}}'], { stdio: 'ignore' });
52
+ }
53
+ catch {
54
+ resolve(false);
55
+ return;
56
+ }
57
+ const timer = setTimeout(() => { try {
58
+ proc.kill();
59
+ }
60
+ catch { /* gone */ } finish(false); }, 4000);
61
+ proc.on('error', () => finish(false));
62
+ proc.on('close', code => finish(code === 0));
63
+ });
64
+ }
65
+ /**
66
+ * Arguments of `docker run` for one confined command: all capabilities dropped, no new privileges,
67
+ * memory and process limits, only the workspace mounted (read-only in `read-only` mode).
68
+ */
69
+ function buildDockerArgs(name, req, opts) {
70
+ const rel = path.relative(req.workspace, req.cwd).split(path.sep).join('/');
71
+ const readOnly = req.mode === 'read-only';
72
+ return [
73
+ 'run', '--rm', '--name', name,
74
+ '--network', req.network === 'none' ? 'none' : 'bridge',
75
+ '--cap-drop', 'ALL',
76
+ '--security-opt', 'no-new-privileges',
77
+ '--memory', opts.memory,
78
+ '--pids-limit', String(opts.pidsLimit),
79
+ ...(opts.user ? ['--user', opts.user] : []),
80
+ ...(readOnly ? ['--read-only', '--tmpfs', '/tmp'] : []),
81
+ '-v', `${req.workspace}:/workspace${readOnly ? ':ro' : ''}`,
82
+ '-w', rel ? `/workspace/${rel}` : '/workspace',
83
+ opts.image,
84
+ 'sh', '-c', req.command,
85
+ ];
86
+ }
87
+ /**
88
+ * Container confinement. `read-only` mounts the workspace read-only (and the container root); `workspace-write`
89
+ * writes only inside the workspace; the network is `none` unless the policy allows it. It never claims
90
+ * `danger-full-access` (a container is not full access), and when the daemon does not answer the service
91
+ * reports SANDBOX_UNAVAILABLE instead of running on the host.
92
+ */
93
+ class DockerBackend {
94
+ name = 'docker';
95
+ bin;
96
+ image;
97
+ memory;
98
+ pidsLimit;
99
+ user;
100
+ probe;
101
+ negativeTtlMs;
102
+ cached;
103
+ constructor(opts = {}) {
104
+ this.bin = opts.bin ?? 'docker';
105
+ this.image = opts.image ?? 'node:22';
106
+ this.memory = opts.memory ?? '2g';
107
+ this.pidsLimit = opts.pidsLimit ?? 512;
108
+ this.user = opts.user === false ? undefined
109
+ : opts.user ?? (typeof process.getuid === 'function' && typeof process.getgid === 'function' ? `${process.getuid()}:${process.getgid()}` : undefined);
110
+ this.probe = opts.probe ?? (() => defaultProbe(this.bin));
111
+ this.negativeTtlMs = opts.negativeTtlMs ?? 5000;
112
+ }
113
+ supports(mode, _network) {
114
+ return mode === 'read-only' || mode === 'workspace-write';
115
+ }
116
+ async available() {
117
+ const now = Date.now();
118
+ if (this.cached && (this.cached.ok || now - this.cached.at < this.negativeTtlMs))
119
+ return this.cached.ok;
120
+ const ok = await this.probe().catch(() => false);
121
+ this.cached = { ok, at: now };
122
+ return ok;
123
+ }
124
+ unavailableReason() {
125
+ return `the docker daemon is not reachable ("${this.bin} version" failed)`;
126
+ }
127
+ exec(req) {
128
+ const name = `bk-run-${process.pid}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
129
+ const proc = (0, child_process_1.spawn)(this.bin, buildDockerArgs(name, req, { image: this.image, memory: this.memory, pidsLimit: this.pidsLimit, user: this.user }));
130
+ return (0, process_1.runProcess)(proc, {
131
+ timeoutMs: req.timeoutMs, signal: req.signal, onOutput: req.onOutput,
132
+ kill: (p) => {
133
+ (0, child_process_1.spawn)(this.bin, ['kill', name], { stdio: 'ignore' }).on('error', () => undefined);
134
+ (0, process_1.killProcessTree)(p);
135
+ },
136
+ });
137
+ }
138
+ }
139
+ exports.DockerBackend = DockerBackend;
140
+ //# sourceMappingURL=docker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docker.js","sourceRoot":"","sources":["../../src/backends/docker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,0CAqBC;AAlED,iDAAyD;AACzD,2CAA6B;AAE7B,wCAAyD;AAyBzD,SAAS,YAAY,CAAC,GAAW;IAC7B,OAAO,IAAI,OAAO,CAAU,OAAO,CAAC,EAAE;QAClC,IAAI,IAAI,GAAG,KAAK,CAAC;QACjB,MAAM,MAAM,GAAG,CAAC,EAAW,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YAAC,IAAI,GAAG,IAAI,CAAC;YAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAAC,CAAC,CAAC,CAAC,CAAC;QAClG,IAAI,IAAkB,CAAC;QACvB,IAAI,CAAC;YAAC,IAAI,GAAG,IAAA,qBAAK,EAAC,GAAG,EAAE,CAAC,S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AC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QAC1G,MAAM,IAAI,GAAG,IAAA,qBAAK,EAAC,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACjJ,OAAO,IAAA,oBAAU,EAAC,IAAI,EAAE;YACpB,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACpE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE;gBACR,IAAA,qBAAK,EAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;gBAClF,IAAA,yBAAe,EAAC,CAAC,CAAC,CAAC;YACvB,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;CACJ;AAjDD,sCAiDC"}
@@ -0,0 +1,13 @@
1
+ import type { SandboxMode, SandboxNetwork } from '@backendkit-labs/agent-core';
2
+ import type { BackendExecRequest, SandboxBackend } from './types';
3
+ /**
4
+ * Runs on the host with no confinement. It therefore claims exactly one thing: `danger-full-access`
5
+ * with the network open. Anything stricter makes the service look for another backend, or fail.
6
+ */
7
+ export declare class NoneBackend implements SandboxBackend {
8
+ readonly name = "none";
9
+ supports(mode: SandboxMode, network: SandboxNetwork): boolean;
10
+ available(): Promise<boolean>;
11
+ exec(req: BackendExecRequest): Promise<import("@backendkit-labs/agent-core").SandboxExecResult>;
12
+ }
13
+ //# sourceMappingURL=none.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"none.d.ts","sourceRoot":"","sources":["../../src/backends/none.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAElE;;;GAGG;AACH,qBAAa,WAAY,YAAW,cAAc;IAC9C,QAAQ,CAAC,IAAI,UAAU;IAEvB,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO;IAIvD,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAEnC,IAAI,CAAC,GAAG,EAAE,kBAAkB;CAU/B"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoneBackend = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const process_1 = require("../process");
6
+ /**
7
+ * Runs on the host with no confinement. It therefore claims exactly one thing: `danger-full-access`
8
+ * with the network open. Anything stricter makes the service look for another backend, or fail.
9
+ */
10
+ class NoneBackend {
11
+ name = 'none';
12
+ supports(mode, network) {
13
+ return mode === 'danger-full-access' && network === 'allow';
14
+ }
15
+ async available() { return true; }
16
+ exec(req) {
17
+ const proc = (0, child_process_1.spawn)(req.hostCommand ?? req.command, {
18
+ shell: true,
19
+ cwd: req.cwd,
20
+ env: req.env,
21
+ // Own process group on POSIX, so the whole tree can be signalled.
22
+ detached: process.platform !== 'win32',
23
+ });
24
+ return (0, process_1.runProcess)(proc, { timeoutMs: req.timeoutMs, signal: req.signal, onOutput: req.onOutput });
25
+ }
26
+ }
27
+ exports.NoneBackend = NoneBackend;
28
+ //# sourceMappingURL=none.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"none.js","sourceRoot":"","sources":["../../src/backends/none.ts"],"names":[],"mappings":";;;AAAA,iDAAsC;AAEtC,wCAAwC;AAGxC;;;GAGG;AACH,MAAa,WAAW;IACX,IAAI,GAAG,MAAM,CAAC;IAEvB,QAAQ,CAAC,IAAiB,EAAE,OAAuB;QAC/C,OAAO,IAAI,KAAK,oBAAoB,IAAI,OAAO,KAAK,OAAO,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,SAAS,KAAuB,OAAO,IAAI,CAAC,CAAC,CAAC;IAEpD,IAAI,CAAC,GAAuB;QACxB,MAAM,IAAI,GAAG,IAAA,qBAAK,EAAC,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,OAAO,EAAE;YAC/C,KAAK,EAAE,IAAI;YACX,GAAG,EAAE,GAAG,CAAC,GAAG;YACZ,GAAG,EAAE,GAAG,CAAC,GAAG;YACZ,kEAAkE;YAClE,QAAQ,EAAE,OAAO,CAAC,QAAQ,KAAK,OAAO;SACzC,CAAC,CAAC;QACH,OAAO,IAAA,oBAAU,EAAC,IAAI,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IACtG,CAAC;CACJ;AAnBD,kCAmBC"}
@@ -0,0 +1,32 @@
1
+ import type { SandboxExecResult, SandboxMode, SandboxNetwork } from '@backendkit-labs/agent-core';
2
+ export interface BackendExecRequest {
3
+ /** Portable command line. */
4
+ command: string;
5
+ /** Command line adjusted for the host shell, for backends that run on the host. */
6
+ hostCommand?: string;
7
+ cwd: string;
8
+ /** Directory exposed to the command (mounted by container backends). */
9
+ workspace: string;
10
+ mode: SandboxMode;
11
+ network: SandboxNetwork;
12
+ /** Environment for backends that run on the host (already scrubbed). */
13
+ env: Record<string, string>;
14
+ timeoutMs?: number;
15
+ signal?: AbortSignal;
16
+ onOutput?: (chunk: string) => void;
17
+ }
18
+ /** Something that can run a command with a given confinement. */
19
+ export interface SandboxBackend {
20
+ readonly name: string;
21
+ /**
22
+ * Can this backend ENFORCE `mode` with `network`? Honest answers only: checking that a path is inside
23
+ * the workspace is not confinement, so a host backend must not claim `workspace-write`.
24
+ */
25
+ supports(mode: SandboxMode, network: SandboxNetwork): boolean;
26
+ /** Is the backend usable on this host right now (e.g. the docker daemon answers)? */
27
+ available(): Promise<boolean>;
28
+ /** Why `available()` is false, for the error shown to the operator. */
29
+ unavailableReason?(): string;
30
+ exec(req: BackendExecRequest): Promise<SandboxExecResult>;
31
+ }
32
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/backends/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElG,MAAM,WAAW,kBAAkB;IAC/B,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,wEAAwE;IACxE,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,cAAc,CAAC;IACxB,wEAAwE;IACxE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACtC;AAED,iEAAiE;AACjE,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC;IAC9D,qFAAqF;IACrF,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,uEAAuE;IACvE,iBAAiB,CAAC,IAAI,MAAM,CAAC;IAC7B,IAAI,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC7D"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/backends/types.ts"],"names":[],"mappings":""}
package/dist/env.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Environment hygiene for confined processes: variables that look like credentials are not handed down.
3
+ * A case-insensitive denylist by name pattern, never an allowlist-only filter (cmd.exe needs SystemRoot,
4
+ * ComSpec and PATHEXT, and most tools need PATH/HOME-like variables).
5
+ */
6
+ export interface EnvPolicy {
7
+ /** Names (exact, or with `*` as wildcard) that are passed even if they look like credentials, e.g. `GH_TOKEN`. */
8
+ allow?: string[];
9
+ /** Extra names (exact, or with `*`) to drop on top of the default patterns. */
10
+ deny?: string[];
11
+ }
12
+ /** The variables of `env` a confined process may see. Undefined values are dropped. */
13
+ export declare function scrubEnv(env: Record<string, string | undefined>, policy?: EnvPolicy): Record<string, string>;
14
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,WAAW,SAAS;IACtB,kHAAkH;IAClH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,+EAA+E;IAC/E,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAQD,uFAAuF;AACvF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EAAE,MAAM,GAAE,SAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAWhH"}
package/dist/env.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /**
3
+ * Environment hygiene for confined processes: variables that look like credentials are not handed down.
4
+ * A case-insensitive denylist by name pattern, never an allowlist-only filter (cmd.exe needs SystemRoot,
5
+ * ComSpec and PATHEXT, and most tools need PATH/HOME-like variables).
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.scrubEnv = scrubEnv;
9
+ const DEFAULT_DENY = /KEY|SECRET|TOKEN|PASSWORD|PASSWD|CREDENTIAL/i;
10
+ function matcher(patterns) {
11
+ const regexes = (patterns ?? []).map(p => new RegExp('^' + p.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*') + '$', 'i'));
12
+ return name => regexes.some(r => r.test(name));
13
+ }
14
+ /** The variables of `env` a confined process may see. Undefined values are dropped. */
15
+ function scrubEnv(env, policy = {}) {
16
+ const allowed = matcher(policy.allow);
17
+ const denied = matcher(policy.deny);
18
+ const out = {};
19
+ for (const [name, value] of Object.entries(env)) {
20
+ if (value === undefined)
21
+ continue;
22
+ if (allowed(name)) {
23
+ out[name] = value;
24
+ continue;
25
+ }
26
+ if (denied(name) || DEFAULT_DENY.test(name))
27
+ continue;
28
+ out[name] = value;
29
+ }
30
+ return out;
31
+ }
32
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAkBH,4BAWC;AA3BD,MAAM,YAAY,GAAG,8CAA8C,CAAC;AASpE,SAAS,OAAO,CAAC,QAA8B;IAC3C,MAAM,OAAO,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CACrC,IAAI,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAC/F,OAAO,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,uFAAuF;AACvF,SAAgB,QAAQ,CAAC,GAAuC,EAAE,SAAoB,EAAE;IACpF,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9C,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAAC,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;YAAC,SAAS;QAAC,CAAC;QACnD,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,SAAS;QACtD,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC"}
@@ -0,0 +1,16 @@
1
+ export { createSandboxService } from './service';
2
+ export type { SandboxService, SandboxServiceOptions, DecisionListener } from './service';
3
+ export { createSandboxPolicy, parsePolicyConfig, SandboxPolicyError } from './policy';
4
+ export type { SandboxPolicy, SandboxPolicyConfig, SandboxRule, ResolvedPolicy } from './policy';
5
+ export { PERMISSION_PRESETS, isPermissionPreset, matchPreset, needsApproval } from './presets';
6
+ export type { PermissionPreset, PresetDefinition, ApprovalLevel, ActionKind } from './presets';
7
+ export { realPathOf, isInside as isInsideDir } from './paths';
8
+ export { scrubEnv } from './env';
9
+ export type { EnvPolicy } from './env';
10
+ export { NoneBackend } from './backends/none';
11
+ export { DockerBackend, buildDockerArgs } from './backends/docker';
12
+ export type { DockerBackendOptions } from './backends/docker';
13
+ export type { SandboxBackend, BackendExecRequest } from './backends/types';
14
+ export { runProcess, killProcessTree, DEFAULT_MAX_OUTPUT_CHARS } from './process';
15
+ export type { RunProcessOptions } from './process';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACtF,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/F,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/F,OAAO,EAAE,UAAU,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACnE,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAClF,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_MAX_OUTPUT_CHARS = exports.killProcessTree = exports.runProcess = exports.buildDockerArgs = exports.DockerBackend = exports.NoneBackend = exports.scrubEnv = exports.isInsideDir = exports.realPathOf = exports.needsApproval = exports.matchPreset = exports.isPermissionPreset = exports.PERMISSION_PRESETS = exports.SandboxPolicyError = exports.parsePolicyConfig = exports.createSandboxPolicy = exports.createSandboxService = void 0;
4
+ var service_1 = require("./service");
5
+ Object.defineProperty(exports, "createSandboxService", { enumerable: true, get: function () { return service_1.createSandboxService; } });
6
+ var policy_1 = require("./policy");
7
+ Object.defineProperty(exports, "createSandboxPolicy", { enumerable: true, get: function () { return policy_1.createSandboxPolicy; } });
8
+ Object.defineProperty(exports, "parsePolicyConfig", { enumerable: true, get: function () { return policy_1.parsePolicyConfig; } });
9
+ Object.defineProperty(exports, "SandboxPolicyError", { enumerable: true, get: function () { return policy_1.SandboxPolicyError; } });
10
+ var presets_1 = require("./presets");
11
+ Object.defineProperty(exports, "PERMISSION_PRESETS", { enumerable: true, get: function () { return presets_1.PERMISSION_PRESETS; } });
12
+ Object.defineProperty(exports, "isPermissionPreset", { enumerable: true, get: function () { return presets_1.isPermissionPreset; } });
13
+ Object.defineProperty(exports, "matchPreset", { enumerable: true, get: function () { return presets_1.matchPreset; } });
14
+ Object.defineProperty(exports, "needsApproval", { enumerable: true, get: function () { return presets_1.needsApproval; } });
15
+ var paths_1 = require("./paths");
16
+ Object.defineProperty(exports, "realPathOf", { enumerable: true, get: function () { return paths_1.realPathOf; } });
17
+ Object.defineProperty(exports, "isInsideDir", { enumerable: true, get: function () { return paths_1.isInside; } });
18
+ var env_1 = require("./env");
19
+ Object.defineProperty(exports, "scrubEnv", { enumerable: true, get: function () { return env_1.scrubEnv; } });
20
+ var none_1 = require("./backends/none");
21
+ Object.defineProperty(exports, "NoneBackend", { enumerable: true, get: function () { return none_1.NoneBackend; } });
22
+ var docker_1 = require("./backends/docker");
23
+ Object.defineProperty(exports, "DockerBackend", { enumerable: true, get: function () { return docker_1.DockerBackend; } });
24
+ Object.defineProperty(exports, "buildDockerArgs", { enumerable: true, get: function () { return docker_1.buildDockerArgs; } });
25
+ var process_1 = require("./process");
26
+ Object.defineProperty(exports, "runProcess", { enumerable: true, get: function () { return process_1.runProcess; } });
27
+ Object.defineProperty(exports, "killProcessTree", { enumerable: true, get: function () { return process_1.killProcessTree; } });
28
+ Object.defineProperty(exports, "DEFAULT_MAX_OUTPUT_CHARS", { enumerable: true, get: function () { return process_1.DEFAULT_MAX_OUTPUT_CHARS; } });
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAiD;AAAxC,+GAAA,oBAAoB,OAAA;AAE7B,mCAAsF;AAA7E,6GAAA,mBAAmB,OAAA;AAAE,2GAAA,iBAAiB,OAAA;AAAE,4GAAA,kBAAkB,OAAA;AAEnE,qCAA+F;AAAtF,6GAAA,kBAAkB,OAAA;AAAE,6GAAA,kBAAkB,OAAA;AAAE,sGAAA,WAAW,OAAA;AAAE,wGAAA,aAAa,OAAA;AAE3E,iCAA8D;AAArD,mGAAA,UAAU,OAAA;AAAE,oGAAA,QAAQ,OAAe;AAC5C,6BAAiC;AAAxB,+FAAA,QAAQ,OAAA;AAEjB,wCAA8C;AAArC,mGAAA,WAAW,OAAA;AACpB,4CAAmE;AAA1D,uGAAA,aAAa,OAAA;AAAE,yGAAA,eAAe,OAAA;AAGvC,qCAAkF;AAAzE,qGAAA,UAAU,OAAA;AAAE,0GAAA,eAAe,OAAA;AAAE,mHAAA,wBAAwB,OAAA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Where `target` really points, symlinks and junctions followed, even when the file (or some of its parent
3
+ * directories) does not exist yet: the nearest existing ancestor is resolved and the missing tail appended.
4
+ * A dangling link on the way is followed to where it WOULD land, so it cannot be used to write outside.
5
+ */
6
+ export declare function realPathOf(target: string, hops?: number): string;
7
+ /** Normalised containment test; case-insensitive on Windows, separator-agnostic. */
8
+ export declare function isInside(root: string, target: string): boolean;
9
+ //# sourceMappingURL=paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,SAAI,GAAG,MAAM,CAkB3D;AAED,oFAAoF;AACpF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAQ9D"}
package/dist/paths.js ADDED
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.realPathOf = realPathOf;
4
+ exports.isInside = isInside;
5
+ const fs_1 = require("fs");
6
+ const path_1 = require("path");
7
+ const MAX_LINK_HOPS = 40;
8
+ /**
9
+ * Where `target` really points, symlinks and junctions followed, even when the file (or some of its parent
10
+ * directories) does not exist yet: the nearest existing ancestor is resolved and the missing tail appended.
11
+ * A dangling link on the way is followed to where it WOULD land, so it cannot be used to write outside.
12
+ */
13
+ function realPathOf(target, hops = 0) {
14
+ const abs = (0, path_1.resolve)(target);
15
+ if (hops > MAX_LINK_HOPS)
16
+ throw new Error(`too many symbolic links resolving "${target}"`);
17
+ try {
18
+ return fs_1.realpathSync.native(abs);
19
+ }
20
+ catch { /* it, or an ancestor, does not exist: handled below */ }
21
+ let isLink = false;
22
+ try {
23
+ isLink = (0, fs_1.lstatSync)(abs).isSymbolicLink();
24
+ }
25
+ catch { /* not there at all */ }
26
+ if (isLink) {
27
+ // Exists as a link but its target does not: follow it to where it would land.
28
+ const dest = (0, fs_1.readlinkSync)(abs);
29
+ return realPathOf((0, path_1.isAbsolute)(dest) ? dest : (0, path_1.join)((0, path_1.dirname)(abs), dest), hops + 1);
30
+ }
31
+ const parent = (0, path_1.dirname)(abs);
32
+ if (parent === abs)
33
+ return abs;
34
+ return (0, path_1.join)(realPathOf(parent, hops + 1), (0, path_1.basename)(abs));
35
+ }
36
+ /** Normalised containment test; case-insensitive on Windows, separator-agnostic. */
37
+ function isInside(root, target) {
38
+ const norm = (p) => {
39
+ const s = (0, path_1.resolve)(p).replace(/\\/g, '/');
40
+ return process.platform === 'win32' ? s.toLowerCase() : s;
41
+ };
42
+ const r = norm(root);
43
+ const t = norm(target);
44
+ return t === r || t.startsWith(r.endsWith('/') ? r : r + '/');
45
+ }
46
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":";;AAUA,gCAkBC;AAGD,4BAQC;AAvCD,2BAA2D;AAC3D,+BAAoE;AAEpE,MAAM,aAAa,GAAG,EAAE,CAAC;AAEzB;;;;GAIG;AACH,SAAgB,UAAU,CAAC,MAAc,EAAE,IAAI,GAAG,CAAC;IAC/C,MAAM,GAAG,GAAG,IAAA,cAAO,EAAC,MAAM,CAAC,CAAC;IAC5B,IAAI,IAAI,GAAG,aAAa;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,MAAM,GAAG,CAAC,CAAC;IAC3F,IAAI,CAAC;QACD,OAAO,iBAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC,CAAC,uDAAuD,CAAC,CAAC;IAEnE,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,CAAC;QAAC,MAAM,GAAG,IAAA,cAAS,EAAC,GAAG,CAAC,CAAC,cAAc,EAAE,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC,CAAC,sBAAsB,CAAC,CAAC;IAClF,IAAI,MAAM,EAAE,CAAC;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