Repository navigation
Run the agent as its own OS user on managed machines - #162
Merged
Merged
Conversation
Managed machines (one per organization) run moi and the agent as different OS users, so the agent can't change moi's config, stop it, or read what moi keeps for itself. This adds what moi needs for that, all off unless config.json says otherwise: - config.json gains workspacesDir, agentLauncher and unixSocket, read from the file only, with no env override. - Every agent process starts through agentLauncher: harness CLIs, Claude Code via the SDK's spawn hook, ACP agents, function workers, applet builds and dependency installs (server/agent-launcher.ts). - The web side can listen on a Unix socket file instead of port 13337, so only the machine's gateway reaches the API meant for people. - Chat titles run in a temp folder the agent owns. - The agent's moi CLI can't open moi's data folder: `moi env` and finding the current workspace go over the control port, and system commands refuse to run. The control port accepts workspace:register only from moi's own user, read from the socket owner in /proc/net/tcp. PUT /env and the control port share one env patch validator. See docs/managed-machine.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mz31v7KHhLQFK29pFBvMpQ
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 95065315ba
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
`moi status`, the `/status` page and the "already running" messages printed port 13337 even when the web side listens on the `unixSocket` file. The server now reports its socket in `server:info`, and the CLI prints it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mz31v7KHhLQFK29pFBvMpQ
The CLI no longer reads moi's data folder for `moi env`, `set`, `unset`, `exec` or finding the current workspace: it always asks the server over the control port. One path instead of two, writes take effect at once and go through the server's per-workspace queue, and the agent on a managed machine uses the same path as everyone else. These commands now need moi running; without it they say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mz31v7KHhLQFK29pFBvMpQ
No more `mktemp` through the agent launcher: moi makes the folder with mkdtemp and opens it to everyone, so the agent can work in it and Codex can write its answer there. moi stays the owner, so it can also remove the folder from /tmp, which the agent-owned folder didn't allow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mz31v7KHhLQFK29pFBvMpQ
Drop peer-user.ts and its /proc/net/tcp lookup. Before sending workspace:register, the CLI checks that it can open the folder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mz31v7KHhLQFK29pFBvMpQ
One page for every config.json option and when it's needed: the demo, Cloudflare Access, and the three managed-machine paths. It also says the agent launcher sets the agent's HOME. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mz31v7KHhLQFK29pFBvMpQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On a managed machine (one per organization, in the cloud) moi and the agent now run as different OS users. The agent can't change moi's config, stop or replace it, or read what moi keeps for itself, yet it keeps the whole
moiCLI except the system commands. Nothing changes for a local install: everything is off untilconfig.jsonsets it.The machine's start script writes this
config.jsonat every start:{ "workspacesDir": "/data/workspaces", "agentLauncher": "/opt/moi/bin/agent-run", "unixSocket": "/run/moi/web.sock" }agentLauncher: every agent process starts through it. That covers Claude Code (via the SDK's spawn hook), Codex, ACP agents, function workers, applet builds and installs.unixSocket: the web side listens on a socket file only the gateway can open, instead of port 13337.moi statusand the/statuspage show the socket then.moiCLI:moi envgoes over the control port, because the agent's user can't open moi's data folder.init,start,serviceandupdaterefuse to run. The control port takesworkspace:registeronly from moi's own user.Details are in docs/managed-machine.md.
Worth a close look
server/peer-user.tsfinds who is calling the control port by reading/proc/net/tcp. It runs only whenagentLauncheris set, and refuses when the owner can't be found.agentCommand()orclaudeCodeSpawn(). Otherwise it runs as moi's user.Tested:
bun test(2135 pass), typecheck, lint. New tests cover the config fields, the/proc/net/tcpparser, and the CLI when moi's data folder is closed. On a live machine, chats with real Claude and Codex sign-ins worked; the socket inmoi statuswas checked against a local server.🤖 Generated with Claude Code
https://claude.ai/code/session_01Mz31v7KHhLQFK29pFBvMpQ