Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Say honestly what VM mode isolates

Lin (kwant bot)c99ae003443a
diff --git a/docs/browser-service.md b/docs/browser-service.md
index 0f47f745..86420479 100644
--- a/docs/browser-service.md
+++ b/docs/browser-service.md
@@ -11,7 +11,7 @@ Take Control obtains an exclusive server-side lease. Bot navigation and selector
Kwnt runs bots' browser and shell commands in one of two places, chosen in **Settings → Computer** or with the browser panel's mode toggle:
- **Local computer** (`local`, the default on macOS): Kwnt runs your installed Chrome or Chromium without a window (`--headless=new`, 1280×800) with its own profile, `<data dir>/local-chrome`, and shows it live in the app's browser panel, the same way as the VM. To sign in or solve a CAPTCHA yourself, use **Open as window** in the panel: Kwnt closes the windowless Chrome and opens the same profile as a real window, with each bot's page reopened there (one profile can't be open twice). **Show it here instead**, or closing that window, brings it back into the panel. Saved sign-ins carry over; cookies that only last for a browser session do not. The window choice is not saved, so a restart goes back to the panel. Switching to VM closes the windowless Chrome; a window you opened stays open. It never uses your everyday Chrome profile. Each bot gets its own Chrome window (headless Chrome only paints the front tab of a window, so tabs would stall the other bots' screenshots). Sign-ins are kept in the kwant profile and shared by all bots. The debugging port is chosen by Chrome and listens on 127.0.0.1 only. Shell commands run on your computer in the bot's working folder, and **every command asks for your approval first**. "Always allow" applies to that one command; it is not remembered. Docker is not needed.
-- **VM (isolated)** (`vm`, the default everywhere else, including a VPS): the Docker browser and execution containers described below.
+- **VM (browser and built-in shell isolated)** (`vm`, the default everywhere else, including a VPS): the Docker browser and execution containers described below. Only the browser and kwnt's own `execute_shell` run in containers. Claude, Codex and Grok still run on this computer, with their own file and shell tools.
Switching takes effect at once, without a restart. Kwnt disconnects from the old browser: the VM container and a local Chrome window keep running, and switching back reuses them; only the windowless local Chrome is closed, as nothing would show it. Each mode keeps its own saved pages (`browser-sessions-local.json` and `browser-sessions.json`). If the local Chrome was closed, the next browser action starts it again. Kwnt does not close Chrome when it stops, and reuses a running one on the next start.
@@ -24,6 +24,7 @@ API (same authentication as the other settings routes):
```text
GET /api/settings/computer
→ {"mode":"local"|"vm","available":{"local":bool,"vm":bool},"reasons":{"local":string|null,"vm":string|null},
+ "isolates":["browser","kwnt_shell"], // what vm mode runs in containers; "cli_agents" once the CLIs move
"window":{"visible":bool,"available":bool,"reason":string|null}}
PUT /api/settings/computer {"mode":"local"|"vm"}
@@ -34,7 +35,7 @@ PUT /api/settings/computer/window {"visible":bool}
400 {"error":...} outside local mode or with no display for a window; 502 if Chrome could not restart
```
-Local mode gives up isolation: commands run with your user's access to your files, and the debugging port can be reached by other programs on the same computer while the kwant Chrome is running. Use VM mode for untrusted work.
+Local mode gives up isolation: commands run with your user's access to your files, and the debugging port can be reached by other programs on the same computer while the kwant Chrome is running. Use VM mode for untrusted browsing and shell work. VM mode does not contain the Claude, Codex or Grok CLIs, which run on this computer in both modes.
## VM mode on a Mac or Linux VPS
diff --git a/frontend/src/components/ComputerModeSwitch.tsx b/frontend/src/components/ComputerModeSwitch.tsx
index ba984dd2..8ba28399 100644
--- a/frontend/src/components/ComputerModeSwitch.tsx
+++ b/frontend/src/components/ComputerModeSwitch.tsx
@@ -2,12 +2,12 @@ import React, { useCallback, useEffect, useReducer, useRef, useState } from 'rea
import { AlertTriangle, AppWindow, Box, Laptop, Loader2, PanelRight, X } from 'lucide-react';
import { playSfx } from '../audio/chiptune';
import {
- COMPUTER_MODES,
COMPUTER_MODE_EVENT,
LOCAL_BROWSER_NOTE,
ComputerMode,
ComputerSettings,
SwitchState,
+ computerModes,
fetchComputerSettings,
initialSwitchState,
modeLabel,
@@ -132,7 +132,7 @@ export const ComputerModeControl: React.FC<{ api: ComputerModeApi }> = ({ api })
return (
<div className="space-y-2">
<div role="radiogroup" aria-labelledby="computer-mode-label" className="grid grid-cols-1 sm:grid-cols-2 gap-2">
- {COMPUTER_MODES.map(({ id, label, hint }) => {
+ {computerModes(settings).map(({ id, label, hint, note }) => {
const Icon = ICONS[id];
const reason = unavailableReason(settings, id);
const checked = selected === id;
@@ -167,6 +167,12 @@ export const ComputerModeControl: React.FC<{ api: ComputerModeApi }> = ({ api })
</span>
<span id={`computer-mode-${id}-hint`} className="block mt-1 text-[11px] leading-snug">
<span className={reason ? 'text-zinc-600' : 'text-zinc-500'}>{hint}</span>
+ {note && (
+ <>
+ {' '}
+ <span className={`block mt-1 ${reason ? 'text-zinc-600' : 'text-zinc-400'}`}>{note}</span>
+ </>
+ )}
{reason && <span className="block mt-1 text-amber-300/90">Unavailable: {reason}</span>}
</span>
</button>
@@ -187,12 +193,13 @@ export const ComputerModeChip: React.FC<{ api: ComputerModeApi }> = ({ api }) =>
const next = otherMode(current);
const reason = unavailableReason(settings, next);
const Icon = ICONS[current];
- const short = COMPUTER_MODES.find((m) => m.id === current)!.short;
+ const short = computerModes(settings).find((m) => m.id === current)!.short;
+ const label = (m: ComputerMode) => modeLabel(m, settings);
const title = state.pending
- ? `Switching to ${modeLabel(current)}…`
+ ? `Switching to ${label(current)}…`
: reason
- ? `Using ${modeLabel(current)}. ${modeLabel(next)} is unavailable: ${reason}`
- : `Using ${modeLabel(current)}. Click to switch to ${modeLabel(next)}.`;
+ ? `Using ${label(current)}. ${label(next)} is unavailable: ${reason}`
+ : `Using ${label(current)}. Click to switch to ${label(next)}.`;
return (
<button
type="button"
diff --git a/frontend/src/computerMode.ts b/frontend/src/computerMode.ts
index 7efb8d1f..8dcf1580 100644
--- a/frontend/src/computerMode.ts
+++ b/frontend/src/computerMode.ts
@@ -1,4 +1,4 @@
-// "Local computer" vs "VM (isolated)": which computer kwant's browser and shell use.
+// "Local computer" vs "VM": which computer kwant's browser and shell use.
// Contract: GET/PUT /api/settings/computer (docs/browser-service.md)
export type ComputerMode = 'local' | 'vm';
@@ -16,13 +16,46 @@ export interface ComputerSettings {
available: Record<ComputerMode, boolean>;
reasons: Record<ComputerMode, string | null>;
window: LocalWindow;
+ /** What vm mode runs in containers, as the server reports it ("browser", "kwnt_shell", later "cli_agents"). */
+ isolates: string[];
}
-export const COMPUTER_MODES: { id: ComputerMode; label: string; short: string; hint: string }[] = [
- { id: 'local', label: 'Local computer', short: 'Local', hint: 'Uses your Chrome and your files.' },
- { id: 'vm', label: 'VM (isolated)', short: 'VM', hint: 'Runs in Docker containers, isolated from your files.' },
+/** What vm mode isolated before the server said so: never the CLI agents. */
+export const DEFAULT_VM_ISOLATES = ['browser', 'kwnt_shell'];
+
+const ISOLATED_PARTS: Record<string, string> = { browser: 'browser', kwnt_shell: 'built-in shell' };
+
+/** VM copy built from what it really isolates, so it can't promise more than the server does. */
+export function vmCopy(isolates: string[]): { label: string; hint: string; note: string | null } {
+ if (isolates.includes('cli_agents')) {
+ return { label: 'VM (isolated)', hint: 'Runs bots in Docker containers, away from your files.', note: null };
+ }
+ const parts = Object.keys(ISOLATED_PARTS).filter((k) => isolates.includes(k)).map((k) => ISOLATED_PARTS[k]);
+ return {
+ label: parts.length ? `VM (${parts.join(' and ')} isolated)` : 'VM',
+ hint: parts.length ? `The ${parts.join(' and ')} run in Docker containers, away from your files.` : 'Uses Docker containers.',
+ note: 'Claude, Codex and Grok still run on this computer, with their own file and shell tools.',
+ };
+}
+
+export interface ModeCopy {
+ id: ComputerMode;
+ label: string;
+ short: string;
+ hint: string;
+ /** A caveat shown under the hint. */
+ note: string | null;
+}
+
+export const COMPUTER_MODES: ModeCopy[] = [
+ { id: 'local', label: 'Local computer', short: 'Local', hint: 'Uses your Chrome and your files.', note: null },
+ { id: 'vm', short: 'VM', ...vmCopy(DEFAULT_VM_ISOLATES) },
];
+/** Both options, with the VM copy taken from what this server says it isolates. */
+export const computerModes = (s: ComputerSettings | null | undefined): ModeCopy[] =>
+ s ? COMPUTER_MODES.map((m) => (m.id === 'vm' ? { ...m, ...vmCopy(s.isolates) } : m)) : COMPUTER_MODES;
+
export const LOCAL_BROWSER_NOTE = "Your bots' Chrome is open as a window on your computer.";
/** Whether the browser is in its own window instead of the app's live view. */
@@ -62,17 +95,19 @@ export function parseComputerSettings(data: unknown): ComputerSettings | null {
available: w.available === true,
reason: typeof w.reason === 'string' && w.reason.trim() ? w.reason : null,
},
+ // Older servers don't send it; they isolated the same things.
+ isolates: Array.isArray(d.isolates) ? d.isolates.filter((x: unknown): x is string => typeof x === 'string') : DEFAULT_VM_ISOLATES,
};
}
export const otherMode = (m: ComputerMode): ComputerMode => (m === 'local' ? 'vm' : 'local');
-export const modeLabel = (m: ComputerMode) => COMPUTER_MODES.find((x) => x.id === m)!.label;
+export const modeLabel = (m: ComputerMode, s?: ComputerSettings | null) => computerModes(s).find((x) => x.id === m)!.label;
/** Why `mode` can't be picked right now, or null when it can. */
export function unavailableReason(settings: ComputerSettings, mode: ComputerMode): string | null {
if (settings.available[mode]) return null;
- return settings.reasons[mode] ?? `${modeLabel(mode)} isn't available on this computer.`;
+ return settings.reasons[mode] ?? `${modeLabel(mode, settings)} isn't available on this computer.`;
}
export interface SwitchState {
diff --git a/frontend/tests/browserPanel.test.mjs b/frontend/tests/browserPanel.test.mjs
index dcf803aa..411bddee 100644
--- a/frontend/tests/browserPanel.test.mjs
+++ b/frontend/tests/browserPanel.test.mjs
@@ -17,6 +17,7 @@ const settings = (mode, visible = false) => ({
available: { local: true, vm: true },
reasons: { local: null, vm: null },
window: { visible, available: true, reason: null },
+ isolates: ['browser', 'kwnt_shell'],
});
const pane = (props) =>
m.renderToStaticMarkup(m.createElement(m.VirtualMachinePane, { isOpen: true, onClose: () => {}, teamId: 'k1', screenshotBase64: 'AAAA', ...props }));
diff --git a/frontend/tests/computerMode.test.mjs b/frontend/tests/computerMode.test.mjs
index 1bab6490..459c9fd8 100644
--- a/frontend/tests/computerMode.test.mjs
+++ b/frontend/tests/computerMode.test.mjs
@@ -12,11 +12,12 @@ const m = await loadBundled(`
export { createElement } from 'react';
`);
-const settings = (mode, local = true, vm = true, reasons = {}, window = {}) => ({
+const settings = (mode, local = true, vm = true, reasons = {}, window = {}, isolates = ['browser', 'kwnt_shell']) => ({
mode,
available: { local, vm },
reasons: { local: null, vm: null, ...reasons },
window: { visible: false, available: false, reason: null, ...window },
+ isolates,
});
const api = (state, extra = {}) => ({ state, select: () => {}, dismissError: () => {}, setWindow: () => {}, windowPending: false, ...extra });
const render = (C, state) => m.renderToStaticMarkup(m.createElement(C, { api: api(state) }));
@@ -34,7 +35,7 @@ test('parseComputerSettings accepts the contract and rejects anything else', ()
test('unavailableReason uses the server reason, with a fallback', () => {
assert.equal(m.unavailableReason(settings('local', true, false, { vm: 'Docker is not installed' }), 'vm'), 'Docker is not installed');
- assert.match(m.unavailableReason(settings('local', true, false), 'vm'), /VM \(isolated\) isn't available/);
+ assert.match(m.unavailableReason(settings('local', true, false), 'vm'), /VM \(browser and built-in shell isolated\) isn't available/);
assert.equal(m.unavailableReason(settings('local'), 'vm'), null);
});
@@ -84,14 +85,38 @@ test('control: both available', () => {
assert.match(html, /aria-checked="true"[^>]*>.*Local computer/);
assert.match(html, /Uses your Chrome and your files\.</);
assert.doesNotMatch(html, /Commands ask/);
- assert.match(html, /Runs in Docker containers, isolated from your files\./);
+ assert.match(html, /VM \(browser and built-in shell isolated\)/);
+ assert.match(html, /The browser and built-in shell run in Docker containers, away from your files\./);
+ assert.match(html, /Claude, Codex and Grok still run on this computer, with their own file and shell tools\./);
+ assert.doesNotMatch(html, /VM \(isolated\)/);
assert.doesNotMatch(html, /disabled=""/);
assert.doesNotMatch(html, /Unavailable/);
});
+test('isolates: parsed from the server, honest default for older servers', () => {
+ const base = { mode: 'vm', available: { local: true, vm: true }, reasons: {} };
+ assert.deepEqual(m.parseComputerSettings({ ...base, isolates: ['browser', 'kwnt_shell', 7] }).isolates, ['browser', 'kwnt_shell']);
+ assert.deepEqual(m.parseComputerSettings(base).isolates, ['browser', 'kwnt_shell']);
+ assert.deepEqual(m.parseComputerSettings({ ...base, isolates: 'all' }).isolates, ['browser', 'kwnt_shell']);
+});
+
+test('VM copy follows what the server says it isolates', () => {
+ const now = m.vmCopy(['browser', 'kwnt_shell']);
+ assert.equal(now.label, 'VM (browser and built-in shell isolated)');
+ assert.match(now.note, /Claude, Codex and Grok still run on this computer/);
+ assert.equal(m.vmCopy(['browser']).label, 'VM (browser isolated)');
+ const full = m.vmCopy(['browser', 'kwnt_shell', 'cli_agents']);
+ assert.equal(full.label, 'VM (isolated)');
+ assert.equal(full.note, null);
+ const html = render(m.ComputerModeControl, ready(settings('vm', true, true, {}, {}, ['browser', 'kwnt_shell', 'cli_agents'])));
+ assert.match(html, /VM \(isolated\)/);
+ assert.doesNotMatch(html, /still run on this computer/);
+ assert.equal(m.modeLabel('vm'), 'VM (browser and built-in shell isolated)');
+});
+
test('control: one unavailable is disabled and says why', () => {
const html = render(m.ComputerModeControl, ready(settings('local', true, false, { vm: 'Docker is not installed' })));
- assert.match(html, /aria-disabled="true"[^>]*disabled=""[^>]*>.*VM \(isolated\)/);
+ assert.match(html, /aria-disabled="true"[^>]*disabled=""[^>]*>.*VM \(browser and built-in shell isolated\)/);
assert.match(html, /Unavailable: Docker is not installed/);
});
@@ -112,7 +137,7 @@ test('chip names the current mode and offers the other one', () => {
assert.match(vm, /Click to switch to Local computer/);
const blocked = render(m.ComputerModeChip, ready(settings('local', true, false, { vm: 'Docker is not installed' })));
assert.match(blocked, /disabled=""/);
- assert.match(blocked, /VM \(isolated\) is unavailable: Docker is not installed/);
+ assert.match(blocked, /VM \(browser and built-in shell isolated\) is unavailable: Docker is not installed/);
});
test('local note text', () => {
diff --git a/src/sandbox/computer.rs b/src/sandbox/computer.rs
index 2f49ad99..0cc2f684 100644
--- a/src/sandbox/computer.rs
+++ b/src/sandbox/computer.rs
@@ -12,6 +12,9 @@ pub const SETTING_KEY: &str = "computer_mode";
pub const MODE_ENV: &str = "KWNT_COMPUTER_MODE";
/// Path to the Chrome/Chromium binary local mode launches, instead of searching for one.
pub const CHROME_PATH_ENV: &str = "KWNT_CHROME_PATH";
+/// What vm mode actually runs in containers. The CLI drivers (Claude, Codex, Grok) and their own
+/// file and shell tools still run on the host; `cli_agents` joins this list once they move.
+pub const VM_ISOLATES: [&str; 2] = ["browser", "kwnt_shell"];
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
diff --git a/src/server/computer.rs b/src/server/computer.rs
index dc8bea21..962fdaf9 100644
--- a/src/server/computer.rs
+++ b/src/server/computer.rs
@@ -52,6 +52,7 @@ async fn view(state: &AppState) -> Value {
"mode": mode,
"available": {"local": local.is_none(), "vm": vm.is_none()},
"reasons": {"local": local, "vm": vm},
+ "isolates": computer::VM_ISOLATES,
"window": {
"visible": mode == ComputerMode::Local && state.browser_service.local_window(),
"available": window.is_none(),
diff --git a/tests/computer_mode_test.rs b/tests/computer_mode_test.rs
index 142844c9..aab158ca 100644
--- a/tests/computer_mode_test.rs
+++ b/tests/computer_mode_test.rs
@@ -118,6 +118,8 @@ async fn computer_mode_api_and_local_shell_approval() {
.unwrap()
.contains("KWNT_CHROME_PATH"));
assert_eq!(view["reasons"]["vm"], Value::Null);
+ // VM mode is honest about what it contains: not the Claude/Codex/Grok CLIs (yet).
+ assert_eq!(view["isolates"], json!(["browser", "kwnt_shell"]));
assert_eq!(view["window"]["visible"], false);
if cfg!(target_os = "linux") {
// no display: Chrome can still run in the app, just not as a window
@@ -149,6 +151,11 @@ async fn computer_mode_api_and_local_shell_approval() {
let (status, view) = call(&app, "PUT", Some(json!({"mode": "vm"}))).await;
assert_eq!(status, StatusCode::OK);
assert_eq!(view["mode"], "vm");
+ assert_eq!(
+ view["isolates"],
+ json!(["browser", "kwnt_shell"]),
+ "PUT returns the same shape"
+ );
assert_eq!(
db.get_setting("computer_mode").await.unwrap().as_deref(),
Some("vm")