Running Opencode with Ollama on Mac. — Tensors and tokens


Software development

Adam Lusted3 minutes read

How to get started with local Ollama models using Opencode and Docker sandboxes.

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

Why I use Ollama. Honestly, it’s simple. It now has mlx so it runs fast on Apple Silicon. He has a pretty good catalog of models. It is also very stable and does not crash.

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

Another tool I use is docker sandboxes. sbx. At work I use advanced models that require us to place our harnesses in a sandbox. I also like to run my local models in containers as they can easily ruin your computer with unwanted hallucinations.

Installation of tools

Install Docker sandbox:

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

Install open source:

brew install anomalyco/tap/opencode

Install Ollama:

To install ollama, follow the link, download and install the application.

Installation of models

As for the models, we will pull out 2 models. First make sure ollama is working.

Qwen 3.8 27B mxfp8 (32 GB): This is a great workhorse that will get most of your long-term work done and can run uninterrupted for hours with open source.

ollama pull qwen3.8:27b-mxfp8

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

ollama pull gemma4:31b-mxfp8

Note: If you don’t have an Apple 48GB, you can use the standard models: qwen3.8:27b-mlx And gemma4:31b-mlx .

Setting up your project

For this setup, you will need to configure the sbx kit for each project. A kit is a way to personalize your sandbox. Create the following folders and files:

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

special.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

open source-local.yaml

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

  "model": "ollama/gemma4:31b-mxfp8",
  "small_model": "ollama/gemma4:31b-mxfp8",
  "lsp": false,

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

      "options": {
        "baseURL": "
      },

      "models": {


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

        "gemma4:31b-mxfp8": {
          "name": "Gemma 4 31B MXFP8 [33 → ~50 GB] [256K ctx]",
          "limit": {
            "context": 262144,
            "output": 8192
          }
        }

      }
    }
  }
}

For the qwen model, we have limited the context to 64 KB, this ensures that your system does not freeze when it runs out of memory. We also need 3GB for the sandbox.

Launch open source

To run open source, do the following:

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

This will launch Opencode with Qwen selected. Make sure you switch to “low” force using /models team.

You should be good to go.

Note: You will need to be logged into Docker to run sbx. This feature is not very popular among the developer community, but there is no way around it.

Running Opencode with Ollama on Mac. — Tensors and tokens

Leave a Reply

Your email address will not be published. Required fields are marked *