# Pi Coding Agent: Local vs VPS Setup and Security

Choose where Pi should run, then establish a non-root, read-only first session with deliberate state, credentials and recovery boundaries.

Last updated: 2026-12-03

Pi Coding Agent can work on your development machine or in a remote environment you operate. The useful question is not whether a VPS makes Pi more capable. It is whether separating its workspace from your everyday machine gives you a clearer place to control access, preserve sessions and recover changes.

Choose local execution for work that belongs on your machine and benefits from direct supervision. Choose a self-managed VPS when the workspace should live independently of that machine and you are prepared to maintain the remote environment. In either case, Pi's access comes from the process and its surrounding controls, not from the folder you happen to open.

## What Pi can access

Pi's default tools include reading files, running shell commands and editing or writing files. It does not request approval before every tool call. Extensions execute with the Pi process's permissions too, so adding an extension is different from adding a harmless prompt template.

As of 30 September 2026, current Pi documentation includes built-in MCP support and Codemode. Codemode composes tool calls through JavaScript in a QuickJS sandbox. That constrains the JavaScript environment; it does not turn every tool it invokes into a restricted operating-system process. A tool that can reach a file or service still needs an appropriate boundary.

Keep three controls separate: project trust decides which project resources load, tool selection decides which tools the model receives, and OS or container isolation limits the process's reach. A trust prompt is not a per-action approval system. A read-only tool selection is not a filesystem allowlist. These distinctions matter when repository content tries to redirect the agent.

## Local Pi setup versus self-managed VPS Pi setup

The location changes what you have to operate and what a mistake can affect. It does not remove the need for isolation.

| Setup | Persistence and access | Workspace and secret exposure | Isolation boundary | Maintenance and recovery owner |
| --- | --- | --- | --- | --- |
| Local Pi setup | Sessions and files live on your machine; access follows that machine's availability. | Direct execution can reach files and credentials available to your local account. | Use a dedicated account or isolate the whole process; changing directories alone does not confine it. | You maintain Pi, its dependencies, local configuration and recoverable copies of the work. |
| Self-managed VPS Pi setup | The workspace lives on the remote host; you connect to that environment to work with it. | Expose only the intended project and required credentials, rather than copying your personal home directory. | Combine an unprivileged account with an explicit container or VM boundary and limited network access. | You maintain Pi and the remote OS, access controls, session storage, configuration and recovery process. |

Local execution is often the smaller operational commitment when you work interactively on one machine. Remote execution becomes useful when a separate environment is itself part of the requirement. A remote host still needs deliberate process management: saved sessions are not a promise that an active process survives a disconnected terminal, restart or failed update.

A VPS is also not a reason to move every credential into one place. Keep repository access, model-provider authentication and administrative access distinct. A coding task rarely needs the authority used to administer the host.

## Choose the execution mode before installing integrations

Interactive mode suits supervised coding: you can inspect tool activity, direct the next step and review a diff. Print mode suits a bounded scripted task that should return a result and exit. JSON event-stream mode provides structured events from a run when another program needs more than plain text.

RPC mode lets another program control a separate Pi process through its protocol. The TypeScript SDK embeds Pi in an application. Those choices move more responsibility into your surrounding software: it must authenticate callers, handle failures and decide which workspace and tools each request receives. Selecting RPC or an SDK is not an isolation policy.

Start with interactive, read-only work when introducing a remote workspace. Add automation after you can identify the process, storage and access boundary without relying on the model's description of them.

## Build a non-root, read-only first workspace

The official npm package is `@earendil-works/pi-coding-agent`, from the `earendil-works/pi` project. Its npm installation requires Node.js 22.19 or newer. The documented installation uses `--ignore-scripts`; normal installation does not require dependency lifecycle scripts.

The following path adapts Pi's whole-process Docker pattern. It starts on a reader-controlled Linux host with a working rootless Docker installation, a dedicated non-root login and a non-sensitive repository copy. It is a first-session setup, not a complete production security configuration. Rootless Docker keeps its daemon and containers unprivileged at the host boundary; the image below also runs Pi as its non-root `node` user.

Before proceeding, run `id -u` in your remote shell and inspect `docker info`. The account must not be root, and Docker's Security Options must include `rootless`. Stop if they do not. Do not substitute access to a privileged Docker socket for this prerequisite.

### Install Pi inside the image

In a new build directory containing no credentials or project files, save this as `Dockerfile`. It uses the Node 24 image family from Pi's container guide and a user-owned npm prefix. `USER node` applies to both the subsequent installation and the eventual Pi process.

```dockerfile
FROM node:24-bookworm-slim
ENV NPM_CONFIG_PREFIX=/home/node/.local
ENV PATH=/home/node/.local/bin:$PATH
USER node
RUN mkdir -p /home/node/.pi/agent/sessions \
    && chmod 700 /home/node/.pi/agent \
    && npm install -g --ignore-scripts @earendil-works/pi-coding-agent
WORKDIR /workspace
ENTRYPOINT ["pi"]
```

Build with `docker build -t pi-readonly .`. Continue only after a successful build, then run `docker run --rm pi-readonly --version` and record the installed version. Preserve the resulting image ID alongside that version before changing the installation. The package command installs Pi; it does not populate your project, select a model or establish recovery copies.

### Mount only the intended repository

Use a dedicated repository copy without secrets, nested mounts or sensitive linked content. The directory and files must be readable by the container's non-root user. Do not broaden permissions on an existing personal or production directory to make the example work; prepare the intended copy instead.

Run this in Bash on the same Linux host as the rootless Docker daemon. Enter the repository's absolute path when prompted. The function rejects the root directory, your complete home directory and unsupported path forms. Its named volume is reserved for this workspace; start with a new, unused `pi-readonly-state` volume name.

```bash
run_pi_readonly() {
  local repo
  read -r -p 'Absolute repository-copy path: ' repo || return 1
  [[ "$repo" == /* ]] || return 1
  repo=$(realpath -e -- "$repo") || return 1
  [[ -d "$repo" && "$repo" != / && "$repo" != "$HOME" \
     && "$repo" != *,* ]] || return 1

  docker run --rm --init -it --name pi-readonly \
    --mount "type=bind,src=$repo,dst=/workspace,readonly,bind-recursive=disabled" \
    --mount type=volume,src=pi-readonly-state,dst=/home/node/.pi/agent \
    pi-readonly --tools read --no-extensions --no-skills \
    --no-prompt-templates --no-themes --no-context-files --no-approve \
    --session-dir /home/node/.pi/agent/sessions
}
run_pi_readonly
unset -f run_pi_readonly
```

The bind mount makes the repository read-only and excludes nested mounts. The named volume preserves Pi's separate state. The explicit session directory takes precedence over project configuration, while the other options narrow tool and resource loading. None of these flags makes repository text trustworthy or hides Pi's own configuration from its process.

## Establish identity, credentials and session persistence

Before giving Pi a task, use a second terminal on the host to run `docker exec pi-readonly id -u` and `docker exec pi-readonly pwd`. For this image, the expected results are `1000` and `/workspace`. Inspect the container's mounts and require the intended repository source, `/workspace` destination and `RW: false`. A different identity or mount is a failed acceptance check, not something to work around by enabling more tools.

Inside Pi, use `/login` to choose your model provider and follow its supported authentication flow, then `/model` to select an available model. Supply credentials through that flow, not a printed shell command, repository file or chat prompt. Remote OAuth may ask you to return an authorisation code or redirect URL to the terminal. Treat those values as credentials too.

This login stores credentials in Pi's `auth.json` within the state volume. Keep the volume private and out of source control. It is not a credential-isolation boundary: Pi can access its own authentication data. The sample is therefore for your known, non-sensitive repository copy, not an invitation to process hostile repositories with valuable credentials. Where the threat model requires keys outside Pi, use an isolation arrangement with that property rather than enlarging this example's permissions.

Ask Pi to read a specific, existing non-sensitive README and explain its purpose. Compare the response with the actual file and inspect the tool transcript. The expected action is a read of that file, not a shell command, edit, unrelated path or external integration. Missing-file or permission errors should stop the exercise until the workspace mapping is corrected.

Run `/session` and record the session ID and file location without copying its contents into logs. It should be under the explicit session directory. Exit Pi, start the same image with the same mounts and options, then use `/resume` to reopen that session. Require the same history and another correct harmless read. An empty picker or unexpected session path means persistence has not passed.

Use this permissions-and-state checklist before allowing broader work:

| Layer | Required decision | Observable acceptance |
| --- | --- | --- |
| Harness | Keep Pi non-root and record the installed version and image. | Process identity is the intended unprivileged user; the version matches your record. |
| Model connection | Provide only the intended provider credential and model access. | A harmless request works without credentials appearing in commands, prompts or shared output. |
| Working files | Expose the dedicated copy read-only for the first session. | The mount is the intended path with writes disabled; the tool transcript stays within the requested task. |
| Session data | Preserve the explicit state volume and restrict access to it. | The recorded session is available after Pi exits and the container is recreated. |

## Update a copy, not your only working environment

Before an update, stop Pi so its state is no longer changing. Preserve the repository work, including uncommitted changes, and back up the complete Pi state volume. That includes configuration, credentials and sessions, so protect the backup accordingly. Retain the previous image and its recorded version; a conversation export alone does not preserve the working files or all configuration.

For this container pattern, build an updated image under a different tag with `docker build --pull --no-cache -t pi-candidate .` in the original build directory. Restore a backup copy into a separate candidate state volume and use a separate repository copy. Never point the candidate at your only working state. This separates an application update from the decision to adopt any changed data.

In the candidate, repeat the identity and mount checks, reopen the copied session and perform the harmless README read. Require correct history, intended tool selection and a successful response without unexpected access. Record any configuration change needed to achieve that result. Do not enable writing or shell execution merely to get past a failed acceptance step.

On failure, stop the candidate and return to the retained working image and untouched original state. When restoring from backup is necessary, restore into a new volume and recheck the session before replacing the working copy. Session branching or returning to an older image does not reverse file edits or actions already performed against external services; recover those separately.

A remote setup is worthwhile when its separation and persistence serve your workflow and you can own these controls. Virtarix's [AI Agent VPS](<https://virtarix.com/solutions/ai-agent-hosting/>) provides self-managed infrastructure for customer-operated agent applications. You install and configure Pi, manage model access, secure and update the environment, and maintain the application's data and recovery process.
