Learn how to set up OpenCode with Ollama and sbx on your Mac for local AI development.
As artificial intelligence continues to evolve, local model development becomes increasingly viable for developers. With tools like OpenCode, Ollama, and Docker Sandboxes (sbx), Mac users can harness the power of large language models (LLMs) directly on their devices. This guide provides a detailed walkthrough on setting up OpenCode with Ollama and sbx on a Mac, ideal for those looking to create powerful web applications using advanced models like Qwen 3.8 and Gemma 4.
To kickstart your local AI development environment, you need to install the necessary tools. The three key components here are OpenCode, Ollama, and Docker. Follow these steps to get them set up on your Mac.
First, if you haven’t already, install Homebrew, which is a package manager for macOS. You can do this by entering the following command in your terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Next, you’ll need to install Docker. Open your terminal and type:
brew install --cask docker
After the installation, make sure Docker is running before proceeding.
With Docker up and running, it is time to install sbx, which allows you to create Docker sandboxes.
To do so, execute:
brew tap docker/tap && brew install docker/tap/sbx
Now, it's time to download and install Ollama. Visit the Ollama website and follow the instructions to download the application.
Setting up the right models is crucial, as they will serve as the backbone of any project you undertake in your local environment. For this guide, we will be focusing on two powerful models: Qwen 3.8 and Gemma 4.
After successfully setting up Ollama, you can pull the models. First, ensure Ollama is actively running. To install the Qwen 3.8 model, use the following command in your terminal:
ollama pull qwen3.8:27b-mxfp8
This model, which requires 32GB of memory, is great for extended tasks and can handle sustained loads efficiently.
Next, to download the Gemma 4 model, which requires 34GB of memory, enter:
ollama pull gemma4:31b-mxfp8
If you're using a system with less than 48GB of Apple memory, you can still work with the standard model versions:
qwen3.8:27b-mlx
and
gemma4:31b-mlx.
To create a sustainable development environment with OpenCode, you need to set up a sandbox kit for each project. This customization allows you to run different projects without conflicts. Follow these steps to create a sandbox kit.
Create a directory for your project and inside it, add a YAML configuration file named `opencode-local.yaml` that specifies how your sandbox should operate. Here’s an example template for your YAML file:
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
This template configures your OpenCode instance in a Docker sandbox, allowing it to use your locally running Ollama models.
Once you've set up the sandbox configuration, you’re ready to run OpenCode. In your terminal, navigate to your project directory and execute the following command:
sbx run opencode --kit ./sbx-kit/
This command will start OpenCode with the Qwen model selected by default. For optimal performance, especially when working with larger models, remember to adjust the model effort settings via the `/models` command in OpenCode to "low effort." This helps reduce system strain and optimize response times.
The combination of OpenCode, Ollama, and Docker Sandboxes presents developers with a robust framework for AI model development directly on their Mac systems. As tools continue to evolve, the ability to leverage powerful models like Qwen 3.8 and Gemma 4 can efficiently support complex applications while providing the flexibility of local execution. This setup enables developers to innovate without the constraints of cloud reliance while maintaining full control over model interactions.
OpenCode is a framework that allows developers to build applications using large language models in a local environment, enhancing both control and performance.
Ollama simplifies the process of managing large language models, ensuring ease of use and stability, particularly on Apple Silicon devices.
While it's possible to run models without Docker, using Docker provides a streamlined and isolated environment that helps prevent potential conflicts and enhances performance.