Why a VPS for OpenClaw Agents?

Running an OpenClaw agent on a Virtual Private Server (VPS) offers a critical advantage: continuous operation. Unlike a personal laptop, a VPS provides a stable, always-on environment. This means your automation tasks run 24/7 without interruption, regardless of your local machine's status. A VPS offers a permanent digital address for your agents, a stable IP, and immunity from sleep modes. Furthermore, a VPS provides the necessary resources and isolation to run multiple agents or scheduled jobs concurrently. For most OpenClaw applications, a basic Linux VPS with at least 2GB of RAM is sufficient to begin.

1. Server Initialization and Updates

The first step is provisioning your server. Choose a Linux distribution; Ubuntu 22.04 LTS is recommended for its ease of use and extensive community support, making it an accessible starting point. Once your VPS is active, connect to it using SSH. It is crucial to ensure your system is up-to-date before proceeding. Execute the following commands to update your package lists and upgrade existing packages:

sudo apt update && sudo apt upgrade -y

This ensures you are working with the latest security patches and software versions, minimizing potential conflicts or vulnerabilities during the OpenClaw setup.

Ubuntu 22.04 LTS server terminal showing successful apt update and upgrade commands

2. Installing Node.js

OpenClaw is built on Node.js, making its installation a prerequisite. The recommended method for installing Node.js on Debian-based systems like Ubuntu is by using the NodeSource repository. This ensures you get a specific, recent version of Node.js that is compatible with OpenClaw. First, download and execute the NodeSource setup script for Node.js v20.x (a stable and widely supported version). This script configures your system to use the NodeSource repository:

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -

After the repository is added, you can install Node.js and npm (Node Package Manager) using apt:

sudo apt-get install -y nodejs

Verify your Node.js installation by checking its version:

node -v

And npm version:

npm -v

Having Node.js and npm correctly installed is fundamental for managing OpenClaw and its dependencies.

3. Installing OpenClaw

With Node.js and npm set up, you can now install OpenClaw globally. This makes the openclaw command available from any directory on your server. Use npm to install the OpenClaw CLI package:

sudo npm install -g openclaw

This command downloads and installs the OpenClaw package and its dependencies, making the OpenClaw command-line interface ready for use. To confirm the installation, check the OpenClaw version:

openclaw -v

This step confirms that the OpenClaw executable is correctly placed in your system's PATH and is accessible.

4. Creating Your OpenClaw Agent

Now, you need to create a directory for your agent and initialize it. It's good practice to create a dedicated directory for your automation projects. Navigate to your desired location (e.g., your home directory) and create a new folder for your agent. For instance:

mkdir my-openclaw-agent
cd my-openclaw-agent

Inside this directory, use the OpenClaw CLI to create a new agent. This command generates the basic file structure and configuration for your agent:

openclaw init

The init command will typically prompt you for some basic information or create default files. This sets up your agent's workspace, ready for you to define its automation logic.

5. Configuring Your Agent

The core of your agent's behavior is defined in its configuration files. After running openclaw init, you will find configuration files (often in JSON or YAML format) within the agent's directory. You will need to edit these files to specify the tasks your agent should perform, the websites it should interact with, the data it should scrape or process, and any scheduling parameters. For example, you might configure:

  • Scraping Targets: URLs, CSS selectors, or XPath expressions to extract data.
  • Data Storage: Where to save the scraped data (e.g., CSV, JSON, database).
  • Scheduling: How often the agent should run (e.g., hourly, daily, specific times).
  • Login Credentials: If the agent needs to log into websites.
  • User-Agent Strings: To mimic browser behavior and avoid detection.

Refer to the official OpenClaw documentation for the specific configuration options available for your version and use case. Precise configuration is key to effective automation.

6. Running Your Agent

Once configured, you can run your agent. From within the agent's directory, execute:

openclaw run

This command will start the agent, and it will execute its defined tasks according to the schedule or on-demand. Since it's running on a VPS, it will continue to operate even after you disconnect your SSH session.

7. Ensuring Continuous Operation with PM2

To ensure your OpenClaw agent runs continuously and restarts automatically if it crashes or the server reboots, you should use a process manager like PM2. PM2 is a popular choice for managing Node.js applications. First, install PM2 globally:

sudo npm install -g pm2

Then, start your OpenClaw agent using PM2. Navigate to your agent's directory and run:

pm2 start your_agent_script.js --name "my-openclaw-agent"

Replace your_agent_script.js with the main JavaScript file that runs your OpenClaw agent (often index.js or similar, depending on how openclaw init structured it). PM2 will manage the process, keeping it alive. To ensure PM2 starts your agent automatically on server boot, use the following command:

pm2 startup

Follow the instructions provided by the pm2 startup command, which usually involves running another command as root. Finally, save your current PM2 process list so that it will be restored after a reboot:

pm2 save

With PM2 configured, your OpenClaw agent is now set up for robust, unattended, 24/7 operation on your VPS. You can monitor your agent's status, logs, and resource usage using PM2 commands like pm2 list, pm2 logs my-openclaw-agent, and pm2 monit.

PM2 dashboard showing active OpenClaw agent process and its resource utilization

Conclusion

By following these steps, you can effectively deploy and manage your OpenClaw agents on a VPS. This setup provides the reliability and continuous operation necessary for serious automation, freeing you from the constraints of running agents on local machines. The combination of a stable VPS environment and a robust process manager like PM2 ensures your automation workflows execute as intended, around the clock.