Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ silo start [--policy <file>] [--rebuild] [--name <agent>] [--workspace <path>] [
| `-p, --policy <file>` | string | from onboard | Path to a YAML policy file |
| `--rebuild` | boolean | `false` | Rebuild the sandbox image before starting |
| `-n, --name <agent>` | string | from config | Name the agent (creates container `silo-<name>`) |
| `-w, --workspace <path>` | string | from config | Override the workspace path for this agent |
| `-w, --workspace <path>` | string | from config | Override the workspace path for this agent. `~` and relative paths are resolved to an absolute path; an empty value falls back to the config |
| `--desktop` | boolean | `false` | Mount the host Desktop at `/host/Desktop` |
| `--mount <spec>` | string | — | Mount a host path into `/host/...`, e.g. `~/Downloads:/host/Downloads:ro` |
| `-f, --framework <name>` | string | — | Start with a specific framework (uses framework image) |
Expand Down Expand Up @@ -160,6 +160,8 @@ Capability profiles are additive:
silo stop — shut down the sandbox
```

**Workspace mount:** `/workspace` is bind-mounted from the configured folder, which must already exist (as with `--mount`). `~` is expanded. A relative path saved in the config is refused, because the folder it points to would depend on where you run `silo start`; set an absolute path instead. Older configs could hold a bare name such as `ws`, which Docker mounts as the *named volume* `ws`. If that volume exists, `start` keeps mounting it and prints how to move the files to a host folder.

---

### `silo stop`
Expand Down
22 changes: 10 additions & 12 deletions src/commands/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { resolve } from "node:path";
import { execa } from "execa";
import { readConfig, configPath } from "../config/manager.js";
import { log, printBanner, section } from "../utils/logger.js";
import { resolveWorkspaceMount } from "../utils/workspace.js";
import { isContainerRunning, containerExists } from "../utils/system.js";
import { isProxyAlive, readPid } from "../utils/pid.js";
import { proxyLogPath } from "../proxy/spawn.js";
Expand Down Expand Up @@ -331,19 +332,16 @@ export async function runDoctor(): Promise<void> {
}

// ── 9. Workspace ──────────────────────────────────────────────────────
if (existsSync(config.sandbox.workspacePath)) {
results.push({
name: "Workspace",
status: "pass",
message: config.sandbox.workspacePath,
});
// Check what `silo start` would actually mount, so a config saved with
// "~/…" isn't reported missing, a bare name that is really a Docker volume
// is recognised, and the mkdir hint uses the expanded path.
const workspace = await resolveWorkspaceMount(undefined, config.sandbox.workspacePath);
if (!workspace.ok) {
results.push({ name: "Workspace", status: "warn", message: workspace.error, fix: workspace.hint });
} else if (workspace.volume) {
results.push({ name: "Workspace", status: "warn", message: workspace.warning ?? workspace.source, fix: workspace.hint });
} else {
results.push({
name: "Workspace",
status: "warn",
message: `Directory does not exist: ${config.sandbox.workspacePath}`,
fix: `Create it with: mkdir -p "${config.sandbox.workspacePath}"`,
});
results.push({ name: "Workspace", status: "pass", message: workspace.source });
}

reportResults(results);
Expand Down
6 changes: 5 additions & 1 deletion src/commands/onboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { writeConfig, readConfig } from "../config/manager.js";
import type { SiloConfig, LLMProvider } from "../config/schema.js";
import { log, section } from "../utils/logger.js";
import { assertDockerAvailable } from "../utils/system.js";
import { expandHostPath } from "../utils/paths.js";
import {
defaultPolicyPath,
writePolicyFile,
Expand Down Expand Up @@ -316,7 +317,7 @@ export async function runOnboard(opts: { force: boolean }): Promise<void> {
section("Step 4 — Workspace");

const defaultWorkspace = join(homedir(), "silo-workspace");
const { workspacePath } = await inquirer.prompt<{ workspacePath: string }>([
const { workspacePath: workspaceAnswer } = await inquirer.prompt<{ workspacePath: string }>([
{
type: "input",
name: "workspacePath",
Expand All @@ -326,6 +327,9 @@ export async function runOnboard(opts: { force: boolean }): Promise<void> {
v.trim().length > 0 ? true : "Path cannot be empty.",
},
]);
// The prompt returns the text as typed: expand ~ and make it absolute, or
// mkdir creates a literal "./~/…" and Docker can't bind-mount it.
const workspacePath = expandHostPath(workspaceAnswer.trim());

log.blank();
section("Step 5 — Resource Limits");
Expand Down
26 changes: 17 additions & 9 deletions src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import chalk from "chalk";
import { execa } from "execa";
import { existsSync } from "node:fs";
import { homedir } from "node:os";
import { join, resolve } from "node:path";
import { join } from "node:path";
import { readConfig, patchConfig } from "../config/manager.js";
import { startContainer } from "../docker/runner.js";
import { SILO_NETWORK } from "../docker/templates.js";
Expand All @@ -25,6 +25,8 @@ import {
import type { FrameworkDefinition } from "../frameworks/registry.js";
import type { HostMount, IntegrationConfig } from "../config/schema.js";
import { applyPreset, getPreset } from "../policy/presets.js";
import { expandHostPath } from "../utils/paths.js";
import { resolveWorkspaceMount } from "../utils/workspace.js";

interface StartOptions {
policy?: string;
Expand Down Expand Up @@ -84,6 +86,16 @@ export async function runStart(opts: StartOptions): Promise<void> {
process.exit(1);
}

// ── Resolve the workspace mount ──────────────────────────────────────────
const workspace = await resolveWorkspaceMount(opts.workspace, config.sandbox.workspacePath);
if (!workspace.ok) {
log.error(workspace.error);
log.info(workspace.hint);
process.exit(1);
}
if (workspace.warning) log.warn(workspace.warning);
if (workspace.hint) log.info(workspace.hint);

// ── Guard: already running ───────────────────────────────────────────────
if (await isContainerRunning(containerName)) {
log.warn(`Sandbox "${containerName}" is already running.`);
Expand Down Expand Up @@ -131,7 +143,9 @@ export async function runStart(opts: StartOptions): Promise<void> {
containerName,
image,
memoryLimit: browserMemory.memoryLimit,
...(opts.workspace ? { workspacePath: opts.workspace } : {}),
// Becomes `-v <source>:/workspace`: an absolute host folder, or an existing
// named volume from an older config (see resolveWorkspaceMount).
workspacePath: workspace.source,
...(opts.policy ? { policyFile: opts.policy } : {}),
...(hostMounts.length > 0 ? { hostMounts } : {}),
...(framework ? { activeFramework: framework.id } : {}),
Expand Down Expand Up @@ -165,7 +179,7 @@ export async function runStart(opts: StartOptions): Promise<void> {
}

log.info(`Agent: ${chalk.dim(containerName)}`);
log.info(`Workspace: ${chalk.dim(effectiveSandbox.workspacePath)}`);
log.info(`Workspace: ${chalk.dim(effectiveSandbox.workspacePath)}${workspace.volume ? chalk.dim(" (Docker volume)") : ""}`);
if (opts.browser) {
log.info(`Browser: ${chalk.dim("enabled (Chromium inside sandbox)")}`);
log.info(`Memory: ${chalk.dim(effectiveSandbox.memoryLimit)}${browserMemory.bumped ? chalk.dim(` (auto-raised for browser mode from ${config.sandbox.memoryLimit})`) : ""}`);
Expand Down Expand Up @@ -426,12 +440,6 @@ function parseHostMountSpec(spec: string): HostMount {
return { source, target, mode };
}

function expandHostPath(path: string): string {
if (path === "~") return homedir();
if (path.startsWith("~/")) return resolve(homedir(), path.slice(2));
return resolve(path);
}

export function ensureBrowserMemoryLimit(memoryLimit: string): {
memoryLimit: string;
bumped: boolean;
Expand Down
5 changes: 4 additions & 1 deletion src/commands/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { readConfig, configPath } from "../config/manager.js";
import { inspectContainer, containerStats } from "../docker/runner.js";
import { log, printBanner, section } from "../utils/logger.js";
import { isContainerRunning, containerExists } from "../utils/system.js";
import { expandHome } from "../utils/paths.js";
import { isProxyAlive, readPid, pidFilePath } from "../utils/pid.js";
import { readAuditLog, auditLogPath, getSessionId } from "../audit/audit.js";

Expand Down Expand Up @@ -65,7 +66,9 @@ export async function runStatus(): Promise<void> {
["Container", containerName],
["Status", statusLabel],
["Image", image],
["Workspace", chalk.dim(config.sandbox.workspacePath)],
// Expand ~ to match what `silo start` mounts; a relative legacy value is
// shown as stored (start refuses it rather than guessing a base folder).
["Workspace", chalk.dim(expandHome(config.sandbox.workspacePath))],
["CPU limit", config.sandbox.cpuLimit],
["Memory limit", config.sandbox.memoryLimit],
);
Expand Down
37 changes: 37 additions & 0 deletions src/utils/paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Host path helpers.
*/
import { homedir } from "node:os";
import { join, resolve } from "node:path";

/**
* Expand a leading `~` to the home directory, the way a shell would, and
* leave everything else untouched. Covers `~`, `~/x` and Windows-style `~\x`.
* `~user/x` is not expanded.
*/
export function expandHome(path: string): string {
if (path === "~") return homedir();
if (/^~[\\/]/.test(path)) return join(homedir(), path.slice(2));
return path;
}

/**
* Turn a user-supplied host path into the absolute path Docker needs.
*
* Expands a leading `~` (a shell would, but prompts, flags read from config
* and YAML don't) and resolves relative paths against the current directory.
* Docker rejects a `~/…` bind-mount source and treats a bare name such as `ws`
* as a named volume, so a raw path either fails or silently mounts something
* other than the host folder the user meant.
*/
export function expandHostPath(path: string): string {
return resolve(expandHome(path));
}

/**
* True when Docker would read this `-v` source as a named volume rather than
* a host path: its rule for local volume names is `[a-zA-Z0-9][a-zA-Z0-9_.-]*`.
*/
export function isVolumeName(path: string): boolean {
return /^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/.test(path);
}
12 changes: 12 additions & 0 deletions src/utils/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ export async function containerExists(name: string): Promise<boolean> {
}
}

/**
* Returns true if a Docker named volume with the given name exists.
*/
export async function dockerVolumeExists(name: string): Promise<boolean> {
try {
await execa("docker", ["volume", "inspect", name], { stdio: "ignore" });
return true;
} catch {
return false;
}
}

/**
* Returns the current Node.js version as a semver string.
*/
Expand Down
80 changes: 80 additions & 0 deletions src/utils/workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Deciding what `silo start` mounts at /workspace.
*/
import { existsSync } from "node:fs";
import { isAbsolute, resolve } from "node:path";
import { expandHome, isVolumeName } from "./paths.js";
import { dockerVolumeExists } from "./system.js";

export type WorkspaceMount =
| {
ok: true;
/** The `-v <source>:/workspace` source: an absolute path, or a volume name. */
source: string;
/** True when `source` is an existing Docker named volume, not a host folder. */
volume: boolean;
/** Set when the caller should tell the user something about the mount. */
warning?: string;
hint?: string;
}
| { ok: false; error: string; hint: string };

/**
* Work out the workspace mount from `--workspace` and the configured path.
*
* - A non-empty `--workspace` wins. An empty one (`-w "$WS"` with `WS` unset)
* falls back to the config rather than resolving to the current directory.
* - `~` forms are expanded and absolute paths are used as they are. The folder
* must already exist, as `--mount` sources must: on Linux, Docker would
* otherwise create it owned by root, and the sandbox user can't write to it.
* - A bare name such as `ws` used to reach Docker unchanged, which mounts the
* named volume `ws`. If that volume exists, the user's files are in it, so
* keep mounting it and say so, rather than switching to an empty folder.
* - Any other relative path in the config has no reliable base directory (it
* depends on where `silo start` runs), so ask for an absolute path instead.
* On the command line, a relative path is resolved against the current
* directory, which is what a shell user means.
*/
export async function resolveWorkspaceMount(
flag: string | undefined,
configured: string,
volumeExists: (name: string) => Promise<boolean> = dockerVolumeExists,
): Promise<WorkspaceMount> {
const fromFlag = Boolean(flag);
const raw = flag || configured;
const expanded = expandHome(raw);

if (!isAbsolute(expanded)) {
if (isVolumeName(raw) && (await volumeExists(raw))) {
return {
ok: true,
source: raw,
volume: true,
warning:
`Workspace "${raw}" is a Docker named volume, not a host folder. Earlier SILO ` +
`versions mounted bare names this way, so your files are in that volume. Still mounting it.`,
hint:
`To move to a host folder, copy the files out ` +
`(docker run --rm -v ${raw}:/from -v /path/to/folder:/to alpine cp -a /from/. /to/) ` +
`and set that folder as the workspace.`,
};
}
if (!fromFlag) {
return {
ok: false,
error: `The workspace path in your config, "${raw}", is relative, so the folder it points to depends on where you run silo.`,
hint: "Set an absolute path: re-run `silo onboard --force`, or pass `--workspace /path/to/folder`.",
};
}
}

const source = resolve(expanded);
if (!existsSync(source)) {
return {
ok: false,
error: `Workspace folder does not exist: ${source}`,
hint: `Create it with: mkdir -p "${source}"`,
};
}
return { ok: true, source, volume: false };
}
Loading
Loading