@kendoo.agentdesk/agentdesk 0.22.1 → 0.23.0
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 +3 -1
- package/cli/session-isolation.mjs +175 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -272,7 +272,9 @@ Once running, a "Run Team" button appears on [agentdesk.live](https://agentdesk.
|
|
|
272
272
|
### Security
|
|
273
273
|
|
|
274
274
|
- **Per-session identity isolation** — every session runs with `HOME` / `GH_CONFIG_DIR` / `XDG_CONFIG_HOME` pointed at a private scratch dir containing only this project's tracker credentials and commit identity. `gh`, `git`, and `ssh` inside the session cannot see your global accounts, other projects' tokens, or keys elsewhere on disk.
|
|
275
|
-
- **Kernel-enforced sandbox when available** — on macOS (`sandbox-exec`) and Linux (`bwrap` / bubblewrap), sessions run with
|
|
275
|
+
- **Kernel-enforced sandbox when available** — on macOS (`sandbox-exec`) and Linux (`bwrap` / bubblewrap), sessions run with a strict allowlist policy: full read/write on the project cwd, the per-session scratch HOME, `/tmp`, and common tool caches (`~/.nvm`, `~/.npm`, `~/.cache`, `~/.pyenv`, `~/.rbenv`, `~/.rvm`, `~/.cargo`, `~/.rustup`, `~/.gem`, `~/.local`). Read-only on system paths (`/usr`, `/etc`, `/System`, etc.). **Everything else under your real `$HOME` is unreadable from inside the session** — `~/Documents`, browser cookie stores, other projects' `.env` files, SSH keys, cloud-provider creds. Network stays open so agents can reach the Anthropic API, tracker APIs, package registries, and remote git. If `sandbox-exec` / `bwrap` isn't installed, sessions fall back to scoped-env isolation with a one-line notice.
|
|
276
|
+
- Opt out for debugging: `AGENTDESK_NO_SANDBOX=1` (no kernel sandbox at all).
|
|
277
|
+
- If the strict allowlist breaks a tool you need, fall back to the pre-allowlist denylist policy with `AGENTDESK_SANDBOX_LEGACY=1` and please file an issue so we can extend the allowlist.
|
|
276
278
|
- **Credentials prerequisite** — scoped sessions push code over HTTPS using a per-project GitHub token. `agentdesk init` saves it to the project's `.env` as `GITHUB_TOKEN`; if you skip that step, the session refuses to start with an actionable message. SSH-only remotes (`git@github.com:...`) are also rejected — the sandbox intentionally isolates `~/.ssh`. Switch the origin to `https://github.com/<owner>/<repo>.git` or run without scoped isolation.
|
|
277
279
|
- **Outbound only** — no ports opened on your machine
|
|
278
280
|
- **Project allowlist** — only runs on projects registered via `agentdesk init`
|
|
@@ -5,12 +5,21 @@
|
|
|
5
5
|
// - macOS: `sandbox-exec` (TrustedBSD sandbox, same primitive App Sandbox uses)
|
|
6
6
|
// - Linux: `bwrap` (bubblewrap — mount namespaces, same primitive Docker uses)
|
|
7
7
|
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
8
|
+
// AD-30: the policy is an ALLOWLIST — deny by default, then re-expose only what
|
|
9
|
+
// legitimate tools need (project cwd, scratchHome, system binaries/libraries,
|
|
10
|
+
// tool caches like ~/.nvm and ~/.npm). The previous denylist of ~12 known
|
|
11
|
+
// credential paths left every other ~/Documents, browser cookie store, and
|
|
12
|
+
// other-project .env readable to a prompt-injected agent.
|
|
12
13
|
//
|
|
13
|
-
// Escape
|
|
14
|
+
// Escape hatches:
|
|
15
|
+
// - AGENTDESK_NO_SANDBOX=1 — skip kernel isolation entirely (scoped HOME still applies)
|
|
16
|
+
// - AGENTDESK_SANDBOX_LEGACY=1 — revert to the pre-AD-30 denylist (use only if strict
|
|
17
|
+
// policy breaks a tool you need; report so we can extend)
|
|
18
|
+
//
|
|
19
|
+
// Failure mode: if sandbox-exec / bwrap isn't installed or the profile can't
|
|
20
|
+
// be written, we emit a one-line notice and spawn the child as normal. The
|
|
21
|
+
// scoped HOME from session-sandbox.mjs still applies — isolation degrades to
|
|
22
|
+
// "scoped env" rather than "kernel boundary."
|
|
14
23
|
|
|
15
24
|
import { execSync } from "child_process";
|
|
16
25
|
import { existsSync, writeFileSync } from "fs";
|
|
@@ -49,6 +58,10 @@ export function probeIsolation() {
|
|
|
49
58
|
return cachedProbe;
|
|
50
59
|
}
|
|
51
60
|
|
|
61
|
+
function legacyMode() {
|
|
62
|
+
return process.env.AGENTDESK_SANDBOX_LEGACY === "1";
|
|
63
|
+
}
|
|
64
|
+
|
|
52
65
|
// Build the spawn arguments for an isolated claude invocation. Takes the
|
|
53
66
|
// original command/args/options and returns the wrapped form, plus a flag
|
|
54
67
|
// indicating which isolation mode is active.
|
|
@@ -58,39 +71,129 @@ export function wrapIsolatedSpawn({ cmd, args, cwd, scratchHome, sessionId }) {
|
|
|
58
71
|
return { cmd, args, isolation: { kind: "none", reason: probe.reason } };
|
|
59
72
|
}
|
|
60
73
|
|
|
74
|
+
const policyKind = legacyMode() ? "legacy" : "strict";
|
|
75
|
+
|
|
61
76
|
if (probe.kind === "sandbox-exec") {
|
|
62
77
|
const profilePath = join(scratchHome, "sandbox.sb");
|
|
63
|
-
|
|
78
|
+
const profile = policyKind === "legacy"
|
|
79
|
+
? macosProfileLegacy({ cwd, scratchHome })
|
|
80
|
+
: macosProfileStrict({ cwd, scratchHome });
|
|
81
|
+
writeFileSync(profilePath, profile, { mode: 0o600 });
|
|
64
82
|
return {
|
|
65
83
|
cmd: "sandbox-exec",
|
|
66
84
|
args: ["-f", profilePath, cmd, ...args],
|
|
67
|
-
isolation: { kind: "sandbox-exec" },
|
|
85
|
+
isolation: { kind: "sandbox-exec", policy: policyKind },
|
|
68
86
|
};
|
|
69
87
|
}
|
|
70
88
|
|
|
71
89
|
if (probe.kind === "bwrap") {
|
|
90
|
+
const bwrap = policyKind === "legacy"
|
|
91
|
+
? bwrapArgsLegacy({ cwd, scratchHome })
|
|
92
|
+
: bwrapArgsStrict({ cwd, scratchHome });
|
|
72
93
|
return {
|
|
73
94
|
cmd: "bwrap",
|
|
74
|
-
args: [...
|
|
75
|
-
isolation: { kind: "bwrap" },
|
|
95
|
+
args: [...bwrap, cmd, ...args],
|
|
96
|
+
isolation: { kind: "bwrap", policy: policyKind },
|
|
76
97
|
};
|
|
77
98
|
}
|
|
78
99
|
|
|
79
100
|
return { cmd, args, isolation: { kind: "none", reason: "unknown probe kind" } };
|
|
80
101
|
}
|
|
81
102
|
|
|
82
|
-
// --- macOS
|
|
103
|
+
// --- macOS profiles ----------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
function sbString(s) {
|
|
106
|
+
return `"${String(s).replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// AD-30 strict allowlist. Start with deny-default, then re-expose only the
|
|
110
|
+
// paths and capabilities legitimate tools need. Anything under $HOME that
|
|
111
|
+
// isn't explicitly allowed is unreadable — that includes ~/Documents,
|
|
112
|
+
// browser cookie stores, other projects' .env files, etc.
|
|
113
|
+
function macosProfileStrict({ cwd, scratchHome }) {
|
|
114
|
+
const home = homedir();
|
|
115
|
+
|
|
116
|
+
// Tool installations and caches users typically need read access to. If a
|
|
117
|
+
// path doesn't exist we still list it — sandbox-exec ignores missing paths.
|
|
118
|
+
const userToolPaths = [
|
|
119
|
+
join(home, ".nvm"),
|
|
120
|
+
join(home, ".npm"),
|
|
121
|
+
join(home, ".cache"),
|
|
122
|
+
join(home, ".pyenv"),
|
|
123
|
+
join(home, ".rbenv"),
|
|
124
|
+
join(home, ".rvm"),
|
|
125
|
+
join(home, ".cargo"),
|
|
126
|
+
join(home, ".rustup"),
|
|
127
|
+
join(home, ".gem"),
|
|
128
|
+
join(home, ".local"),
|
|
129
|
+
join(home, "Library", "Caches"),
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
return [
|
|
133
|
+
`(version 1)`,
|
|
134
|
+
`(deny default)`,
|
|
135
|
+
``,
|
|
136
|
+
`; Process, IPC, signals, and basic mach lookups so child tools can exec.`,
|
|
137
|
+
`(allow process-exec)`,
|
|
138
|
+
`(allow process-fork)`,
|
|
139
|
+
`(allow signal)`,
|
|
140
|
+
`(allow mach-lookup)`,
|
|
141
|
+
`(allow sysctl-read)`,
|
|
142
|
+
`(allow iokit-open)`,
|
|
143
|
+
`(allow system-socket)`,
|
|
144
|
+
``,
|
|
145
|
+
`; Network — agents need to reach the Anthropic API, tracker APIs, package`,
|
|
146
|
+
`; registries, and remote git over HTTPS/SSH.`,
|
|
147
|
+
`(allow network*)`,
|
|
148
|
+
``,
|
|
149
|
+
`; Project cwd + scratch HOME — full read/write.`,
|
|
150
|
+
`(allow file-read* file-write* (subpath ${sbString(cwd)}))`,
|
|
151
|
+
`(allow file-read* file-write* (subpath ${sbString(scratchHome)}))`,
|
|
152
|
+
``,
|
|
153
|
+
`; System binaries and libraries — read-only.`,
|
|
154
|
+
`(allow file-read* (subpath "/usr"))`,
|
|
155
|
+
`(allow file-read* (subpath "/bin"))`,
|
|
156
|
+
`(allow file-read* (subpath "/sbin"))`,
|
|
157
|
+
`(allow file-read* (subpath "/System"))`,
|
|
158
|
+
`(allow file-read* (subpath "/Library"))`,
|
|
159
|
+
`(allow file-read* (subpath "/Applications"))`,
|
|
160
|
+
`(allow file-read* (subpath "/opt"))`,
|
|
161
|
+
`(allow file-read* (subpath "/private/etc"))`,
|
|
162
|
+
`(allow file-read* (subpath "/private/var/db/timezone"))`,
|
|
163
|
+
``,
|
|
164
|
+
`; Standard devices.`,
|
|
165
|
+
`(allow file-read* file-write* (literal "/dev/null"))`,
|
|
166
|
+
`(allow file-read* (literal "/dev/random"))`,
|
|
167
|
+
`(allow file-read* (literal "/dev/urandom"))`,
|
|
168
|
+
`(allow file-read* file-write* (literal "/dev/tty"))`,
|
|
169
|
+
`(allow file-read* file-write* (literal "/dev/stdin"))`,
|
|
170
|
+
`(allow file-read* file-write* (literal "/dev/stdout"))`,
|
|
171
|
+
`(allow file-read* file-write* (literal "/dev/stderr"))`,
|
|
172
|
+
``,
|
|
173
|
+
`; Temp space — child tools and package managers stage here.`,
|
|
174
|
+
`(allow file-read* file-write* (subpath "/tmp"))`,
|
|
175
|
+
`(allow file-read* file-write* (subpath "/private/tmp"))`,
|
|
176
|
+
`(allow file-read* file-write* (subpath "/private/var/folders"))`,
|
|
177
|
+
``,
|
|
178
|
+
`; Tool installations and caches the user already has in $HOME — read+write`,
|
|
179
|
+
`; because package managers and version managers update their own caches.`,
|
|
180
|
+
`; NOTE: only these specific subpaths are exposed; the rest of $HOME stays`,
|
|
181
|
+
`; denied, so ~/Documents, ~/.ssh, ~/.aws, browser cookies, etc. are NOT`,
|
|
182
|
+
`; readable from inside the sandbox.`,
|
|
183
|
+
...userToolPaths.map(p => `(allow file-read* file-write* (subpath ${sbString(p)}))`),
|
|
184
|
+
``,
|
|
185
|
+
].join("\n");
|
|
186
|
+
}
|
|
83
187
|
|
|
84
|
-
|
|
188
|
+
// Pre-AD-30 denylist — kept as opt-in fallback via AGENTDESK_SANDBOX_LEGACY=1
|
|
189
|
+
// in case the strict policy breaks a tool we haven't accounted for.
|
|
190
|
+
function macosProfileLegacy({ cwd, scratchHome }) {
|
|
85
191
|
const home = homedir();
|
|
86
|
-
// Known-sensitive paths: reads AND writes denied, even though general
|
|
87
|
-
// access is allowed, so a confused agent can't slurp up other projects'
|
|
88
|
-
// tokens or clobber the user's SSH keys / shell config.
|
|
89
192
|
const denyPathsSubpath = [
|
|
90
193
|
join(home, ".ssh"),
|
|
91
194
|
join(home, ".aws"),
|
|
92
195
|
join(home, ".gcloud"),
|
|
93
|
-
join(home, ".config", "gh"),
|
|
196
|
+
join(home, ".config", "gh"),
|
|
94
197
|
join(home, ".docker"),
|
|
95
198
|
join(home, ".kube"),
|
|
96
199
|
join(home, ".agentdesk"),
|
|
@@ -98,7 +201,7 @@ function macosProfile({ cwd, scratchHome }) {
|
|
|
98
201
|
];
|
|
99
202
|
const denyPathsLiteral = [
|
|
100
203
|
join(home, ".netrc"),
|
|
101
|
-
join(home, ".gitconfig"),
|
|
204
|
+
join(home, ".gitconfig"),
|
|
102
205
|
join(home, ".npmrc"),
|
|
103
206
|
join(home, ".pypirc"),
|
|
104
207
|
join(home, ".zshrc"),
|
|
@@ -108,32 +211,73 @@ function macosProfile({ cwd, scratchHome }) {
|
|
|
108
211
|
join(home, ".profile"),
|
|
109
212
|
];
|
|
110
213
|
|
|
111
|
-
|
|
214
|
+
return [
|
|
112
215
|
`(version 1)`,
|
|
113
216
|
`(allow default)`,
|
|
114
217
|
``,
|
|
115
|
-
`;
|
|
116
|
-
`; Agents can't read other projects' tokens, can't overwrite SSH keys or`,
|
|
117
|
-
`; rewrite the user's shell rc files.`,
|
|
218
|
+
`; LEGACY denylist (pre-AD-30). Set AGENTDESK_SANDBOX_LEGACY=1 to use.`,
|
|
118
219
|
...denyPathsSubpath.map(p => `(deny file-read* file-write* (subpath ${sbString(p)}))`),
|
|
119
220
|
...denyPathsLiteral.map(p => `(deny file-read* file-write* (literal ${sbString(p)}))`),
|
|
120
221
|
``,
|
|
121
222
|
].join("\n");
|
|
122
|
-
|
|
123
|
-
return sb;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function sbString(s) {
|
|
127
|
-
return `"${String(s).replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
128
223
|
}
|
|
129
224
|
|
|
130
225
|
// --- Linux bwrap args --------------------------------------------------------
|
|
131
226
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
227
|
+
// AD-30 strict allowlist via bwrap. Read-only binds for system paths, --tmpfs
|
|
228
|
+
// over $HOME so nothing on the user's home directory is visible by default,
|
|
229
|
+
// then re-expose specific tool dirs that exist as read-only binds.
|
|
230
|
+
function bwrapArgsStrict({ cwd, scratchHome }) {
|
|
231
|
+
const home = homedir();
|
|
232
|
+
const args = [
|
|
233
|
+
"--die-with-parent",
|
|
234
|
+
"--unshare-ipc",
|
|
235
|
+
"--unshare-uts",
|
|
236
|
+
"--unshare-pid",
|
|
237
|
+
"--proc", "/proc",
|
|
238
|
+
"--dev", "/dev",
|
|
239
|
+
// System: read-only.
|
|
240
|
+
"--ro-bind", "/usr", "/usr",
|
|
241
|
+
"--ro-bind", "/etc", "/etc",
|
|
242
|
+
"--ro-bind-try", "/lib", "/lib",
|
|
243
|
+
"--ro-bind-try", "/lib64", "/lib64",
|
|
244
|
+
"--ro-bind-try", "/lib32", "/lib32",
|
|
245
|
+
"--ro-bind-try", "/bin", "/bin",
|
|
246
|
+
"--ro-bind-try", "/sbin", "/sbin",
|
|
247
|
+
"--ro-bind-try", "/opt", "/opt",
|
|
248
|
+
// tmp: writable.
|
|
249
|
+
"--bind", "/tmp", "/tmp",
|
|
250
|
+
// Blank the real home; re-expose specific tool dirs below.
|
|
251
|
+
"--tmpfs", home,
|
|
252
|
+
// Project cwd + scratch HOME: writable.
|
|
253
|
+
"--bind", cwd, cwd,
|
|
254
|
+
"--bind", scratchHome, scratchHome,
|
|
255
|
+
// Network is intentionally NOT unshared — agents need tracker APIs and git.
|
|
256
|
+
];
|
|
257
|
+
|
|
258
|
+
// Tool dirs the user typically has in $HOME — re-expose only if present.
|
|
259
|
+
// `--ro-bind-try` is a no-op if the source path doesn't exist.
|
|
260
|
+
const userToolPaths = [
|
|
261
|
+
join(home, ".nvm"),
|
|
262
|
+
join(home, ".npm"),
|
|
263
|
+
join(home, ".cache"),
|
|
264
|
+
join(home, ".pyenv"),
|
|
265
|
+
join(home, ".rbenv"),
|
|
266
|
+
join(home, ".rvm"),
|
|
267
|
+
join(home, ".cargo"),
|
|
268
|
+
join(home, ".rustup"),
|
|
269
|
+
join(home, ".gem"),
|
|
270
|
+
join(home, ".local"),
|
|
271
|
+
];
|
|
272
|
+
for (const p of userToolPaths) {
|
|
273
|
+
args.push("--ro-bind-try", p, p);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return args;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Pre-AD-30 denylist via bwrap (--bind / / + tmpfs over deny paths).
|
|
280
|
+
function bwrapArgsLegacy({ cwd, scratchHome }) {
|
|
137
281
|
const home = homedir();
|
|
138
282
|
const denyPaths = [
|
|
139
283
|
join(home, ".ssh"),
|
|
@@ -162,10 +306,7 @@ function bwrapArgs({ cwd, scratchHome }) {
|
|
|
162
306
|
"--unshare-ipc",
|
|
163
307
|
"--unshare-uts",
|
|
164
308
|
"--unshare-pid",
|
|
165
|
-
// Network is NOT unshared — agents need network for tracker APIs and git.
|
|
166
309
|
];
|
|
167
310
|
for (const p of denyPaths) args.push("--tmpfs", p);
|
|
168
|
-
// scratch HOME + project dir stay writable (already bound via --bind / /
|
|
169
|
-
// above — tmpfs blanks only the specific deny paths, not the rest).
|
|
170
311
|
return args;
|
|
171
312
|
}
|