π OpenHands: AI-Driven Development
docs: document dockerized dev setup as default (#232)
Robert Brennan157f394c62e0
diff --git a/AGENTS.md b/AGENTS.mdindex 5b4baba5a7..3eefc7c7fc 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -152,6 +152,8 @@- `ManageWorkspacesModal` should require a confirmation step before removing either a saved workspace or a workspace parent; parent removals should mention the child-workspace impact, and tests should assert both the confirmation flow and that removing the selected workspace clears the launch selection.- In `useWorkspacesStore`, keep `clearWorkspaces()` scoped to literal workspaces only; use explicit helpers like `clearWorkspaceParents()` / `clearAll()` for broader resets so future callers do not accidentally wipe parent registrations.+- Custom secrets are NOT auto-attached by the agent-server. `POST /api/conversations` only persists what the client sends in `request.secrets`; the persisted secrets store (`/api/settings/secrets`) is never read at conversation-start. `buildStartConversationRequestWithEncryptedSettings` enumerates `SecretsService.getSecrets()` and turns each entry into a `LookupSecret` whose `url` points back at `/api/settings/secrets/{name}` and whose `headers` carry `X-Session-API-Key` for auth. Pre-1.21.x agent-server SDKs would silently drop that header during validation when `secrets_encrypted=true` (the cipher in the validation context tried to `cipher.decrypt(plaintext_session_key)`, failed, and the validator removed the header β the conversation runtime then got 401s for every saved secret). The SDK fix preserves plaintext header values when decryption fails; if you still see saved secrets unavailable inside a conversation, verify the running agent-server bundles a `LookupSecret._validate_secrets` that falls back to plaintext on decrypt failure.+- Library packaging notes:- Public npm entrypoints now come from `src/index.ts` β `src/lib/index.ts`, with domain barrels under `src/components/{conversation,terminal,browser,files,settings,sidebar}/index.ts`.- `npm run build` remains the standalone app build (`react-router build`), while `npm run build:lib` runs `vite build` in library mode plus `tsc -p tsconfig.lib.json` to emit `.d.ts` files into `dist/`.diff --git a/README.md b/README.mdindex e291929adc..da26e9e388 100644--- a/README.md+++ b/README.md@@ -22,20 +22,40 @@ If you have questions or feedback, please open a GitHub issue or join the [#proj## Quickstart+### With Docker (recommended)+**Prerequisites**:- Node.js 22.12.x or later- `npm`-- `uv` (for running the agent server via `uvx`)+- Docker++Set `$PROJECT_PATH` to the directory on your machine where your projects live (e.g. `/path/to/your/projects`). The agent server will mount this directory so the agent can read and edit your code.++```sh+export PROJECT_PATH=/path/to/your/projects+git clone https://github.com/OpenHands/agent-canvas.git+cd agent-canvas+npm install+npm run dev:docker+```++Access the UI at [http://localhost:8000](http://localhost:8000)++### Without Docker> [!WARNING]> This runs the agent-server directly on the machine you're installing on--the agent will have full access to your filesystem!-> Stay tuned for docker sandboxing instructions.++**Prerequisites**:+- Node.js 22.12.x or later+- `npm`+- `uv` (for running the agent server via `uvx`)```shgit clone https://github.com/OpenHands/agent-canvas.gitcd agent-canvasnpm install-npm run dev+npm run dev:dangerously-dockerless```Access the UI at [http://localhost:8000](http://localhost:8000)diff --git a/package.json b/package.jsonindex e02ec5fe18..6dee5c0def 100644--- a/package.json+++ b/package.json@@ -51,10 +51,12 @@"zustand": "5.0.12"},"scripts": {- "dev": "npm run dev:automation",+ "dev": "npm run dev:docker",+ "dev:dangerously-dockerless": "npm run dev:automation","dev:safe": "node --env-file-if-exists=.env scripts/dev-safe.mjs","dev:extra-backend": "node --env-file-if-exists=.env scripts/dev-extra-backend.mjs","dev:automation": "node --env-file-if-exists=.env scripts/dev-with-automation.mjs",+ "dev:docker": "node --env-file-if-exists=.env scripts/dev-docker.mjs","dev:static": "node --env-file-if-exists=.env scripts/dev-static.mjs","dev:minimal": "node --env-file-if-exists=.env scripts/dev-safe.mjs","dev:frontend": "npm run make-i18n && cross-env VITE_MOCK_API=false react-router dev",diff --git a/scripts/dev-docker.mjs b/scripts/dev-docker.mjsnew file mode 100644index 0000000000..cc1d1d29b9--- /dev/null+++ b/scripts/dev-docker.mjs@@ -0,0 +1,214 @@+/**+ * Dockerized Development Stack+ *+ * Same as `dev-with-automation.mjs` (Vite + ingress + automation backend),+ * but runs the agent-server inside a Docker container instead of via `uvx`.+ *+ * The agent-server image listens on port 8000 inside the container; we map+ * it to the host's `agentServerPort` (default 18000) so the ingress proxy+ * and the secret-seeding step can reach it via http://localhost:18000.+ *+ * Required environment variables:+ * - PROJECT_PATH: Absolute host path to your projects. Mounted into the+ * container at /workspace/projects so the agent can read/edit your code.+ *+ * Optional environment variables:+ * - OH_AGENT_SERVER_GIT_REF: Git ref (branch/tag/SHA) of the agent-server+ * to use. Translates to the docker tag `${ref}-python`, e.g.+ * `main` -> `ghcr.io/openhands/agent-server:main-python`.+ *+ * Optional credential mounts (only mounted when the host path exists):+ * - ~/.openhands -> /home/openhands/.openhands (persistence)+ * - ~/.claude -> /home/openhands/.claude (Claude credentials)+ * - ~/.codex -> /home/openhands/.codex (Codex credentials)+ * - ~/.ssh -> /home/openhands/.ssh (git/ssh access)+ *+ * Usage:+ * PROJECT_PATH=/path/to/your/projects npm run dev:docker+ * OH_AGENT_SERVER_GIT_REF=main PROJECT_PATH=... npm run dev:docker+ */++import { spawnSync } from "node:child_process";+import { existsSync } from "node:fs";+import { homedir } from "node:os";+import { join } from "node:path";+import { fileURLToPath, pathToFileURL } from "node:url";+import process from "node:process";++import {+ c,+ commandExists,+ logError,+ logService,+ logSuccess,+ main,+ spawnService,+} from "./dev-with-automation.mjs";++// Docker image for the agent-server.+const AGENT_SERVER_REPO = "ghcr.io/openhands/agent-server";+// Default tag used when OH_AGENT_SERVER_GIT_REF is not set. Update to upgrade.+const DEFAULT_AGENT_SERVER_TAG = "d3f4851-python";+const CONTAINER_NAME = "agent-canvas-dev-agent-server";++// Default secret key matches dev-safe.mjs so persisted settings stay+// decryptable across docker / non-docker runs.+const DEFAULT_SECRET_KEY = "openhands-dev-secret-key-change-in-prod";++/**+ * Resolve the docker image to use based on environment.+ *+ * If OH_AGENT_SERVER_GIT_REF is set, use `${ref}-python` as the tag, mirroring+ * the publishing convention (e.g. `main` -> `main-python`, `abc1234` ->+ * `abc1234-python`). Otherwise fall back to the pinned default tag.+ */+function resolveAgentServerImage(env = process.env) {+ const gitRef = env.OH_AGENT_SERVER_GIT_REF;+ const tag = gitRef ? `${gitRef}-python` : DEFAULT_AGENT_SERVER_TAG;+ return `${AGENT_SERVER_REPO}:${tag}`;+}++function suggestDockerless() {+ logError("");+ logError(+ "If you'd rather not use Docker, you can run the agent-server directly with:",+ );+ logError(" npm run dev:dangerously-dockerless");+ logError(+ "Note: this runs the agent with full access to your filesystem.",+ );+}++/**+ * Check that the docker CLI is on PATH AND that the docker daemon is+ * actually responding. `commandExists("docker")` only verifies the binary is+ * installed, which is not enough -- on macOS / Windows the daemon may be+ * stopped, and on Linux the user may not have permissions to talk to it.+ */+function checkDockerPrereqs(config) {+ if (!commandExists("docker")) {+ logError("docker is required for dev:docker but was not found on PATH.");+ logError("Install Docker: https://docs.docker.com/get-docker/");+ suggestDockerless();+ process.exit(1);+ }+ logSuccess("docker found");++ // `docker info` exits non-zero (and writes to stderr) if the daemon+ // isn't reachable. Use a short timeout to avoid hanging.+ const info = spawnSync("docker", ["info"], {+ stdio: ["ignore", "ignore", "pipe"],+ timeout: 10_000,+ });+ if (info.status !== 0) {+ logError("docker is installed but the daemon does not appear to be running.");+ const stderr = info.stderr ? info.stderr.toString().trim() : "";+ if (stderr) {+ logError(` ${stderr.split("\n")[0]}`);+ }+ logError("Start Docker (e.g. open Docker Desktop) and try again.");+ suggestDockerless();+ process.exit(1);+ }+ logSuccess("docker daemon is running");++ if (!process.env.PROJECT_PATH) {+ logError("PROJECT_PATH is required for dev:docker.");+ logError("Set it to the directory containing your projects, e.g.:");+ logError(" export PROJECT_PATH=/path/to/your/projects");+ process.exit(1);+ }+ logSuccess(`PROJECT_PATH=${process.env.PROJECT_PATH}`);+}++function startAgentServerDocker(config) {+ const image = resolveAgentServerImage();+ logService(+ "agent-server",+ `Starting in Docker on port ${config.agentServerPort} (image: ${image})...`,+ c.blue,+ );++ // Best-effort cleanup of any leftover container from a previous run.+ spawnSync("docker", ["rm", "-f", CONTAINER_NAME], { stdio: "ignore" });++ const home = homedir();+ const dockerArgs = [+ "run",+ "--rm",+ "--name",+ CONTAINER_NAME,+ "--init",+ "-v",+ `${process.env.PROJECT_PATH}:/workspace/projects`,+ ];++ // Optional credential / state mounts. Only mount when the host path+ // exists so docker doesn't auto-create empty directories on the host.+ const optionalMounts = [+ [join(home, ".openhands"), "/home/openhands/.openhands"],+ [join(home, ".claude"), "/home/openhands/.claude"],+ [join(home, ".codex"), "/home/openhands/.codex"],+ [join(home, ".ssh"), "/home/openhands/.ssh"],+ ];+ for (const [src, dest] of optionalMounts) {+ if (existsSync(src)) {+ dockerArgs.push("-v", `${src}:${dest}`);+ }+ }++ // Map agent-server's in-container port (8000) to the host port the+ // ingress proxy expects.+ dockerArgs.push("-p", `${config.agentServerPort}:8000`);++ // Environment variables for the agent-server inside the container.+ // These mirror buildAgentServerEnv() from dev-safe.mjs but use paths+ // that exist inside the container (under the mounted ~/.openhands).+ const containerEnv = {+ OH_CONVERSATIONS_PATH:+ "/home/openhands/.openhands/agent-canvas/conversations",+ OH_PERSISTENCE_DIR: "/home/openhands/.openhands",+ OH_BASH_EVENTS_DIR:+ "/home/openhands/.openhands/agent-canvas/bash_events",+ TMUX_TMPDIR: "/home/openhands/.openhands/agent-canvas/tmux",+ OH_SECRET_KEY: process.env.OH_SECRET_KEY || DEFAULT_SECRET_KEY,+ // Required so the secret-seeding PUT /api/settings/secrets call from+ // the host can authenticate against the agent-server in the container.+ OH_SESSION_API_KEYS_0: config.sessionApiKey,+ };+ for (const [k, v] of Object.entries(containerEnv)) {+ dockerArgs.push("-e", `${k}=${v}`);+ }++ dockerArgs.push(image);++ spawnService("agent-server", "docker", dockerArgs, {+ color: c.blue,+ });+}++const isMainModule =+ process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href;++if (isMainModule) {+ main({+ bannerTitle: "Agent Canvas + Automation Development Stack (Docker)",+ extraPrereqs: checkDockerPrereqs,+ startAgentServer: startAgentServerDocker,+ }).catch((err) => {+ logError(`Fatal error: ${err.message}`);+ if (err.stack) {+ console.error(c.dim + err.stack + c.reset);+ }+ process.exit(1);+ });+}++export {+ AGENT_SERVER_REPO,+ CONTAINER_NAME,+ DEFAULT_AGENT_SERVER_TAG,+ checkDockerPrereqs,+ resolveAgentServerImage,+ startAgentServerDocker,+};diff --git a/scripts/dev-with-automation.mjs b/scripts/dev-with-automation.mjsindex 07feb2c436..b2c3811265 100644--- a/scripts/dev-with-automation.mjs+++ b/scripts/dev-with-automation.mjs@@ -684,15 +684,26 @@ function printBanner(config) {console.log("");}-async function main() {+async function main(options = {}) {+ const {+ bannerTitle = "Agent Canvas + Automation Development Stack",+ startAgentServer: startAgentServerOverride,+ extraPrereqs,+ } = options;+const args = parseArgs();console.log("");- console.log(`${c.cyan}${c.bold}Agent Canvas + Automation Development Stack${c.reset}`);+ console.log(`${c.cyan}${c.bold}${bannerTitle}${c.reset}`);console.log("");// Setup phase+ // (uvx is still required even in docker mode because the automation+ // backend runs via uvx; only the agent-server is dockerized.)checkPrerequisites();+ if (typeof extraPrereqs === "function") {+ extraPrereqs(config);+ }// Build config with dynamic port allocationconst config = await buildConfig(args);@@ -702,7 +713,8 @@ async function main() {logStep("2/2", "Starting services...");// 1. Start agent-server first (other services depend on it)- startAgentServer(config);+ const agentServerStarter = startAgentServerOverride ?? startAgentServer;+ agentServerStarter(config);// Wait for agent-server to be ready (60s timeout for slow systems)const agentServerReady = await waitForService(@@ -746,6 +758,14 @@ export {buildAutomationCommand,buildConfig,generateRandomApiKey,+ main,+ spawnService,+ commandExists,+ logService,+ logStep,+ logSuccess,+ logError,+ c,DEFAULT_AUTOMATION_REPO,DEFAULT_AUTOMATION_PACKAGE,DEFAULT_AUTOMATION_VERSION,