How to Install and Use OpenHands: The AI Agent for Automated Coding on Linux

Artificial Intelligence tutorial - IT technology blog
Artificial Intelligence tutorial - IT technology blog

Manually fixing dozens of trivial bugs after a refactor, or typing out boilerplate for a new project by hand — these are the kinds of tasks that drain the enthusiasm right out of engineers. I once spent an entire afternoon debugging a silly logic error that should have taken ten minutes to resolve. That’s when I decided to try OpenHands (formerly OpenDevin), an open-source AI agent that can execute coding tasks like a real engineer.

Unlike ChatGPT — which only exchanges messages — OpenHands directly runs terminal commands, reads files, writes code, and runs tests inside its own sandbox. This guide goes straight into how to set it up on Linux.

Up and Running in 5 Minutes

The fastest way to run OpenHands is with Docker. No need to install Python separately, no library conflicts to worry about. More importantly, the sandbox isolates the AI from your main filesystem — reducing the risk of accidentally deleting important files.

Step 1: Install Docker

On Ubuntu/Debian, install it quickly with:

sudo apt update && sudo apt install docker.io -y
sudo usermod -aG docker $USER

Log out and log back in for the Docker permissions to take effect.

Step 2: Pull the Image and Run

The command below pulls the latest image and opens the web interface on port 3000:

docker run -it \
    --pull=always \
    -e SANDBOX_USER_ID=$(id -u) \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v ~/.openhands-state:/.openhands-state \
    -p 3000:3000 \
    --add-host host.docker.internal:host-gateway \
    --name openhands-app \
    ghcr.io/all-hands-ai/openhands:0.9

Once the terminal shows Server started at http://localhost:3000, you’re done. Open your browser and it’s ready to use.

Why This Isn’t Just Another Chatbot

The core problem with AI chatbots is the lack of a feedback loop. You paste code in, the AI fixes it, you paste it back, run it, hit an error, and start over. Each cycle takes 2–3 minutes — multiply that by a dozen bugs and half your day is gone.

OpenHands solves this through an Event Stream mechanism: the AI observes execution results and adjusts on its own. Try giving it a concrete task like: “Install FastAPI and write a simple CRUD endpoint.” It will:

  1. Open a terminal inside the Docker sandbox.
  2. Run pip install fastapi.
  3. Create the main.py file on its own.
  4. Start the server and read logs if there are syntax errors.
  5. Fix issues on its own until everything runs, then report back.

I once threw a Python repo at it that hadn’t been touched in two years: “Upgrade the dependencies and fix the build errors.” It worked through the problem for 15 minutes — reinstalled the environment, patched library version conflicts, and got the unit tests passing cleanly. The same task used to take me about 3 hours because I had to Google each error one by one.

Choosing the Right LLM

Once you’re in at localhost:3000, the first thing to do is configure the model. Here’s what I’ve actually tested:

1. Claude Sonnet 4 (Recommended)

My top choice for a coding agent right now. Its ability to track long context and follow multi-step instructions is noticeably more reliable — especially when a task involves editing multiple files at once. Requires an API Key from Anthropic.

2. GPT-4o

Fast responses, but tends to cut off mid-generation on tasks involving more than 200 lines of code. Good for short tasks or when speed is the top priority.

3. Running Locally with Ollama

Don’t want to send your code to the cloud? Ollama is a reasonable option. One caveat: smaller models like Llama 3 8B tend to fall apart around step 4–5 of a complex action chain. If you’re going local, prioritize DeepSeek-Coder-V2 or Qwen2.5-Coder 32B or larger.

Connect to Ollama running on your host machine by changing the URL in OpenHands settings:

http://host.docker.internal:11434

Tips for Better Results

Mount Your Project Directory

To have the AI edit your source code directly, add the -v flag when starting:

-v /path/to/your/project:/opt/workspace_base

All changes will sync directly into your real directory. Commit first before handing off a task — if the AI makes a wrong edit, one git checkout brings everything back.

Smaller Tasks, Better Results

Avoid prompts like: “Build me an e-commerce platform.” Break it down: “Write a JWT authentication module,” then “Create the database schema for products.” Tasks scoped to under 200 lines of code consistently produce much cleaner results than large, vague requests.

Set a Max Iterations Limit

OpenHands runs in a loop. When it hits a tough bug, it can loop 50–100 times without finishing — and every iteration costs tokens. I always set Max Iterations = 20–30. That’s enough for most tasks and keeps your API bill from spiking at the end of the month.

How Does It Hold Up in Practice?

The most common question: can OpenHands replace a developer? No. But that’s not what it’s designed to do.

Think of OpenHands as a hardworking junior developer who doesn’t mind repetitive work. Fixing trivial bugs, writing unit tests, migrating data, scaffolding boilerplate — tasks that eat up 20–30% of your time but don’t require deep thinking. I’ve been using it for automation scripts on production and the results have been fairly solid.

Where AI still can’t replace you is in System Design and deep performance optimization — decisions that require understanding business context. But when it handles the grunt work, you free up time to focus on designing new features.

If you’re on Linux and haven’t tried an AI agent yet, OpenHands is a good place to start. Initial setup takes about 10–15 minutes. After a week of getting used to the workflow, you’ll naturally figure out what to delegate to it and what to keep doing yourself.

Share: