# I Built an App to Run Local LLMs on Colab and Vast.ai in One Night

> Source: <https://dev.to/koheip/i-built-an-app-to-run-local-llms-on-colab-and-vastai-in-one-night-4poh>
> Published: 2026-11-29 12:33:32+00:00

**Recommendation:** Set OLLAMA_KEEP_ALIVE=-1 so the model stays resident in GPU memory and replies are immediate after the first load; on a T4, qwen3:8b otherwise spent much of its first request loading weights.
More in the playbook "Inference and self-hosting": <https://wpnews.pro/playbooks/inference-serving>

I wanted to try local LLMs such as Qwen, but the GPU in my own PC is too weak to run them. Renting a GPU on Colab or Vast.ai works, but redoing the setup every time is tedious.

So, together with Claude, I built a harness (a tool) for running "local LLMs" on rented GPUs in one night, and turned it into an app. It is called **llm-harness**.

This article is for you if:

The part I struggled with most was working within Colab's rules, so that is the focus of this article.

llm-harness runs one of vLLM, llama.cpp, or Ollama on a Colab or Vast.ai GPU.

I shaped it step by step while asking Claude for changes.

`llm-harness up` / `status` / `chat` / `down`
There are two routes for renting a GPU: Vast.ai and Colab.

Both routes end up usable as an OpenAI-compatible API. The Colab route is built a bit differently because of Colab's rules, which I cover in the next section.

The harness looks at the generation of the rented GPU and picks the inference engine automatically.

There are three reasons for choosing Ollama on the T4:

The app runs only on `127.0.0.1` on my own PC. On top of that, I added two protections so that other websites cannot operate it without permission:

`X-Harness`) on POST requests
When another website tries to send a request with a custom header, the browser blocks it. The app relies on that behavior.

This is the highlight of the article.

The first idea was to "expose the server started on Colab through a tunnel (cloudflared or ngrok) and use it from my PC."

However, Colab's FAQ prohibits offering web services to the outside and "connecting to remote proxies." On top of that, on the free tier, bypassing the notebook UI to work through a web UI is also prohibited.

Reference: [Colab FAQ (Which activities are restricted in Colab?)](https://research.google.com/colaboratory/faq.html)

So I decided not to use a tunnel.

The first solution was to run the server only inside Colab (`127.0.0.1`) and use it from within the same notebook. Nothing is exposed to the outside.

But with this, I could not use it from the app on my PC.

In the end, I used Google's official Colab CLI. The app sends code with `colab exec` and receives the result. This let me chat from the app on my own PC without exposing the server.

The flow looks like this:

```
# Rent a GPU runtime
colab new -s llm-harness --gpu T4

# Send the startup script and start the server
colab exec -s llm-harness -f setup.py

# For each chat message, send a small script with colab exec and call the LLM from inside the runtime

# Return the runtime
colab stop -s llm-harness
```

This works thanks to two properties described in the official documentation:

`exec` calls → a server started once can be reused
I passed the chat content through environment variables (`--env`) instead of embedding it in the code. When I checked the Colab CLI source, the values were safely embedded using Python's `repr`.

The GPU options are T4 / L4 / G4 / A100 / H100. Which ones you can use depends on your plan.

I learned that it matters to design within the rules, rather than settling for "it works, so it's fine."

I actually ran it on a T4 with Colab Pro.

The GPU check came out as follows, and since it was a T4, Ollama was selected:

```
GPU: Tesla T4 15360 MiB compute 7.5 → backend: ollama
```

The model was `qwen3:8b`.

(I asked both questions in Japanese; the above are translations.)

However, the two questions took 174.9 seconds.

It looked like it had stalled partway, so I checked `nvidia-smi` in a terminal and saw about 5.4 GB loaded into GPU memory. The slowness was because the model was being loaded onto the GPU on the first request only.

So I added two things:

`OLLAMA_KEEP_ALIVE=-1`
With this, replies come right away once "Ready" is shown.

The scary part about rented GPUs is getting billed because you forgot to stop one. I built the following into the Vast.ai route:

`CONTAINER_API_KEY`). My main API key is never passed to the instance
Using the real Vast.ai or Colab costs money. So I built a "fake CLI" and a "fake LLM server" for testing.

I wrote fake `vastai` and fake `colab` commands in Python and swapped them in for the real ones with environment variables.

With browser automation (Playwright), the tests actually click through the UI and check "GPU search → start → chat → stop" end to end.

These tests found a small bug where the text on the send button was wrapping vertically, and I fixed it.

To be honest, I have not tried the following two things for real yet:

That said, running it in the notebook version (Colab in the browser) has worked. That is the T4 result from the previous section.

`colab exec` from Google's official Colab CLI to chat from the app without exposing the server
Design within the rules, rather than settling for "it works, so it's fine." That was the biggest lesson for me this time.

I handed the job of putting a shortcut on my PC to another agent (grokbot). Instead of my instructions for this task, grokbot read a different instruction file I had written on 11/17 (one for saving articles as drafts on Zenn and Qiita).

When handing work to an agent, pasting the text itself is more reliable than giving it a file name.
