{"slug": "opencode-custom-provider-in-docker-sandbox", "title": "OpenCode Custom Provider in Docker Sandbox", "summary": "A developer has published a guide for configuring OpenCode, an AI coding assistant, to use a custom provider within a Docker sandbox environment. The write-up details setting up an opencode.jsonc configuration file with a custom provider using the @ai-sdk/openai-compatible package, and explains how to securely pass API keys as environment variables when running in containers. The guide also covers enabling or disabling providers via whitelist or blacklist settings.", "body_md": "A simple guide/writeup to myself and others when setting up OpenCode inside a Docker sandbox.\n\n`opencode.jsonc`\n\nconfig:\n\n```\n{\n  \"$schema\": \"https://opencode.ai/config.json\",\n  \"lsp\": true,\n  // see note below\n  \"enabled_providers\": [\n    \"custom_provider\"\n  ],\n  \"provider\": {\n    \"custom_provider\": {\n      \"npm\": \"@ai-sdk/openai-compatible\",\n      \"name\": \"My Custom Provider\",\n      \"options\": {\n        \"baseURL\": \"https://custom_provider.example.com/v1\",\n        // see note below\n        \"apiKey\": \"{env:CUSTOM_PROVIDER_API_KEY}\"\n      },\n      \"models\": {\n        \"mistral.devstral-2-123b\": {\n          \"name\": \"mistral.devstral-2-123b\"\n        },\n        \"openai.gpt-oss-120b-1:0\": {\n          \"name\": \"openai.gpt-oss-120b-1:0\"\n        },\n        \"openai.gpt-oss-20b-1:0\": {\n          \"name\": \"openai.gpt-oss-20b-1:0\"\n        }\n      }\n    }\n  }\n}\n```\n\nThere’s a default config in your user (check the docs for OpenCode) but OpenCode will also consume the closest one in your directory tree. This is very handy when running in a sandbox that only has access to a sub-directory tree on your disk.\n\nIf you run OpenCode in a container such as Docker Sandboxes, which is good because then the agents can’t access your whole machine, but requires more setup, you have to pass in your API key as an environment variable when setting up. Here’s an example for docker `sbx`\n\n:\n\n```\nexport CUSTOM_PROVIDER_API_KEY=**************** && \\\n    sbx secret set-custom \\\n    --host custom_provider.example.com \\\n    --env CUSTOM_PROVIDER_API_KEY \\\n    --value \"$CUSTOM_PROVIDER_API_KEY\"\n```\n\nOpenCode supports numerous providers, enabled by default. You can either blacklist (`disabled_providers: [...]`\n\n) or whitelist them (`enabled_providers: [...]`\n\n).", "url": "https://wpnews.pro/news/opencode-custom-provider-in-docker-sandbox", "canonical_source": "https://dev.to/stoft/opencode-custom-provider-in-docker-sandbox-166b", "published_at": "2026-09-03 15:12:41+00:00", "updated_at": "2026-09-03 15:26:51.587436+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "ai-agents"], "entities": ["OpenCode", "Docker", "@ai-sdk/openai-compatible", "Mistral", "OpenAI"], "alternates": {"html": "https://wpnews.pro/news/opencode-custom-provider-in-docker-sandbox", "markdown": "https://wpnews.pro/news/opencode-custom-provider-in-docker-sandbox.md", "text": "https://wpnews.pro/news/opencode-custom-provider-in-docker-sandbox.txt", "jsonld": "https://wpnews.pro/news/opencode-custom-provider-in-docker-sandbox.jsonld"}}