{"slug": "setting-up-opencode-with-ollama-and-sbx-on-mac", "title": "Setting up OpenCode with Ollama and sbx on Mac", "summary": "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.", "body_md": "[Software development](/categories/software/)\n\n# Running Opencode with Ollama on mac.\n\nHow to get started with running Ollama local models with Opencode and Docker Sandboxes.\n\nViable 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.\n\nWhy 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.\n\nWhy [Opencode](https://opencode.ai/). Well, we need to start somewhere with this blog and opencode is a great harness.\n\nThere 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. \n\n### Installing the tools\n\n**Install Docker Sandbox:**\n\n```\nbrew trust docker/tap && brew install docker/tap/sbx\n```\n\n**Install Opencode:**\n\n```\nbrew install anomalyco/tap/opencode\n```\n\n**Install Ollama:**\n\nTo install ollama, goto [https://ollama.com/](https://ollama.com/) and download and install the app.\n\n### Installing the models\n\nFor the models, we'll pull 2 models. First ensure ollama is running.\n\n**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.\n\n```\nollama pull qwen3.8:27b-mxfp8\n```\n\n**Gemma 4 31b mxfp8 (34GB):** This is a great big dense model when you need something bigger.\n\n```\nollama pull gemma4:31b-mxfp8\n```\n\n**Note:** If you don't have the 48GB Apple, you can pull the standard models: `qwen3.8:27b-mlx` and `gemma4:31b-mlx` . \n\n### Configuring your project\n\nFor 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:\n\n```\n./sbx-kit/files/home/.config/opencode-local.json\n./sbx-kit/spec.yaml\n```\n\n**spec.yaml**\n\n```\nschemaVersion: \"2\"\nkind: mixin\nname: local-ollama-opencode\nversion: \"0.1.0\"\ndisplayName: Local Ollama for OpenCode\ndescription: Configure OpenCode in Docker Sandboxes to use Ollama running on the Mac host.\n\nrequires:\n  agent: opencode\n\nenvironment:\n  variables:\n    OPENCODE_CONFIG: /home/agent/.config/opencode-local.json\n\npermissions:\n  network:\n    allow:\n      - localhost:11434\n      - localhost:5173\n      - localhost:4000\n\nagentInstructions:\n  content: |\n    Local Ollama runs on the host machine.\n\n    Default model:\n      qwen3.8:27b-mxfp8\n\n    Deep file analysis / reasoning:\n      gemma4:31b-mxfp8\n```\n\n**opencode-local.yaml**\n\n```\n{\n  \"$schema\": \"https://opencode.ai/config.json\",\n\n  \"model\": \"ollama/qwen3.8:27b-mxfp8\",\n  \"small_model\": \"ollama/qwen3.8:27b-mxfp8\",\n  \"lsp\": false,\n\n  \"provider\": {\n    \"ollama\": {\n      \"npm\": \"@ai-sdk/openai-compatible\",\n      \"name\": \"Mac Ollama\",\n\n      \"options\": {\n        \"baseURL\": \"http://host.docker.internal:11434/v1\"\n      },\n\n      \"models\": {\n        \"qwen3.8:27b-mlx\": {\n          \"name\": \"Qwen 3.8 27B MLX [18 → ~35 GB] [256K ctx]\",\n          \"limit\": {\n            \"context\": 262144,\n            \"output\": 8192\n          },\n          \"variants\": {\n            \"low\": {\n              \"reasoningEffort\": \"low\"\n            },\n            \"medium\": {\n              \"reasoningEffort\": \"medium\"\n            },\n            \"high\": {\n              \"reasoningEffort\": \"high\"\n            },\n            \"xhigh\": {\n              \"reasoningEffort\": \"xhigh\"\n            }\n          }\n        },\n\n        \"qwen3.8:27b-mxfp8\": {\n          \"name\": \"Qwen 3.8 27B MXFP8 [31 → ~48 GB] [256K ctx]\",\n          \"limit\": {\n            \"context\": 262144,\n            \"output\": 8192\n          },\n          \"variants\": {\n            \"low\": {\n              \"reasoningEffort\": \"low\"\n            },\n            \"medium\": {\n              \"reasoningEffort\": \"medium\"\n            },\n            \"high\": {\n              \"reasoningEffort\": \"high\"\n            },\n            \"xhigh\": {\n              \"reasoningEffort\": \"xhigh\"\n            }\n          }\n        }\n      }\n    }\n  }\n}\n```\n\nFor 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.\n\n### Run Opencode\n\nTo run opencode, run the following:\n\n```\nsbx run opencode --kit ./sbx-kit/\n```\n\nThis will start Opencode with Qwen selected. Ensure you change down to \"low\" effort via `/models` command.\n\nYou should be good to go.\n\n**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.\n\n[← Back to the latest](/)", "url": "https://wpnews.pro/news/setting-up-opencode-with-ollama-and-sbx-on-mac", "canonical_source": "https://tensorsandtokens.com/posts/opencode-ollama/", "published_at": "2026-09-11 00:45:26+00:00", "updated_at": "2026-09-11 00:53:00.387355+00:00", "lang": "en", "topics": ["large-language-models", "ai-tools", "developer-tools", "ai-products"], "entities": ["OpenCode", "Ollama", "Docker Sandboxes", "Qwen 3.8", "Gemma 4", "Apple MacBook Pro M5", "Docker"], "alternates": {"html": "https://wpnews.pro/news/setting-up-opencode-with-ollama-and-sbx-on-mac", "markdown": "https://wpnews.pro/news/setting-up-opencode-with-ollama-and-sbx-on-mac.md", "text": "https://wpnews.pro/news/setting-up-opencode-with-ollama-and-sbx-on-mac.txt", "jsonld": "https://wpnews.pro/news/setting-up-opencode-with-ollama-and-sbx-on-mac.jsonld"}}