Support > About cloud server > Claude Code Permissions and Isolation: Minimal Configuration for Safely Running AI Agents on a Shared VPS
Claude Code Permissions and Isolation: Minimal Configuration for Safely Running AI Agents on a Shared VPS
Time : 2026-10-20 11:40:26
Edit : Jtti

The primary distinction between AI agents (such as Claude Code) and traditional scripts lies in their extensive permissions. They can execute shell commands, modify the file system, and even initiate network requests. Running Claude Code as `root` on a VPS—especially one hosting databases, backend services, or shared resources—is akin to introducing a robot into your home that could spiral out of control at any moment.

Should an agent—due to a "hallucination"—execute a command like `rm -rf /`, or fall victim to a prompt injection attack that leads to the exposure of sensitive keys (such as `~/.ssh/id_rsa` or `.env` files), the consequences could be catastrophic.

Safely running an AI agent on a shared VPS does not require an overly complex architecture; however, it does necessitate adherence to a few fundamental isolation standards.

Configuration 1: User Isolation—Never Run AI as `root`

This is the most essential and cost-effective line of defense.

1. Create a dedicated system user

Establish a specific, non-privileged user account for the AI ​​agent. This user should have access only to its own home directory and possess no `sudo` privileges.

sudo adduser claude-agent

Disable shell login for this user (if manual access is not required):

sudo usermod -s /usr/sbin/nologin claude-agent

2. Restrict directory permissions

Clone your project into `/home/claude-agent/workspace` and assign ownership to this user. Never expose sensitive directories—such as `/etc`, `/var`, or the home directories of other users—to the agent.

sudo chown -R claude-agent:claude-agent /home/claude-agent/workspace

3. Execute as the designated user

If using `tmux`, switch to this user before launching the agent. If using `systemd` (as described in the first article), ensure that `User=claude-agent` is specified within the service file.

Configuration 2: Container Isolation—The Ultimate Sandbox

In scenarios involving multiple projects or shared access, the most straightforward way to prevent cross-contamination is by using Docker containers.

1. Utilize official or custom-built images

Avoid running the agent directly on the host machine. Building a Dockerfile for the Claude Code runtime environment:

```dockerfile

FROM node:18-alpine

WORKDIR /app

RUN npm install -g @anthropic-ai/claude-code

Create a non-root user

RUN addgroup -S agent && adduser -S agent -G agent

USER agent

Build and run:

docker build -t claude-sandbox .

Mount the local code directory into the container

docker run -it --rm -v /home/claude-agent/workspace:/app -w /app claude-sandbox

This approach strictly confines the agent’s file modifications and network activity to within the container, preventing it from accessing the host machine's system files.

Configuration 3: Resource Limits—Preventing the Agent from Crashing the Server

As mentioned earlier, Claude Code may occasionally experience memory leaks or abnormal resource consumption. In a shared environment, if it exhausts the available memory, it could trigger the OOM (Out-Of-Memory) Killer, potentially terminating other critical processes.

1. Using systemd cgroups for resource constraints

Add the following to your `claude.service` file:

```ini

[Service]

Limit maximum memory to 4GB

MemoryMax=4G

Limit CPU usage to 200% (equivalent to 2 cores)

CPUQuota=200%

If Claude Code’s memory usage exceeds this threshold, the system will automatically terminate the process, thereby protecting the host machine.

2. Applying limits in Docker

Include resource constraints when starting the container:

docker run -it --rm --memory="4g" --cpus="2.0" -v ... claude-sandbox

Configuration 4: Network and Key Isolation

1. Protecting private keys on the host machine

When the agent runs as the `claude-agent` user, it cannot, by default, access the `.ssh` directories belonging to `root` or other users. Furthermore, if the agent is running inside a container, private keys from the host machine are not mapped into the container environment.

2. Minimizing API permissions

In the Anthropic console, generate distinct API keys for different agents whenever possible. Additionally, set conservative spending limits to prevent runaway code from causing an unexpectedly high API bill.

Why is a dedicated, clean VPS the best starting point? No matter how robust the isolation you implement within your system, infrastructure-level isolation remains the primary line of defense. Deploying AI agents alongside your core business operations on the same machine is inherently risky.

If you wish to carve out a dedicated, isolated space for your AI agents, Jtti’s Hong Kong Lightweight Cloud—offering 1 vCPU, 1GB of RAM, and 200Mbps of dedicated bandwidth—serves as an ideal "sandbox." It provides independent resources, ensures no bandwidth contention with other users, and maintains consistent pricing upon renewal, making the long-term costs of running persistent agents highly transparent. For enterprise-grade, multi-agent deployments, Jtti’s 2 vCPU/4GB RAM or 4 vCPU/8GB RAM configurations allow for further multi-dimensional resource partitioning at the container level.

The core logic behind this isolation is to assume that agents will inevitably make mistakes, and then to limit the potential "blast radius" of such errors through layered restrictions. From operating-system-level user isolation and container sandboxing to the underlying virtualization isolation provided by Jtti’s VPS, every layer acts as a safeguard for your data security.

Relevant contents

Does Claude Code stop when your SSH connection drops? Keep your AI agent running persistently on a Jtti VPS using tmux + systemd. How should I choose the CPU and RAM when running Claude Code on a Jtti VPS? A Complete Guide to Mounting NFS Shares on Windows Server: From Client Installation to Auto-Mounting and Troubleshooting Choosing a VPS based solely on price? Make sure it features CN2, 9929, or CMIN2 routing—or at least network optimization across all three major carriers—otherwise, even the cheapest option is just a waste of money. Troubleshooting Windows Server File Share Access Issues: A Comprehensive Guide to Causes and Solutions How can I verify whether the IP address of a Singapore CN2 VPS is a "native" (original/residential-assigned) IP? How to Choose a VPS for Setting Up a TikTok Node: Key Considerations and Common Pitfalls Where can you buy Hong Kong CN2 GIA VPS? A guide covering channels, verification, and selection. What to do if Steam keeps disconnecting? A complete guide to troubleshooting causes and preventive solutions. Jtti Hong Kong VPS Money-Saving Guide: Multiple Hidden Discount Channels—Stop Paying Full Price
Go back

24/7/365 support.We work when you work

Support