{"slug": "i-built-an-app-to-run-local-llms-on-colab-and-vast-ai-in-one-night", "title": "I Built an App to Run Local LLMs on Colab and Vast.ai in One Night", "summary": "A developer built llm-harness, an app that runs local LLMs such as Qwen on rented Colab and Vast.ai GPUs through a single CLI (up/status/chat/down), automatically selecting vLLM, llama.cpp, or Ollama based on the GPU generation. To stay within Colab's rules against tunnels and remote proxies, the harness drives Google's official Colab CLI via colab exec, passing chat content through environment variables rather than exposing the server. On a Colab Pro T4, Ollama was selected for qwen3:8b, and the developer added OLLAMA_KEEP_ALIVE=-1 to avoid slow first-request model loading.", "body_md": "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.\n\nSo, 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**.\n\nThis article is for you if:\n\nThe part I struggled with most was working within Colab's rules, so that is the focus of this article.\n\nllm-harness runs one of vLLM, llama.cpp, or Ollama on a Colab or Vast.ai GPU.\n\nI shaped it step by step while asking Claude for changes.\n\n`llm-harness up` / `status` / `chat` / `down`\nThere are two routes for renting a GPU: Vast.ai and Colab.\n\nBoth 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.\n\nThe harness looks at the generation of the rented GPU and picks the inference engine automatically.\n\nThere are three reasons for choosing Ollama on the T4:\n\nThe 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:\n\n`X-Harness`) on POST requests\nWhen another website tries to send a request with a custom header, the browser blocks it. The app relies on that behavior.\n\nThis is the highlight of the article.\n\nThe first idea was to \"expose the server started on Colab through a tunnel (cloudflared or ngrok) and use it from my PC.\"\n\nHowever, 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.\n\nReference: [Colab FAQ (Which activities are restricted in Colab?)](https://research.google.com/colaboratory/faq.html)\n\nSo I decided not to use a tunnel.\n\nThe 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.\n\nBut with this, I could not use it from the app on my PC.\n\nIn 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.\n\nThe flow looks like this:\n\n```\n# Rent a GPU runtime\ncolab new -s llm-harness --gpu T4\n\n# Send the startup script and start the server\ncolab exec -s llm-harness -f setup.py\n\n# For each chat message, send a small script with colab exec and call the LLM from inside the runtime\n\n# Return the runtime\ncolab stop -s llm-harness\n```\n\nThis works thanks to two properties described in the official documentation:\n\n`exec` calls → a server started once can be reused\nI 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`.\n\nThe GPU options are T4 / L4 / G4 / A100 / H100. Which ones you can use depends on your plan.\n\nI learned that it matters to design within the rules, rather than settling for \"it works, so it's fine.\"\n\nI actually ran it on a T4 with Colab Pro.\n\nThe GPU check came out as follows, and since it was a T4, Ollama was selected:\n\n```\nGPU: Tesla T4 15360 MiB compute 7.5 → backend: ollama\n```\n\nThe model was `qwen3:8b`.\n\n(I asked both questions in Japanese; the above are translations.)\n\nHowever, the two questions took 174.9 seconds.\n\nIt 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.\n\nSo I added two things:\n\n`OLLAMA_KEEP_ALIVE=-1`\nWith this, replies come right away once \"Ready\" is shown.\n\nThe scary part about rented GPUs is getting billed because you forgot to stop one. I built the following into the Vast.ai route:\n\n`CONTAINER_API_KEY`). My main API key is never passed to the instance\nUsing the real Vast.ai or Colab costs money. So I built a \"fake CLI\" and a \"fake LLM server\" for testing.\n\nI wrote fake `vastai` and fake `colab` commands in Python and swapped them in for the real ones with environment variables.\n\nWith browser automation (Playwright), the tests actually click through the UI and check \"GPU search → start → chat → stop\" end to end.\n\nThese tests found a small bug where the text on the send button was wrapping vertically, and I fixed it.\n\nTo be honest, I have not tried the following two things for real yet:\n\nThat said, running it in the notebook version (Colab in the browser) has worked. That is the T4 result from the previous section.\n\n`colab exec` from Google's official Colab CLI to chat from the app without exposing the server\nDesign within the rules, rather than settling for \"it works, so it's fine.\" That was the biggest lesson for me this time.\n\nI 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).\n\nWhen handing work to an agent, pasting the text itself is more reliable than giving it a file name.", "url": "https://wpnews.pro/news/i-built-an-app-to-run-local-llms-on-colab-and-vast-ai-in-one-night", "canonical_source": "https://dev.to/koheip/i-built-an-app-to-run-local-llms-on-colab-and-vastai-in-one-night-4poh", "published_at": "2026-11-29 12:33:32+00:00", "updated_at": "2026-11-29 12:43:50.926975+00:00", "lang": "en", "topics": ["large-language-models", "ai-tools", "ai-infrastructure", "developer-tools", "mlops"], "entities": ["llm-harness", "Colab", "Vast.ai", "Ollama", "vLLM", "llama.cpp", "Qwen", "Claude"], "also_reported_by": [], "takeaway": "Driving a Colab-hosted inference server through the official Colab CLI's exec calls, with chat content passed via environment variables, gives an OpenAI-compatible API without a tunnel, and setting OLLAMA_KEEP_ALIVE=-1 eliminates the slow first-request model load on a T4.", "recommendation": {"advice": "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.", "playbook": "inference-serving", "playbook_url": "https://wpnews.pro/playbooks/inference-serving"}, "alternates": {"html": "https://wpnews.pro/news/i-built-an-app-to-run-local-llms-on-colab-and-vast-ai-in-one-night", "markdown": "https://wpnews.pro/news/i-built-an-app-to-run-local-llms-on-colab-and-vast-ai-in-one-night.md", "text": "https://wpnews.pro/news/i-built-an-app-to-run-local-llms-on-colab-and-vast-ai-in-one-night.txt", "jsonld": "https://wpnews.pro/news/i-built-an-app-to-run-local-llms-on-colab-and-vast-ai-in-one-night.jsonld"}}