cd /news/large-language-models/setting-up-opencode-with-ollama-and-… · home topics large-language-models article
[ARTICLE · art-126388] src=tensorsandtokens.com ↗ pub= topic=large-language-models verified=true sentiment=↑ positive

Setting up OpenCode with Ollama and sbx on Mac

A developer guide details running local LLMs with OpenCode, Ollama, and Docker Sandboxes (sbx) on an Apple MacBook Pro M5 with 48GB of memory, pulling Qwen 3.8 27B mxfp8 (32GB) and Gemma 4 31B mxfp8 (34GB) via Ollama. The setup requires a per-project sbx kit with a spec.yaml and opencode-local.json config, pointing OpenCode at Ollama's host endpoint http://host.docker.internal:11434/v1 with a 262144-token context and 8192-token output limit. The guide recommends the 48GB Apple machine as the sweet spot for running 30B models, with standard qwen3.8:27b-mlx and gemma4:31b-mlx alternatives for smaller machines.

read3 min views6 publishedSep 11, 2026

Software development

How to get started with running Ollama local models with Opencode and Docker Sandboxes.

Viable local LLM development is here. With powerful models like Qwen 3.8 and Gemma4 we can now finally use these models to build out web applications. I'm using a Apple Macbook pro m5 48GB model. I think this is the sweet spot for local development as it allows you to run 30B models with a decent sized context.

Why I use Ollama. To be frank it's just easy. It has mlx now, so it's fast on Apple silicon. It has a pretty good model directory. It is also very stable and won't crash.

Why Opencode. Well, we need to start somewhere with this blog and opencode is a great harness.

There is one other tool that I use, docker sandboxes aka sbx. I use frontier models at work which require us to sandbox our harnesses. I also, like to run my local models in containers as they can just as easily mess up your computer with a unwanted hallucination.

Installing the tools

Install Docker Sandbox:

brew trust docker/tap && brew install docker/tap/sbx

Install Opencode:

brew install anomalyco/tap/opencode

Install Ollama:

To install ollama, goto https://ollama.com/ and download and install the app.

Installing the models

For the models, we'll pull 2 models. First ensure ollama is running.

Qwen 3.8 27B mxfp8 (32GB): This is a great workhorse model that will do most of your long running work and can run undisturbed for multiple hours within opencode.

ollama pull qwen3.8:27b-mxfp8

Gemma 4 31b mxfp8 (34GB): This is a great big dense model when you need something bigger.

ollama pull gemma4:31b-mxfp8

Note: If you don't have the 48GB Apple, you can pull the standard models: qwen3.8:27b-mlx and gemma4:31b-mlx .

Configuring your project

For this setup, it requires you to setup a sbx kit for every project. A kit is a way to customise the sandbox. Create the following folders and files:

./sbx-kit/files/home/.config/opencode-local.json
./sbx-kit/spec.yaml

spec.yaml

schemaVersion: "2"
kind: mixin
name: local-ollama-opencode
version: "0.1.0"
displayName: Local Ollama for OpenCode
description: Configure OpenCode in Docker Sandboxes to use Ollama running on the Mac host.

requires:
  agent: opencode

environment:
  variables:
    OPENCODE_CONFIG: /home/agent/.config/opencode-local.json

permissions:
  network:
    allow:
      - localhost:11434
      - localhost:5173
      - localhost:4000

agentInstructions:
  content: |
    Local Ollama runs on the host machine.

    Default model:
      qwen3.8:27b-mxfp8

    Deep file analysis / reasoning:
      gemma4:31b-mxfp8

opencode-local.yaml

{
  "$schema": "https://opencode.ai/config.json",

  "model": "ollama/qwen3.8:27b-mxfp8",
  "small_model": "ollama/qwen3.8:27b-mxfp8",
  "lsp": false,

  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Mac Ollama",

      "options": {
        "baseURL": "http://host.docker.internal:11434/v1"
      },

      "models": {
        "qwen3.8:27b-mlx": {
          "name": "Qwen 3.8 27B MLX [18 → ~35 GB] [256K ctx]",
          "limit": {
            "context": 262144,
            "output": 8192
          },
          "variants": {
            "low": {
              "reasoningEffort": "low"
            },
            "medium": {
              "reasoningEffort": "medium"
            },
            "high": {
              "reasoningEffort": "high"
            },
            "xhigh": {
              "reasoningEffort": "xhigh"
            }
          }
        },

        "qwen3.8:27b-mxfp8": {
          "name": "Qwen 3.8 27B MXFP8 [31 → ~48 GB] [256K ctx]",
          "limit": {
            "context": 262144,
            "output": 8192
          },
          "variants": {
            "low": {
              "reasoningEffort": "low"
            },
            "medium": {
              "reasoningEffort": "medium"
            },
            "high": {
              "reasoningEffort": "high"
            },
            "xhigh": {
              "reasoningEffort": "xhigh"
            }
          }
        }
      }
    }
  }
}

For the qwen model, we've limited the context to 64k, this will ensure your system dose not lock up when it runs out of memory. We also need 3GB for the sandbox.

Run Opencode

To run opencode, run the following:

sbx run opencode --kit ./sbx-kit/

This will start Opencode with Qwen selected. Ensure you change down to "low" effort via /models command.

You should be good to go.

Note: You will need to login into Docker to run sbx. This feature is not really liked by the development community but there is no way around it.

← Back to the latest

── more in #large-language-models 4 stories · sorted by recency
── more on @opencode 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/setting-up-opencode-…] indexed:0 read:3min 2026-09-11 ·