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. Software development /categories/software/ Running Opencode with Ollama on mac. 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 https://ollama.com/library/qwen3.8 and Gemma4 https://ollama.com/library/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 https://ollama.com/ . 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 https://opencode.ai/ . 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 https://www.docker.com/products/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/ 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 https://docs.docker.com/ai/sandboxes/customize/kits/ 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 /