mhl42.ai · MHL Academy · Set up a Linux computer for coding agents · December 2026
Mostly Harmless · MHL · 42

MHL Academy · Guide 03

Set up a Linux computer for coding agents

A practical setup for a developer who works alone and for a small team. It prepares an Ubuntu or Fedora workstation for AI coding agents such as Claude Code and Codex. Each step limits the damage if the agent or the computer is compromised.

01The short version

An AI coding agent is a program in which an AI model reads files, runs commands and changes code. Claude Code and Codex are examples. On a normal Linux workstation, the agent runs with your user account. Thus it can read each file that you can read. It can also use each key that it finds, which is a secret text that gives access to a service.

This guide puts limits around the agent. The limits are in the operating system and in settings files, because hostile text can override an instruction.

If this agent obeys an attacker at this moment, what can it read, what can it change, and where can it send data?

The central assumption is: assume a breach. Plan as if the agent already obeys an attacker, and as if the computer already runs malicious software. An agent reads web pages, tickets and package files, and a sentence in them can change what it does. This attack is named prompt injection, and no product stops it reliably. Each step below makes the answer to the test question smaller.

  1. Prepare the computer with updates, disk encryption, a screen lock and a firewall.
  2. Give the agent its own user account and one projects folder.
  3. Turn on the sandbox, which lets the operating system limit files and network.
  4. Use a separate system for unattended work.
  5. Move each secret to a password manager or a hardware security key.
  6. Delay new package versions, and review the files that steer the agent.
  7. Put the settings in a file that the agent cannot change.

The commands are for current Ubuntu and Fedora versions with the GNOME desktop. We tested no product. The statements come from vendor documentation on 4 December 2026.

THE LINUX COMPUTERPersonal accountmail and documentsbrowser sessionssaved passwordsAGENT ACCOUNT (NO SUDO RIGHTS)SANDBOX (BUBBLEWRAP)Coding agentruns commandsProject folderread and writeKey files and other foldersrules block the accessNETWORKPermitted hostsa proxy compares eachhost with a listSECRETS STAY OUTSIDEPassword managerHardware security key
Figure 1. The boundaries of this guide on a Linux computer. The agent can write only to the project folder. The personal data, the key files and the secrets stay outside its reach.

02Prepare the computer

These settings do not depend on the agent. They limit what a thief, a person on the same network or malicious software can get.

  • Updates. Old software has known faults. Ubuntu installs security updates automatically Ubuntu. Fedora needs one more package and the line apply_updates = True in the section [commands] of the file /etc/dnf/automatic.conf DNF.
  • Disk encryption. Encryption protects the data of a lost computer. The Linux method is LUKS (Linux Unified Key Setup), and you select it in the installer Ubuntu; Fedora. It gives no protection while you are signed in.
  • Screen lock. In the GNOME settings, open "Privacy & Security" and then "Screen Lock". Turn on "Automatic Screen Lock" GNOME.
  • Firewall. A firewall blocks connections that other computers start. The Ubuntu tool ufw is off by default Ubuntu. Fedora uses the tool firewalld by default firewalld.
  • Network services. A service is a background program. Stop each service that waits for connections and that you do not use.
  • No daily work as root. The account root is the administrator, and the command sudo gives its rights to one command. Do not start an agent with sudo. The group docker of the software Docker also gives root-level rights Docker, so keep the agent out of it.
# Ubuntu
sudo unattended-upgrade -v --dry-run       # Show the next automatic run.
sudo ufw enable                            # Turn on the firewall.
sudo ufw status verbose                    # The status must show "deny (incoming)".

# Fedora
sudo dnf install dnf5-plugin-automatic             # Install the automatic update tool.
sudo systemctl enable --now dnf5-automatic.timer   # Start its timer.
sudo firewall-cmd --list-all                       # List the permitted services and ports.

# Ubuntu and Fedora
lsblk -f                                    # An encrypted disk shows "crypto_LUKS".
sudo ss -tulpn                              # List programs that wait for connections.
sudo systemctl disable --now NAME.service   # Stop one service permanently.
id                                          # List the groups of your account.

If lsblk shows no crypto_LUKS partition, plan a new installation with encryption. Keep a copy of the passphrase outside this computer. Restart the computer after an update of the kernel, the core of the operating system.

03Separate agent work from personal data

Linux separates one user account from another, but not the programs of one account. Thus give the agent its own account. A separate computer or a virtual machine separates more. A virtual machine is a full second computer that runs as a program.

sudo useradd --create-home --shell /bin/bash agent   # Create the account "agent".
sudo chmod 700 /home/agent                           # Close its home folder to other accounts.
chmod 700 "$HOME"                                    # Close your home folder to other accounts.
sudo -iu agent                                       # Open a shell as "agent".

The account agent has no password, so nobody can sign in to it directly. It cannot read your home folder, your keys, your keyring or your browser profile. Do not add it to the groups sudo, wheel or docker, which give administrator rights. Sign in to the AI product again in this account. Clone the repositories with a key of the agent, and review its work as a branch on the code host.

If your editor must open the same files as the agent, use your own account with the sandbox. These rules apply in each option.

  • One projects folder. Keep all repositories in one folder, for example ~/projects. Start the agent inside one project folder.
  • Not the home folder, not Downloads. A sandboxed command can write to the start folder, and the agent loads instruction files from it. Do not start it in your home folder or in ~/Downloads BleepingComputer.
  • A separate browser profile. A browser profile holds the open sessions of your mailbox, your bank and your code host. Use a second profile with no sign-in for development and for browser agents Anthropic.

04Turn on the sandbox

A sandbox is an enclosed work area that the operating system enforces. Inside it, a command can change only the permitted folders and connect only to the permitted sites. On Linux, Claude Code and Codex build the sandbox with the tool bubblewrap. Claude Code also needs socat, which sends network traffic to a filter Claude Code; Codex.

sudo apt-get install bubblewrap socat   # Ubuntu
sudo dnf install bubblewrap socat       # Fedora

The sandbox of Claude Code is off by default. If a package is missing, Claude Code runs the commands with no sandbox. Put this example in the user settings file, ~/.claude/settings.json.

{
  "sandbox": {
    "enabled": true,
    "failIfUnavailable": true,
    "allowUnsandboxedCommands": false,
    "network": { "allowedDomains": ["github.com", "registry.npmjs.org"] },
    "filesystem": { "denyRead": ["~/.ssh", "~/.aws"] }
  },
  "permissions": {
    "disableBypassPermissionsMode": "disable",
    "blockReadsOutsideWorkingDirectories": true,
    "deny": ["Read(~/.ssh/**)", "Read(~/.aws/**)", "Read(./.env)", "Read(./.env.*)"]
  }
}
  • enabled and failIfUnavailable. The sandbox is on. If it cannot start, Claude Code stops.
  • allowUnsandboxedCommands. The agent cannot repeat a failed command outside the sandbox.
  • allowedDomains. A filter on your computer permits only these sites.
  • denyRead. By default, a command can read most of the computer, also ~/.ssh. Add each folder that holds keys, but only folders that exist.
  • deny and blockReadsOutsideWorkingDirectories. The sandbox covers shell commands only. These settings limit the file tools of the agent. The second setting needs version 2.1.257 or later Claude Code.

Enter /sandbox in Claude Code to see the status. Then ask the agent to run ls ~/.ssh. The command must fail.

On Ubuntu, the security function AppArmor can stop bubblewrap. Add the AppArmor profile that the documentation of your agent gives Claude Code; Codex. Do not use the sysctl command that removes the restriction for all programs.

Codex uses its sandbox by default. A command can write to the project folder, and the network is off Codex. Make these defaults explicit in the file ~/.codex/config.toml. As a test, codex sandbox linux runs one command inside the sandbox.

sandbox_mode = "workspace-write"
approval_policy = "on-request"

[sandbox_workspace_write]
network_access = false

The sandbox does not cover the items below Claude Code.

  • File tools and web tools. In Claude Code, the tools Read, Edit, Write and WebFetch run outside the sandbox. Permission rules limit them.
  • Local MCP servers and hooks. An MCP server is a program that gives the agent more tools. A hook is a script that runs at a fixed event. Both run with the full access of your account.
  • Permitted sites. The filter reads only the name of a site, so each permitted site is a possible exit for data.
  • Plain ssh. It does not work in the sandbox of Claude Code. Let the agent commit, and do the push yourself.
  • Codex. Its network filter does not cover web search or the connections of MCP servers Codex.

05Use a stronger boundary for unattended work

Unattended work means that no person approves the steps. Each tool has a flag for this: --dangerously-skip-permissions in Claude Code and --dangerously-bypass-approvals-and-sandbox in Codex. Do not use these flags on your work computer. The malicious Nx packages of August 2025 used exactly these flags Snyk. Anthropic states that the built-in sandbox alone is not sufficient for unattended runs Claude Code. Put the full agent process inside a boundary that it cannot change.

Boundary What it separates Limits on Linux
Docker Sandboxes Each agent gets a small virtual machine (microVM) and sees only the project folder. A filter on the host holds the real keys Docker. Local use is free. It needs Ubuntu 24.04 or later with KVM, the virtual machine function of Linux. Fedora is not on the list Docker.
A virtual machine It is a full second system with its own kernel. The agent can reach each key that you copy into it.
A container It has its own files and processes, but it uses the kernel of the host. A kernel fault can open it. Do not give it your home folder or the control interface of Docker.
A cloud session The agent runs on a computer of the vendor. Your code leaves your computer. Claude Code keeps the GitHub keys outside the session Claude Code.

Install the tool sbx as Docker describes Docker. The command claude --cloud starts a cloud session of Claude Code.

sudo usermod -aG kvm $USER         # Add your account to the group "kvm". Sign in again.
sbx login                          # Sign in to Docker.
sbx run --name my-sandbox claude   # Start Claude Code in the current project folder.

06Protect keys and secrets

A secret in a file is available to each program that runs with your account, and the agent is one of them. Move each secret to a place that needs a person or a piece of hardware.

  • Password manager. A password manager keeps secrets in an encrypted store. With the command-line tool of 1Password, a .env file contains only references such as op://vault/item/field. The command op run gives the values to one program while it runs 1Password. Do not start the agent itself with op run.
  • Hardware security key. This small USB device proves your identity to a service. Its main value here is isolation: the key makes its secret inside the device, and no software can copy it. Each use needs a touch. Thus malicious software gets no credential that works later or on a different computer. Register two keys for each important account. One limit stays: malicious software can use a session that is already open.
  • SSH key on the hardware key. SSH is the protocol that sends code to the code host. A normal private key is a file in ~/.ssh that software can copy. With the type ed25519-sk, the private part stays on the hardware key, and the file is of no use alone GitHub; OpenSSH.
  • Desktop keyring. GNOME Keyring stores passwords and tokens, which are secret texts that work as keys. It does not separate the programs of one desktop session GNOME. Thus an agent in your account can ask it for a secret. The account agent has its own keyring.
  • No secrets in .env files. A deny rule does not stop a script that opens the file itself Claude Code. Move the keys to the password manager.
  • Git credentials. The git helper store keeps your password unencrypted in ~/.git-credentials Git. Give the agent a fine-grained token for named repositories, with an expiry date GitHub.
op run --env-file=.env -- npm start         # Give the secrets to "npm start" only.
ssh-keygen -t ed25519-sk -C "work laptop"   # Make an SSH key on the hardware key.
find ~/projects -name ".env*"               # Find files that can hold keys.
git config --global credential.helper       # "store" means an unencrypted file.

07Control what the agent installs and loads

An agent installs packages and loads tools. Each of them is code from another person.

In 2026, malicious versions of the packages TanStack and LiteLLM were online for some hours before their removal TanStack. A waiting period of one day excludes such versions npm; pnpm; uv.

# ~/.npmrc (npm, the unit is days)
min-release-age=1

# pnpm-workspace.yaml (pnpm, the unit is minutes)
minimumReleaseAge: 1440

# ~/.config/uv/uv.toml (uv, a duration)
exclude-newer = "24 hours"

A local MCP server runs outside the sandbox. Write its exact version in the file .mcp.json, so that a start cannot load a new version. In an interactive session, Claude Code asks for approval before it uses a server from this file Claude Code.

{
  "mcpServers": {
    "docs": { "command": "npx", "args": ["-y", "@example/docs-server@1.4.2"] }
  }
}

The files CLAUDE.md, AGENTS.md and .mcp.json and the folder .claude/ steer the agent, and some of them can run code. Read them before you start an agent in a repository from another person. In a team, require a review for each change. This command shows the changes.

git log --stat -- CLAUDE.md AGENTS.md .mcp.json .claude/

An extension of the editor VS Code has the same rights as the editor VS Code. Install an extension only from a publisher that you can identify.

08Settings for a team

A developer or a tricked agent can change a user settings file. Managed settings are in a place that the daily account cannot change. A team of one person can use them too.

Claude Code reads the file /etc/claude-code/managed-settings.json, and no user file or project file can override it Claude Code. Save the settings example as managed-settings.json, and install it with root as the owner. Then /status in Claude Code shows that the file is loaded. An account with administrator rights can edit the file, but the account agent cannot.

sudo install -D -m 644 -o root -g root managed-settings.json /etc/claude-code/managed-settings.json

For a team, add allowManagedPermissionRulesOnly and allowManagedMcpServersOnly. Then only the rules and the MCP servers of the managed file apply.

Codex reads the file /etc/codex/requirements.toml. This example permits only the two safer sandbox modes Codex.

allowed_approval_policies = ["untrusted", "on-request"]
allowed_sandbox_modes = ["read-only", "workspace-write"]

A team has three light options to bring the settings to each computer.

  • The organisation console. On Claude Team and Claude Enterprise, an owner enters the same settings under "Claude Code" and "Managed settings". Claude Code gets them at each start and each hour. Codex has "Agent security" in its Admin Console.
  • A copy by hand. One person installs the file and checks it each month. Anthropic states that a file which the operating system protects gives stronger guarantees than the console Claude Code.
  • Ansible. This tool copies a file with a set owner to many computers Ansible.

09Things to avoid

  • Do not start an agent with sudo or in the account root.
  • Do not use a flag that bypasses the permission checks on your work computer.
  • Do not keep the account that runs agents in the group docker.
  • Do not turn off the firewall or the security functions AppArmor and SELinux for a tool.
  • Do not put a key in a prompt, in a .env file or in the file ~/.bashrc.
  • Do not run a command from a web page or from an agent with sudo before you read it.

10If something suspicious occurs

Examples are a command that reads key folders, a connection to an unknown site, or an unexpected sign-in notice. Do the steps in this order.

  1. Stop the agent, and stop your work on this computer.
  2. Disconnect the computer from the network. The command nmcli networking off does this.
  3. Leave the computer on, and lock the screen. Do not delete files.
  4. Use a different computer that you trust. Sign out all sessions of the code host, the AI product, the mailbox and the password manager.
  5. Cancel each key that was in a file or in the session of the agent. Start with the keys for production systems.
  6. A credential on a hardware key was not copied. But look in the records of each account for new keys, tokens and devices.
  7. If you cannot exclude malicious software, install the system again with encryption, and create new keys.
  8. In a team, tell the owner of the agent setup immediately.

11Monthly self-check

  • Automatic security updates, disk encryption, the screen lock and the firewall are on.
  • The account that runs agents is not in the groups sudo, wheel or docker.
  • The sandbox is on, and the command ls ~/.ssh fails for the agent.
  • The list of permitted sites contains only sites that the current projects need.
  • No project folder contains a .env file with a real key.
  • The SSH key for the code host is on a hardware key, and two hardware keys are registered.
  • Each token of the agent has an expiry date and is limited to named repositories.
  • The package managers have a waiting period, and each MCP server has a fixed version.
  • The managed settings file is in place, and root is its owner.

12Sources