Join our Discord Server
Collabnix Team The Collabnix Team is a diverse collective of Docker, Kubernetes, and IoT experts united by a passion for cloud-native technologies. With backgrounds spanning across DevOps, platform engineering, cloud architecture, and container orchestration, our contributors bring together decades of combined experience from various industries and technical domains.

Local and Hosted Models in Docker Sandboxes: Running Agents on llmman, Ollama, OpenAI and Custom Endpoints with sbx run –model

6 min read

Terminal-style banner showing the command sbx run --model gemma4 --provider ollama claude with the title Local and Hosted Models in Docker Sandboxes

Docker Sandboxes run coding agents such as Claude Code, Codex and OpenCode inside isolated microVMs, so the agent can install packages, edit files and run commands without touching your host. Until recently, the model behind those agents was whatever the agent shipped with. The Docker docs now include a dedicated guide, Use local and hosted models, that explains how to pick the model and the service that answer your agent’s requests with a single sbx run --model flag.

This matters for three practical reasons. You can keep prompts and code on your own machine by using a local GGUF model. You can reuse an Ollama setup you already have. And you can point agents at an internal, OpenAI-compatible or Anthropic-compatible GPU server while the API key stays outside the sandbox. This post walks through each path, the commands involved, and the settings that control the bundled model service, called llmman.

Prerequisites

  • The sbx CLI installed and signed in on your host. Follow the install guide for macOS, Windows or Linux.
  • A local sandbox. The guide states that --model is not supported with cloud sandboxes or with v3 kits.
  • One of the built-in agents covered by the guide: claude, codex or opencode.
  • A model that supports the tool calls and context length your agent needs.
  • Network access on first startup, because llmman downloads its llama.cpp runtime if it is missing.
  • Optional: Ollama installed and running on the host, or an API key for a hosted provider or a custom endpoint.

How the bundled llmman service works

Docker Sandboxes ships with llmman, a model management tool that is installed alongside sbx. You do not install it separately. It does two jobs: it serves local models, and it forwards requests to hosted providers or to custom endpoints you define.

A few behaviors are worth knowing before you start:

  • The Docker Sandboxes daemon starts llmman on your host and stops it when the daemon stops. It starts even if you never pass --model.
  • The service keeps running after a sandbox or the CLI exits. All sandboxes share its model store and its loaded models, so a model pulled once is reused.
  • Local models run on the host, not inside the microVM. Their memory and compute needs are separate from the sandbox resource limits you set with flags like --cpus and --memory.
  • On Linux, llmman first tries Docker or Podman to run the inference server in a container. If neither works, it tries a downloaded binary, and then llama-server on the host PATH.

If you never use local or hosted models through llmman, you can switch the service off so it skips the runtime download:

sbx settings set model.server.enabled false
sbx daemon restart

The restart applies the change. Note that if the daemon was not running, the settings command starts it first, so the service may begin its download before you restart. Ollama still works with the bundled service disabled. To turn it back on:

sbx settings set model.server.enabled true
sbx daemon restart

Step 1: Enable model selection

Model selection is experimental, so you need to opt in on the host before any --model example works. Two settings are required: one that allows experimental features in general, and one that turns on the model feature itself.

sbx settings set platform.allowExperimentalFeatures true
sbx settings set feature.model true

After that, the --provider flag decides where the model runs:

  • Omitted, or llmman: a local model managed by llmman.
  • ollama: an existing Ollama installation on your host.
  • A hosted provider ID such as openai or anthropic: a provider that llmman supports.
  • An ID you defined in model.providers: your own inference endpoint.

Step 2: Run a local model or use Ollama

The simplest path is a local model served by llmman. Pass a GGUF model reference or a short name to --model, followed by the agent:

sbx run --model gemma4 claude

Docker Sandboxes downloads the model if needed and runs it on the host. To use the same model with a different agent, replace claude with codex or opencode. Because the model store is shared, a second sandbox using gemma4 does not trigger another download.

If you already run Ollama, select it with --provider ollama:

sbx run --model gemma4 --provider ollama claude

Docker Sandboxes connects to Ollama at localhost:11434. It does not install, start or manage the Ollama process, so make sure Ollama is running and the model is available before you launch the sandbox. If you prefer Docker Model Runner, the docs have a separate guide: Run Claude Code in a Docker Sandbox with Docker Model Runner.

Step 3: Use a hosted provider without exposing the key

For a hosted model, store the provider key on the host with sbx secret set, using the same ID you pass to --provider. Then run the agent with a model from that provider. The guide’s example runs Codex against an OpenAI model:

sbx secret set openai
sbx run --provider openai --model gpt-5-nano codex

Here llmman acts as a forwarder. It does not download or run the hosted model. The list of supported providers and their API key variable names lives in the llmman provider documentation.

The credential flow is the interesting part. The sandbox only ever sees a placeholder value. The host proxy swaps in the stored key, and only in authentication headers on requests that go to the host’s llmman service. llmman then authenticates to the provider. Docker Sandboxes wires this up automatically when you select the provider, so you do not need sbx secret set-custom or domain injection rules. Sandbox-scoped secrets take precedence over global ones.

Read the warning in the guide carefully: model provider keys are protected differently from other sandbox credentials. For normal credentials, the proxy only injects them for their configured domains. For model providers, the key is supplied to llmman, and llmman can forward it to any endpoint it supports. Selecting --provider does not lock the key to that one provider endpoint.

If you do not store a secret, the key must be present in the environment of the host shell that starts the daemon, because llmman inherits the daemon environment. After changing that variable, run sbx daemon restart from the same shell. That restart also restarts the model service and interrupts in-flight model requests from sandboxes. Setting the variable only in the shell where you call sbx run --model does nothing for a service that is already running. Stored secrets avoid this restart entirely.

Step 4: Connect a custom inference endpoint

Teams with an internal GPU server can register it through the model.providers setting. It is a JSON object keyed by provider ID, and setting it replaces the whole object, so check the current value first:

sbx settings get model.providers

Then define a provider. This example registers an OpenAI-compatible endpoint under the ID company:

sbx settings set model.providers '{"company":{"url":"https://inference.example.com/v1","wire":"openai"}}'

The supported fields are:

  • url: required HTTP or HTTPS base URL, usually ending in /v1. Do not include /chat/completions or /messages.
  • wire: the API format the endpoint speaks, openai (the default) or anthropic. It describes the endpoint, not the agent you run.
  • apiKeyEnv: optional name of a host environment variable holding the key, used only as a fallback when no stored secret exists.
  • name: optional display name that defaults to the provider ID.

The endpoint must be reachable from your host, not from the sandbox. If it needs a key, store it under the provider ID and run an agent against it:

sbx secret set company
sbx run --provider company --model MODEL_NAME claude

The same provider works with codex or opencode.

Step 5: Change models and reasoning levels

You do not need a new sandbox to try a different model. Pass the existing sandbox name with the new selection:

sbx run --name SANDBOX_NAME --model MODEL_NAME --provider PROVIDER_ID

This recreates the sandbox container, while the workspace and kit-owned volumes persist. Leave out --provider to switch to a local llmman model.

For models that support it, --variant sets a reasoning level. The documented levels are minimal, low, medium, high, xhigh and max, and some models also accept none or thinking. Values depend on the model and agent:

sbx run --provider openai --model MODEL_NAME --variant high codex

According to the guide, Claude Code does not support none or minimal. For Claude Code and Codex, --variant needs an attached session and cannot be combined with --detach. In OpenCode it only sets the starting variant, which you can change inside OpenCode.

Local sandboxes vs Cloud Sandboxes

Everything in this guide applies to local sandboxes. The guide is explicit that --model is not supported with cloud sandboxes, and it is also not supported with v3 kits. The reason is architectural: llmman, Ollama and the credential swap all live on your host, and a local sandbox reaches them through the host proxy. A Docker Cloud Sandbox runs away from your machine, so this host-side model plumbing does not apply there. If your workflow depends on a local model or an internal endpoint, plan to run that agent in a local sandbox. For how the two modes differ in general, see Local vs cloud sandboxes.

Troubleshooting tips from the docs

  • First run is slow or fails offline. llmman downloads its llama.cpp runtime on first startup. Make sure the host has network access, or disable the service with model.server.enabled false if you only use Ollama.
  • Ollama provider cannot connect. Docker Sandboxes expects Ollama at localhost:11434 and never starts it for you. Start Ollama on the host first.
  • A new API key is ignored. If you rely on environment variables, restart the daemon from the shell that holds the updated variable. Better, store the key with sbx secret set.
  • A custom provider vanished. model.providers is replaced as a whole. Run sbx settings get model.providers first and include every provider you want to keep.
  • The endpoint URL returns errors. Use the base URL only, without /chat/completions or /messages, and confirm wire matches the endpoint API format.
  • –model is rejected. Check that both experimental settings are on, and that you are not targeting a cloud sandbox or a v3 kit.

Key takeaways

  • sbx run --model lets Claude Code, Codex and OpenCode use local, Ollama, hosted or custom models from inside a local sandbox.
  • Model selection is experimental and needs platform.allowExperimentalFeatures and feature.model set to true.
  • llmman runs on the host, shares one model store across sandboxes, and can be turned off with model.server.enabled false.
  • Provider keys never enter the sandbox, but they are scoped to llmman rather than to a single provider endpoint.
  • Custom endpoints are defined in model.providers, which is replaced in full on every set.
  • Switching models on an existing sandbox recreates the container and keeps the workspace.

References

Source guide: Use local and hosted models on docs.docker.com. Related pages: Install Docker Sandboxes, Manage credentials, Sandbox settings, Local vs cloud sandboxes, Run Claude Code in a Docker Sandbox with Docker Model Runner, and the llmman provider list.

Have Queries? Join https://launchpass.com/collabnix

Collabnix Team The Collabnix Team is a diverse collective of Docker, Kubernetes, and IoT experts united by a passion for cloud-native technologies. With backgrounds spanning across DevOps, platform engineering, cloud architecture, and container orchestration, our contributors bring together decades of combined experience from various industries and technical domains.

Understanding AI Embeddings and Vector Search for Beginners

Explore the world of AI embeddings and vector search, learning how they transform massive data into actionable insights, driving intelligent systems.
Collabnix Team
9 min read

Leave a Reply

Join our Discord Server