@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 +116 -3
- package/dist/backends/docker.d.ts +56 -0
- package/dist/backends/docker.d.ts.map +1 -0
- package/dist/backends/docker.js +140 -0
- package/dist/backends/docker.js.map +1 -0
- package/dist/backends/none.d.ts +13 -0
- package/dist/backends/none.d.ts.map +1 -0
- package/dist/backends/none.js +28 -0
- package/dist/backends/none.js.map +1 -0
- package/dist/backends/types.d.ts +32 -0
- package/dist/backends/types.d.ts.map +1 -0
- package/dist/backends/types.js +3 -0
- package/dist/backends/types.js.map +1 -0
- package/dist/env.d.ts +14 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +32 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/paths.d.ts +9 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +46 -0
- package/dist/paths.js.map +1 -0
- package/dist/policy.d.ts +65 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +116 -0
- package/dist/policy.js.map +1 -0
- package/dist/presets.d.ts +27 -0
- package/dist/presets.d.ts.map +1 -0
- package/dist/presets.js +37 -0
- package/dist/presets.js.map +1 -0
- package/dist/process.d.ts +24 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +77 -0
- package/dist/process.js.map +1 -0
- package/dist/service.d.ts +25 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +131 -0
- package/dist/service.js.map +1 -0
- package/package.json +46 -6
package/dist/policy.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { SandboxCaller, SandboxMode, SandboxNetwork } from '@backendkit-labs/agent-core';
|
|
2
|
+
import type { EnvPolicy } from './env';
|
|
3
|
+
import { type ApprovalLevel, type PermissionPreset } from './presets';
|
|
4
|
+
/** A more specific setting for one agent and/or one tool. The first rule that matches wins. */
|
|
5
|
+
export interface SandboxRule {
|
|
6
|
+
agentId?: string;
|
|
7
|
+
tool?: string;
|
|
8
|
+
mode?: SandboxMode;
|
|
9
|
+
network?: SandboxNetwork;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The whole policy as plain JSON, so it can live in a file (`fleet.yaml`), travel in a control request
|
|
13
|
+
* and be shown back (`snapshot()`).
|
|
14
|
+
*/
|
|
15
|
+
export interface SandboxPolicyConfig {
|
|
16
|
+
/** Starting point for `mode` and `approval`. Default `ask`. */
|
|
17
|
+
preset?: PermissionPreset;
|
|
18
|
+
/** Overrides the preset's mode. */
|
|
19
|
+
mode?: SandboxMode;
|
|
20
|
+
/** Overrides the preset's approval level. */
|
|
21
|
+
approval?: ApprovalLevel;
|
|
22
|
+
/** Default: `none` for `read-only` and `workspace-write`, `allow` for `danger-full-access`. */
|
|
23
|
+
network?: SandboxNetwork;
|
|
24
|
+
/** Extra directories (besides the call's workspace) a confined command may use as its working directory. */
|
|
25
|
+
roots?: string[];
|
|
26
|
+
rules?: SandboxRule[];
|
|
27
|
+
env?: EnvPolicy;
|
|
28
|
+
/** Tools refused outright while the mode is `read-only` (they write). The integrator lists them. */
|
|
29
|
+
writeTools?: string[];
|
|
30
|
+
/** Tools that run commands (what the approval level calls "commands"). Default `['run_command']`. */
|
|
31
|
+
commandTools?: string[];
|
|
32
|
+
}
|
|
33
|
+
export interface ResolvedPolicy {
|
|
34
|
+
mode: SandboxMode;
|
|
35
|
+
network: SandboxNetwork;
|
|
36
|
+
approval: ApprovalLevel;
|
|
37
|
+
roots: string[];
|
|
38
|
+
env: EnvPolicy;
|
|
39
|
+
/** Preset that matches the effective mode and approval, or `custom`. */
|
|
40
|
+
preset: PermissionPreset | 'custom';
|
|
41
|
+
}
|
|
42
|
+
export declare class SandboxPolicyError extends Error {
|
|
43
|
+
constructor(path: string, message: string);
|
|
44
|
+
}
|
|
45
|
+
/** Checks an untrusted object (a YAML file, a control request) and returns it as a typed config. */
|
|
46
|
+
export declare function parsePolicyConfig(input: unknown): SandboxPolicyConfig;
|
|
47
|
+
/**
|
|
48
|
+
* The single place that decides how a call is confined. It is plain data behind two methods: `set` swaps the
|
|
49
|
+
* whole configuration (taking effect on the NEXT call, never in the middle of one) and `snapshot` shows it.
|
|
50
|
+
*/
|
|
51
|
+
export interface SandboxPolicy {
|
|
52
|
+
resolve(caller: SandboxCaller, tool: string): ResolvedPolicy;
|
|
53
|
+
/** Replaces the configuration after validating it. A throwing call leaves the current policy untouched. */
|
|
54
|
+
set(config: SandboxPolicyConfig): void;
|
|
55
|
+
/** A copy of the current configuration. */
|
|
56
|
+
snapshot(): SandboxPolicyConfig;
|
|
57
|
+
/** Tools refused while `read-only`, for the caller to enforce. */
|
|
58
|
+
writeTools(): readonly string[];
|
|
59
|
+
/** Tools that count as running a command for the approval level. */
|
|
60
|
+
commandTools(): readonly string[];
|
|
61
|
+
/** Increments on every successful `set`, so a control plane can tell whether its copy is current. */
|
|
62
|
+
readonly version: number;
|
|
63
|
+
}
|
|
64
|
+
export declare function createSandboxPolicy(initial?: SandboxPolicyConfig): SandboxPolicy;
|
|
65
|
+
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC9F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAuD,KAAK,aAAa,EAAE,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAM3H,+FAA+F;AAC/F,MAAM,WAAW,WAAW;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,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C,kEAAkE;IAClE,UAAU,IAAI,SAAS,MAAM,EAAE,CAAC;IAChC,oEAAoE;IACpE,YAAY,IAAI,SAAS,MAAM,EAAE,CAAC;IAClC,qGAAqG;IACrG,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC5B;AAED,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,mBAAwB,GAAG,aAAa,CAkCpF"}
|
package/dist/policy.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SandboxPolicyError = void 0;
|
|
4
|
+
exports.parsePolicyConfig = parsePolicyConfig;
|
|
5
|
+
exports.createSandboxPolicy = createSandboxPolicy;
|
|
6
|
+
const presets_1 = require("./presets");
|
|
7
|
+
const MODES = ['read-only', 'workspace-write', 'danger-full-access'];
|
|
8
|
+
const NETWORKS = ['none', 'allow'];
|
|
9
|
+
const APPROVALS = ['none', 'commands', 'writes-and-commands'];
|
|
10
|
+
class SandboxPolicyError extends Error {
|
|
11
|
+
constructor(path, message) {
|
|
12
|
+
super(`Invalid sandbox policy at ${path}: ${message}`);
|
|
13
|
+
this.name = 'SandboxPolicyError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.SandboxPolicyError = SandboxPolicyError;
|
|
17
|
+
const defaultNetwork = (mode) => (mode === 'danger-full-access' ? 'allow' : 'none');
|
|
18
|
+
function oneOf(path, value, allowed) {
|
|
19
|
+
if (typeof value !== 'string' || !allowed.includes(value)) {
|
|
20
|
+
throw new SandboxPolicyError(path, `expected one of ${allowed.join(' | ')}, got ${JSON.stringify(value)}`);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
function stringList(path, value) {
|
|
25
|
+
if (!Array.isArray(value) || value.some(v => typeof v !== 'string'))
|
|
26
|
+
throw new SandboxPolicyError(path, 'expected an array of strings');
|
|
27
|
+
return [...value];
|
|
28
|
+
}
|
|
29
|
+
/** Checks an untrusted object (a YAML file, a control request) and returns it as a typed config. */
|
|
30
|
+
function parsePolicyConfig(input) {
|
|
31
|
+
if (typeof input !== 'object' || input === null || Array.isArray(input))
|
|
32
|
+
throw new SandboxPolicyError('$', 'expected an object');
|
|
33
|
+
const c = input;
|
|
34
|
+
const out = {};
|
|
35
|
+
if (c.preset !== undefined) {
|
|
36
|
+
if (!(0, presets_1.isPermissionPreset)(c.preset))
|
|
37
|
+
throw new SandboxPolicyError('preset', `unknown preset ${JSON.stringify(c.preset)}`);
|
|
38
|
+
out.preset = c.preset;
|
|
39
|
+
}
|
|
40
|
+
if (c.mode !== undefined)
|
|
41
|
+
out.mode = oneOf('mode', c.mode, MODES);
|
|
42
|
+
if (c.approval !== undefined)
|
|
43
|
+
out.approval = oneOf('approval', c.approval, APPROVALS);
|
|
44
|
+
if (c.network !== undefined)
|
|
45
|
+
out.network = oneOf('network', c.network, NETWORKS);
|
|
46
|
+
if (c.roots !== undefined)
|
|
47
|
+
out.roots = stringList('roots', c.roots);
|
|
48
|
+
if (c.writeTools !== undefined)
|
|
49
|
+
out.writeTools = stringList('writeTools', c.writeTools);
|
|
50
|
+
if (c.commandTools !== undefined)
|
|
51
|
+
out.commandTools = stringList('commandTools', c.commandTools);
|
|
52
|
+
if (c.env !== undefined) {
|
|
53
|
+
const e = c.env;
|
|
54
|
+
if (typeof e !== 'object' || e === null)
|
|
55
|
+
throw new SandboxPolicyError('env', 'expected an object');
|
|
56
|
+
out.env = {
|
|
57
|
+
...(e.allow !== undefined ? { allow: stringList('env.allow', e.allow) } : {}),
|
|
58
|
+
...(e.deny !== undefined ? { deny: stringList('env.deny', e.deny) } : {}),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (c.rules !== undefined) {
|
|
62
|
+
if (!Array.isArray(c.rules))
|
|
63
|
+
throw new SandboxPolicyError('rules', 'expected an array');
|
|
64
|
+
out.rules = c.rules.map((r, i) => {
|
|
65
|
+
const rule = r;
|
|
66
|
+
if (typeof rule !== 'object' || rule === null)
|
|
67
|
+
throw new SandboxPolicyError(`rules[${i}]`, 'expected an object');
|
|
68
|
+
if (rule.agentId !== undefined && typeof rule.agentId !== 'string')
|
|
69
|
+
throw new SandboxPolicyError(`rules[${i}].agentId`, 'expected a string');
|
|
70
|
+
if (rule.tool !== undefined && typeof rule.tool !== 'string')
|
|
71
|
+
throw new SandboxPolicyError(`rules[${i}].tool`, 'expected a string');
|
|
72
|
+
return {
|
|
73
|
+
...(rule.agentId !== undefined ? { agentId: rule.agentId } : {}),
|
|
74
|
+
...(rule.tool !== undefined ? { tool: rule.tool } : {}),
|
|
75
|
+
...(rule.mode !== undefined ? { mode: oneOf(`rules[${i}].mode`, rule.mode, MODES) } : {}),
|
|
76
|
+
...(rule.network !== undefined ? { network: oneOf(`rules[${i}].network`, rule.network, NETWORKS) } : {}),
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
function createSandboxPolicy(initial = {}) {
|
|
83
|
+
let config = parsePolicyConfig(initial);
|
|
84
|
+
let version = 1;
|
|
85
|
+
return {
|
|
86
|
+
resolve(caller, tool) {
|
|
87
|
+
const preset = presets_1.PERMISSION_PRESETS[config.preset ?? 'ask'];
|
|
88
|
+
let mode = config.mode ?? preset.mode;
|
|
89
|
+
let ruleNetwork;
|
|
90
|
+
const rule = (config.rules ?? []).find(r => (r.agentId === undefined || r.agentId === caller.agentId) && (r.tool === undefined || r.tool === tool));
|
|
91
|
+
if (rule) {
|
|
92
|
+
if (rule.mode)
|
|
93
|
+
mode = rule.mode;
|
|
94
|
+
ruleNetwork = rule.network;
|
|
95
|
+
}
|
|
96
|
+
const approval = config.approval ?? preset.approval;
|
|
97
|
+
return {
|
|
98
|
+
mode,
|
|
99
|
+
network: ruleNetwork ?? config.network ?? defaultNetwork(mode),
|
|
100
|
+
approval,
|
|
101
|
+
roots: [...(config.roots ?? [])],
|
|
102
|
+
env: { allow: [...(config.env?.allow ?? [])], deny: [...(config.env?.deny ?? [])] },
|
|
103
|
+
preset: (0, presets_1.matchPreset)(mode, approval),
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
set(next) {
|
|
107
|
+
config = parsePolicyConfig(next);
|
|
108
|
+
version++;
|
|
109
|
+
},
|
|
110
|
+
snapshot: () => JSON.parse(JSON.stringify(config)),
|
|
111
|
+
writeTools: () => config.writeTools ?? [],
|
|
112
|
+
commandTools: () => config.commandTools ?? ['run_command'],
|
|
113
|
+
get version() { return version; },
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":";;;AAuEA,8CAsCC;AAoBD,kDAkCC;AAjKD,uCAA2H;AAE3H,MAAM,KAAK,GAAkB,CAAC,WAAW,EAAE,iBAAiB,EAAE,oBAAoB,CAAC,CAAC;AACpF,MAAM,QAAQ,GAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACrD,MAAM,SAAS,GAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,qBAAqB,CAAC,CAAC;AA2C/E,MAAa,kBAAmB,SAAQ,KAAK;IACzC,YAAY,IAAY,EAAE,OAAe;QACrC,KAAK,CAAC,6BAA6B,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QACvD,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACrC,CAAC;CACJ;AALD,gDAKC;AAED,MAAM,cAAc,GAAG,CAAC,IAAiB,EAAkB,EAAE,CAAC,CAAC,IAAI,KAAK,oBAAoB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjH,SAAS,KAAK,CAAmB,IAAY,EAAE,KAAc,EAAE,OAAqB;IAChF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,Q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;YACD,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC;YACpD,OAAO;gBACH,IAAI;gBACJ,OAAO,EAAE,WAAW,IAAI,MAAM,CAAC,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC;gBAC9D,QAAQ;gBACR,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;gBAChC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC,EAAE;gBACnF,MAAM,EAAE,IAAA,qBAAW,EAAC,IAAI,EAAE,QAAQ,CAAC;aACtC,CAAC;QACN,CAAC;QACD,GAAG,CAAC,IAAI;YACJ,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;YACjC,OAAO,EAAE,CAAC;QACd,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAwB;QACzE,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE;QACzC,YAAY,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,IAAI,CAAC,aAAa,CAAC;QAC1D,IAAI,OAAO,KAAK,OAAO,OAAO,CAAC,CAAC,CAAC;KACpC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SandboxMode } from '@backendkit-labs/agent-core';
|
|
2
|
+
/**
|
|
3
|
+
* What needs a human before it runs:
|
|
4
|
+
* - `none`: nothing.
|
|
5
|
+
* - `commands`: running commands.
|
|
6
|
+
* - `writes-and-commands`: file writes and running commands.
|
|
7
|
+
*/
|
|
8
|
+
export type ApprovalLevel = 'none' | 'commands' | 'writes-and-commands';
|
|
9
|
+
export type PermissionPreset = 'read-only' | 'ask' | 'auto-edit' | 'full';
|
|
10
|
+
export interface PresetDefinition {
|
|
11
|
+
mode: SandboxMode;
|
|
12
|
+
approval: ApprovalLevel;
|
|
13
|
+
description: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Sandbox mode + approval, by name. `auto-edit` deviates from the SPEC-0006 table on purpose: the command
|
|
17
|
+
* allowlist of `run_command` stays a hard block (it is not a soft list yet), so here "auto-edit" means file
|
|
18
|
+
* edits run without asking and every command asks.
|
|
19
|
+
*/
|
|
20
|
+
export declare const PERMISSION_PRESETS: Readonly<Record<PermissionPreset, PresetDefinition>>;
|
|
21
|
+
export declare function isPermissionPreset(x: unknown): x is PermissionPreset;
|
|
22
|
+
/** The preset a (mode, approval) pair corresponds to, or `custom` when it matches none. */
|
|
23
|
+
export declare function matchPreset(mode: SandboxMode, approval: ApprovalLevel): PermissionPreset | 'custom';
|
|
24
|
+
export type ActionKind = 'read' | 'write' | 'command';
|
|
25
|
+
/** Does an action of this kind need a human under this approval level? */
|
|
26
|
+
export declare function needsApproval(level: ApprovalLevel, kind: ActionKind): boolean;
|
|
27
|
+
//# sourceMappingURL=presets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../src/presets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,UAAU,GAAG,qBAAqB,CAAC;AAExE,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,KAAK,GAAG,WAAW,GAAG,MAAM,CAAC;AAE1E,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,aAAa,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAKnF,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,gBAAgB,CAEpE;AAED,2FAA2F;AAC3F,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,GAAG,gBAAgB,GAAG,QAAQ,CAKnG;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAEtD,0EAA0E;AAC1E,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAI7E"}
|
package/dist/presets.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PERMISSION_PRESETS = void 0;
|
|
4
|
+
exports.isPermissionPreset = isPermissionPreset;
|
|
5
|
+
exports.matchPreset = matchPreset;
|
|
6
|
+
exports.needsApproval = needsApproval;
|
|
7
|
+
/**
|
|
8
|
+
* Sandbox mode + approval, by name. `auto-edit` deviates from the SPEC-0006 table on purpose: the command
|
|
9
|
+
* allowlist of `run_command` stays a hard block (it is not a soft list yet), so here "auto-edit" means file
|
|
10
|
+
* edits run without asking and every command asks.
|
|
11
|
+
*/
|
|
12
|
+
exports.PERMISSION_PRESETS = {
|
|
13
|
+
'read-only': { mode: 'read-only', approval: 'none', description: 'nothing can write; no approval needed' },
|
|
14
|
+
'ask': { mode: 'workspace-write', approval: 'writes-and-commands', description: 'writes only in the workspace; ask before writes and commands' },
|
|
15
|
+
'auto-edit': { mode: 'workspace-write', approval: 'commands', description: 'writes only in the workspace; file edits run, commands ask' },
|
|
16
|
+
'full': { mode: 'danger-full-access', approval: 'none', description: 'no confinement, no approval' },
|
|
17
|
+
};
|
|
18
|
+
function isPermissionPreset(x) {
|
|
19
|
+
return typeof x === 'string' && Object.prototype.hasOwnProperty.call(exports.PERMISSION_PRESETS, x);
|
|
20
|
+
}
|
|
21
|
+
/** The preset a (mode, approval) pair corresponds to, or `custom` when it matches none. */
|
|
22
|
+
function matchPreset(mode, approval) {
|
|
23
|
+
for (const [name, def] of Object.entries(exports.PERMISSION_PRESETS)) {
|
|
24
|
+
if (def.mode === mode && def.approval === approval)
|
|
25
|
+
return name;
|
|
26
|
+
}
|
|
27
|
+
return 'custom';
|
|
28
|
+
}
|
|
29
|
+
/** Does an action of this kind need a human under this approval level? */
|
|
30
|
+
function needsApproval(level, kind) {
|
|
31
|
+
if (level === 'none')
|
|
32
|
+
return false;
|
|
33
|
+
if (kind === 'command')
|
|
34
|
+
return true;
|
|
35
|
+
return level === 'writes-and-commands' && kind === 'write';
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=presets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presets.js","sourceRoot":"","sources":["../src/presets.ts"],"names":[],"mappings":";;;AA8BA,gDAEC;AAGD,kCAKC;AAKD,sCAIC;AA/BD;;;;GAIG;AACU,QAAA,kBAAkB,GAAyD;IACpF,WAAW,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,uCAAuC,EAAE;IAC1G,KAAK,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,QAAQ,EAAE,qBAAqB,EAAE,WAAW,EAAE,8DAA8D,EAAE;IAChJ,WAAW,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,4DAA4D,EAAE;IACzI,MAAM,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,6BAA6B,EAAE;CACvG,CAAC;AAEF,SAAgB,kBAAkB,CAAC,CAAU;IACzC,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,0BAAkB,EAAE,CAAC,CAAC,CAAC;AAChG,CAAC;AAED,2FAA2F;AAC3F,SAAgB,WAAW,CAAC,IAAiB,EAAE,QAAuB;IAClE,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,0BAAkB,CAAgD,EAAE,CAAC;QAC1G,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;IACpE,CAAC;IACD,OAAO,QAAQ,CAAC;AACpB,CAAC;AAID,0EAA0E;AAC1E,SAAgB,aAAa,CAAC,KAAoB,EAAE,IAAgB;IAChE,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IACnC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACpC,OAAO,KAAK,KAAK,qBAAqB,IAAI,IAAI,KAAK,OAAO,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ChildProcess } from 'child_process';
|
|
2
|
+
import type { SandboxExecResult } from '@backendkit-labs/agent-core';
|
|
3
|
+
/** Stdout+stderr kept in `SandboxExecResult.output` (the callback still gets everything). */
|
|
4
|
+
export declare const DEFAULT_MAX_OUTPUT_CHARS = 40000;
|
|
5
|
+
/**
|
|
6
|
+
* Stops a process and everything it started. A plain `proc.kill()` leaves the children of a shell
|
|
7
|
+
* running (and on Windows does not reach them at all).
|
|
8
|
+
*/
|
|
9
|
+
export declare function killProcessTree(proc: ChildProcess): void;
|
|
10
|
+
export interface RunProcessOptions {
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
onOutput?: (chunk: string) => void;
|
|
14
|
+
maxOutputChars?: number;
|
|
15
|
+
/** Stops the process (default: the whole process tree). */
|
|
16
|
+
kill?: (proc: ChildProcess) => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Drives an already spawned process to the end: collects stdout and stderr interleaved in arrival order,
|
|
20
|
+
* enforces the timeout, honours the abort signal and kills the whole tree when either fires.
|
|
21
|
+
* Resolves as soon as the process closes, or immediately after it was killed for timeout / abort.
|
|
22
|
+
*/
|
|
23
|
+
export declare function runProcess(proc: ChildProcess, o?: RunProcessOptions): Promise<SandboxExecResult>;
|
|
24
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../src/process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE,6FAA6F;AAC7F,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAE/C;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAaxD;AAED,MAAM,WAAW,iBAAiB;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;CACvC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,GAAE,iBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAwCpG"}
|
package/dist/process.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_MAX_OUTPUT_CHARS = void 0;
|
|
4
|
+
exports.killProcessTree = killProcessTree;
|
|
5
|
+
exports.runProcess = runProcess;
|
|
6
|
+
const child_process_1 = require("child_process");
|
|
7
|
+
/** Stdout+stderr kept in `SandboxExecResult.output` (the callback still gets everything). */
|
|
8
|
+
exports.DEFAULT_MAX_OUTPUT_CHARS = 40_000;
|
|
9
|
+
/**
|
|
10
|
+
* Stops a process and everything it started. A plain `proc.kill()` leaves the children of a shell
|
|
11
|
+
* running (and on Windows does not reach them at all).
|
|
12
|
+
*/
|
|
13
|
+
function killProcessTree(proc) {
|
|
14
|
+
if (process.platform === 'win32' && proc.pid) {
|
|
15
|
+
// taskkill must see the tree while the shell is alive (once cmd.exe dies Windows forgets its
|
|
16
|
+
// children), so the shell is not killed here: /F ends it together with the rest.
|
|
17
|
+
const tk = (0, child_process_1.spawn)('taskkill', ['/pid', String(proc.pid), '/T', '/F'], { stdio: 'ignore' });
|
|
18
|
+
tk.on('error', () => proc.kill());
|
|
19
|
+
tk.on('close', (code) => { if (code !== 0)
|
|
20
|
+
proc.kill(); });
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (proc.pid) {
|
|
24
|
+
try {
|
|
25
|
+
process.kill(-proc.pid, 'SIGKILL');
|
|
26
|
+
}
|
|
27
|
+
catch { /* not a process group leader */ }
|
|
28
|
+
}
|
|
29
|
+
proc.kill();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Drives an already spawned process to the end: collects stdout and stderr interleaved in arrival order,
|
|
33
|
+
* enforces the timeout, honours the abort signal and kills the whole tree when either fires.
|
|
34
|
+
* Resolves as soon as the process closes, or immediately after it was killed for timeout / abort.
|
|
35
|
+
*/
|
|
36
|
+
function runProcess(proc, o = {}) {
|
|
37
|
+
const max = o.maxOutputChars ?? exports.DEFAULT_MAX_OUTPUT_CHARS;
|
|
38
|
+
const kill = o.kill ?? killProcessTree;
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
const chunks = [];
|
|
41
|
+
let total = 0;
|
|
42
|
+
let settled = false;
|
|
43
|
+
const finish = (r) => {
|
|
44
|
+
if (settled)
|
|
45
|
+
return;
|
|
46
|
+
settled = true;
|
|
47
|
+
clearTimeout(timer);
|
|
48
|
+
o.signal?.removeEventListener('abort', onAbort);
|
|
49
|
+
resolve({ ...r, output: chunks.join('') });
|
|
50
|
+
};
|
|
51
|
+
const collect = (data) => {
|
|
52
|
+
const s = data.toString('utf-8');
|
|
53
|
+
o.onOutput?.(s);
|
|
54
|
+
const room = max - total;
|
|
55
|
+
if (room <= 0)
|
|
56
|
+
return;
|
|
57
|
+
chunks.push(s.length > room ? s.slice(0, room) : s);
|
|
58
|
+
total += Math.min(s.length, room);
|
|
59
|
+
};
|
|
60
|
+
proc.stdout?.on('data', collect);
|
|
61
|
+
proc.stderr?.on('data', collect);
|
|
62
|
+
const onAbort = () => {
|
|
63
|
+
kill(proc);
|
|
64
|
+
finish({ exitCode: null, timedOut: false, aborted: true });
|
|
65
|
+
};
|
|
66
|
+
const timer = o.timeoutMs
|
|
67
|
+
? setTimeout(() => { kill(proc); finish({ exitCode: null, timedOut: true, aborted: false }); }, o.timeoutMs)
|
|
68
|
+
: undefined;
|
|
69
|
+
if (o.signal?.aborted)
|
|
70
|
+
onAbort();
|
|
71
|
+
else
|
|
72
|
+
o.signal?.addEventListener('abort', onAbort, { once: true });
|
|
73
|
+
proc.on('error', (err) => finish({ exitCode: null, timedOut: false, aborted: false, error: err.message }));
|
|
74
|
+
proc.on('close', (code) => finish({ exitCode: code, timedOut: false, aborted: false }));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../src/process.ts"],"names":[],"mappings":";;;AAUA,0CAaC;AAgBD,gCAwCC;AA/ED,iDAAyD;AAGzD,6FAA6F;AAChF,QAAA,wBAAwB,GAAG,MAAM,C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AAM,KAAK,GAA8C,CAAC,CAAC,SAAS;YAChE,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC;YAC5G,CAAC,CAAC,SAAS,CAAC;QAEhB,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO;YAAE,OAAO,EAAE,CAAC;;YAC5B,CAAC,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAElE,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAC3G,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAC5F,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SandboxDecision, SandboxRunner } from '@backendkit-labs/agent-core';
|
|
2
|
+
import type { SandboxBackend } from './backends/types';
|
|
3
|
+
import type { SandboxPolicy } from './policy';
|
|
4
|
+
export type DecisionListener = (decision: SandboxDecision) => void;
|
|
5
|
+
export interface SandboxServiceOptions {
|
|
6
|
+
policy: SandboxPolicy;
|
|
7
|
+
/** Tried in order; the first that can ENFORCE the required mode (and is available) runs the call. */
|
|
8
|
+
backends: SandboxBackend[];
|
|
9
|
+
/** Environment the confined process starts from, before scrubbing. Default `process.env`. */
|
|
10
|
+
baseEnv?: Record<string, string | undefined>;
|
|
11
|
+
/** Appends every decision as one JSON line to this file. */
|
|
12
|
+
auditLog?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Hand the command a scrubbed environment (credential-looking variables removed). Default true.
|
|
15
|
+
* Only the legacy `BK_RUN_COMMAND_SANDBOX` path turns it off, to keep its old behaviour.
|
|
16
|
+
*/
|
|
17
|
+
scrubEnvironment?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface SandboxService extends SandboxRunner {
|
|
20
|
+
readonly policy: SandboxPolicy;
|
|
21
|
+
/** Called for every decision (allowed, denied, unavailable). A throwing listener never affects the call. */
|
|
22
|
+
onDecision(listener: DecisionListener): () => void;
|
|
23
|
+
}
|
|
24
|
+
export declare function createSandboxService(options: SandboxServiceOptions): SandboxService;
|
|
25
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACO,eAAe,EACV,aAAa,EACpC,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG9C,MAAM,MAAM,gBAAgB,GAAG,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;AAEnE,MAAM,WAAW,qBAAqB;IAClC,MAAM,EAAE,aAAa,CAAC;IACtB,qGAAqG;IACrG,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,6FAA6F;IAC7F,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAC7C,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,cAAe,SAAQ,aAAa;IACjD,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,4GAA4G;IAC5G,UAAU,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,IAAI,CAAC;CACtD;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAsHnF"}
|
package/dist/service.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSandboxService = createSandboxService;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const env_1 = require("./env");
|
|
7
|
+
const paths_1 = require("./paths");
|
|
8
|
+
const presets_1 = require("./presets");
|
|
9
|
+
function createSandboxService(options) {
|
|
10
|
+
const { policy, backends } = options;
|
|
11
|
+
const listeners = new Set();
|
|
12
|
+
// One chain, so lines reach the file in the order the decisions were taken.
|
|
13
|
+
let auditChain;
|
|
14
|
+
const emit = (d) => {
|
|
15
|
+
for (const l of listeners) {
|
|
16
|
+
try {
|
|
17
|
+
l(d);
|
|
18
|
+
}
|
|
19
|
+
catch { /* an observer must not affect the call */ }
|
|
20
|
+
}
|
|
21
|
+
if (options.auditLog) {
|
|
22
|
+
const file = options.auditLog;
|
|
23
|
+
const line = JSON.stringify({ ts: new Date(d.at).toISOString(), ...d }) + '\n';
|
|
24
|
+
auditChain = (auditChain ?? (0, promises_1.mkdir)((0, path_1.dirname)(file), { recursive: true }).catch(() => undefined))
|
|
25
|
+
.then(() => (0, promises_1.appendFile)(file, line))
|
|
26
|
+
.catch(() => undefined);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const base = (caller, tool) => ({ at: Date.now(), agentId: caller.agentId, sessionId: caller.sessionId, tool });
|
|
30
|
+
return {
|
|
31
|
+
policy,
|
|
32
|
+
onDecision(listener) {
|
|
33
|
+
listeners.add(listener);
|
|
34
|
+
return () => { listeners.delete(listener); };
|
|
35
|
+
},
|
|
36
|
+
authorizeTool(caller, tool) {
|
|
37
|
+
const r = policy.resolve(caller, tool);
|
|
38
|
+
if (r.mode === 'read-only' && policy.writeTools().includes(tool)) {
|
|
39
|
+
const reason = `tool "${tool}" writes, and the sandbox policy for agent "${caller.agentId}" is read-only`;
|
|
40
|
+
emit({ ...base(caller, tool), mode: r.mode, network: r.network, outcome: 'SANDBOX_DENIED', reason });
|
|
41
|
+
return { ok: false, code: 'SANDBOX_DENIED', reason };
|
|
42
|
+
}
|
|
43
|
+
return { ok: true };
|
|
44
|
+
},
|
|
45
|
+
approvalFor(caller, tool) {
|
|
46
|
+
const r = policy.resolve(caller, tool);
|
|
47
|
+
const kind = policy.commandTools().includes(tool) ? 'command' : policy.writeTools().includes(tool) ? 'write' : 'read';
|
|
48
|
+
return (0, presets_1.needsApproval)(r.approval, kind) ? 'ask' : 'none';
|
|
49
|
+
},
|
|
50
|
+
authorizePath(caller, req) {
|
|
51
|
+
const r = policy.resolve(caller, req.tool);
|
|
52
|
+
const deny = (reason) => {
|
|
53
|
+
emit({ ...base(caller, req.tool), mode: r.mode, network: r.network, outcome: 'SANDBOX_DENIED', reason });
|
|
54
|
+
return { ok: false, code: 'SANDBOX_DENIED', reason };
|
|
55
|
+
};
|
|
56
|
+
if (r.mode === 'danger-full-access')
|
|
57
|
+
return { ok: true };
|
|
58
|
+
if (req.access === 'write' && r.mode === 'read-only') {
|
|
59
|
+
return deny(`"${req.path}" is not writable: the sandbox policy for agent "${caller.agentId}" is read-only`);
|
|
60
|
+
}
|
|
61
|
+
// Judge where the path really lands, and against roots that are themselves resolved (a root may be a link too).
|
|
62
|
+
let real;
|
|
63
|
+
let roots;
|
|
64
|
+
try {
|
|
65
|
+
real = (0, paths_1.realPathOf)(req.path);
|
|
66
|
+
roots = [req.workspace, ...r.roots, ...(req.extraRoots ?? [])].map(root => (0, paths_1.realPathOf)(root));
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
return deny(`cannot resolve "${req.path}": ${err instanceof Error ? err.message : String(err)}`);
|
|
70
|
+
}
|
|
71
|
+
if (!roots.some(root => (0, paths_1.isInside)(root, real))) {
|
|
72
|
+
return deny(`"${req.path}" resolves to "${real}", outside the allowed roots`);
|
|
73
|
+
}
|
|
74
|
+
if (req.access === 'write')
|
|
75
|
+
emit({ ...base(caller, req.tool), mode: r.mode, network: r.network, outcome: 'allowed' });
|
|
76
|
+
return { ok: true };
|
|
77
|
+
},
|
|
78
|
+
async run(caller, req) {
|
|
79
|
+
const r = policy.resolve(caller, req.tool);
|
|
80
|
+
const refuse = (code, reason, backend) => {
|
|
81
|
+
emit({ ...base(caller, req.tool), mode: r.mode, network: r.network, backend, outcome: code, reason });
|
|
82
|
+
return { ok: false, code, reason, mode: r.mode, network: r.network, ...(backend ? { backend } : {}) };
|
|
83
|
+
};
|
|
84
|
+
const workspace = req.workspace ?? req.cwd;
|
|
85
|
+
if (r.mode !== 'danger-full-access' && ![workspace, ...r.roots].some(root => (0, paths_1.isInside)(root, req.cwd))) {
|
|
86
|
+
return refuse('SANDBOX_DENIED', `working directory "${req.cwd}" is outside the allowed roots`);
|
|
87
|
+
}
|
|
88
|
+
// First backend that can really enforce the mode. Never "the host, because nothing else works".
|
|
89
|
+
const skipped = [];
|
|
90
|
+
let chosen;
|
|
91
|
+
for (const b of backends) {
|
|
92
|
+
if (!b.supports(r.mode, r.network)) {
|
|
93
|
+
skipped.push(`${b.name}: cannot enforce ${r.mode} with network ${r.network}`);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (!(await b.available())) {
|
|
97
|
+
skipped.push(`${b.name}: ${b.unavailableReason?.() ?? 'not available'}`);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
chosen = b;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
if (!chosen) {
|
|
104
|
+
return refuse('SANDBOX_UNAVAILABLE', `cannot enforce ${r.mode} (network ${r.network}) on this host; nothing was run. ${skipped.join('; ') || 'no backends configured'}`);
|
|
105
|
+
}
|
|
106
|
+
let result;
|
|
107
|
+
try {
|
|
108
|
+
result = await chosen.exec({
|
|
109
|
+
command: req.command,
|
|
110
|
+
...(req.hostCommand !== undefined ? { hostCommand: req.hostCommand } : {}),
|
|
111
|
+
cwd: req.cwd,
|
|
112
|
+
workspace,
|
|
113
|
+
mode: r.mode,
|
|
114
|
+
network: r.network,
|
|
115
|
+
env: options.scrubEnvironment === false
|
|
116
|
+
? Object.fromEntries(Object.entries(options.baseEnv ?? process.env).filter((e) => e[1] !== undefined))
|
|
117
|
+
: (0, env_1.scrubEnv)(options.baseEnv ?? process.env, r.env),
|
|
118
|
+
timeoutMs: req.timeoutMs,
|
|
119
|
+
signal: req.signal,
|
|
120
|
+
onOutput: req.onOutput,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
result = { exitCode: null, output: '', timedOut: false, aborted: false, error: err instanceof Error ? err.message : String(err) };
|
|
125
|
+
}
|
|
126
|
+
emit({ ...base(caller, req.tool), mode: r.mode, network: r.network, backend: chosen.name, outcome: 'allowed' });
|
|
127
|
+
return { ok: true, result, mode: r.mode, network: r.network, backend: chosen.name };
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;AAmCA,oDAsHC;AAzJD,0CAAgD;AAChD,+BAA+B;AAM/B,+BAAiC;AACjC,mCAA+C;AAE/C,uCAA0C;AAyB1C,SAAgB,oBAAoB,CAAC,OAA8B;IAC/D,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACrC,MAAM,SAAS,GAAG,IAAI,GAAG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,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YACtI,CAAC;YACD,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;YAChH,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QACxF,CAAC;KACJ,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@backendkit-labs/agent-sandbox",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@backendkit-labs/agent-sandbox",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Confinement and permissions for what agents run: sandbox modes, presets, a single policy point, swappable backends (host, docker) and environment hygiene, for @backendkit-labs/agent-core",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist/",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"dev": "tsc --watch",
|
|
20
|
+
"typecheck": "tsc --noEmit",
|
|
21
|
+
"prepublishOnly": "npm run build",
|
|
22
|
+
"test": "jest"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@backendkit-labs/agent-core": ">=0.31.0 <0.32.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/jest": "^29.0.0",
|
|
29
|
+
"@types/node": "^20.0.0",
|
|
30
|
+
"jest": "^29.0.0",
|
|
31
|
+
"ts-jest": "^29.0.0",
|
|
32
|
+
"typescript": "^5.4.0"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=20.0.0"
|
|
36
|
+
},
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/BackendKit-labs/backendkit-agent-framework.git",
|
|
40
|
+
"directory": "packages/sandbox"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"license": "MIT"
|
|
46
|
+
}
|