# Enterprise

Use [policies](/policies) to control what OpenCode can use on your organization's machines. Put them in managed
configuration so users and projects can't change them.

## Deploy

Put the policies in the system configuration file:

| Platform | File                                                  |
| -------- | ----------------------------------------------------- |
| macOS    | `/Library/Application Support/opencode/opencode.json` |
| Linux    | `/etc/opencode/opencode.json`                         |
| Windows  | `%ProgramData%\opencode\opencode.json`                |

On macOS, you can also deploy them with MDM as managed preferences for the `ai.opencode.managed` domain. See
[config locations](/config#locations).

```jsonc title="/etc/opencode/opencode.json"
{
  "$schema": "https://opencode.ai/config.json",
  "policies": [{ "action": "integration.use", "resource": "opencode", "effect": "deny" }],
}
```

Policies in these files outrank user and project configuration, so a user or repository can't allow something you deny.
See [precedence](/policies#precedence).

## Block free models

Deny the signed-out free tier. Everything else still works, and people can connect their own providers and accounts.

```jsonc
{
  "policies": [{ "action": "integration.use", "resource": "opencode", "effect": "deny" }],
}
```

The free tier is the `opencode` integration with no account. Signed-in Console accounts are `opencode#<account>`, so
this statement doesn't affect them.

A Console workspace can also offer free models. To block them:

- In your own workspace, turn off **Free models** on the Console's Models tab. See
  [OpenCode models](/console/providers#opencode-models).
- To hide free models in every account, set `OPENCODE_DISABLE_FREE_MODELS=1` on the OpenCode service. See
  [free models](/models#free-models).

## Require your Console workspace

Allow only your organization's Console workspace. Nothing else can be connected or used.

```jsonc
{
  "policies": [
    { "action": "integration.connect", "resource": "*", "effect": "deny" },
    { "action": "integration.connect", "resource": "opencode", "effect": "allow" },
    { "action": "integration.use", "resource": "*", "effect": "deny" },
    { "action": "integration.use", "resource": "opencode#org_01M3CAP8H43Z49CER6NT0Y3ZF1", "effect": "allow" },
  ],
}
```

- `/connect` lists only the OpenCode Console, so people can sign in.
- Only your workspace works. The free tier, personal Console accounts, other organizations, API keys from environment
  variables, and providers from `opencode.json` are blocked.
- Your workspace's models, MCP servers, and web search work. Change them in the Console without redeploying the policy.

Replace `org_01M3CAP8H43Z49CER6NT0Y3ZF1` with your workspace's organization ID. To block free models in the workspace
too, turn off **Free models** in the Console.

## Allow only approved providers

Deny every provider, then allow the ones you approve. This example allows only an internal OpenAI-compatible gateway.

```jsonc
{
  "providers": {
    "company-ai": {
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": { "baseURL": "https://ai.company.example/v1" },
    },
  },
  "policies": [
    { "action": "provider.use", "resource": "*", "effect": "deny" },
    { "action": "provider.use", "resource": "company-ai", "effect": "allow" },
  ],
}
```

A denied provider is removed even when someone has credentials for it. See [providers](/policies#providers).

## Restrict MCP servers and tools

Allow only approved MCP servers, and block tools you don't want agents to run.

```jsonc
{
  "policies": [
    { "action": "mcp.use", "resource": "*", "effect": "deny" },
    { "action": "mcp.use", "resource": "github", "effect": "allow" },
    { "action": "tool.use", "resource": "shell:git push *", "effect": "deny" },
    { "action": "tool.use", "resource": "read:*/.ssh/*", "effect": "deny" },
  ],
}
```

See [MCP servers, skills, and plugins](/policies#mcp-servers-skills-and-plugins) and [tools](/policies#tools).

## Hardening template

Put this template in the system configuration file (see [Deploy](#deploy)).

```jsonc title="/etc/opencode/opencode.json"
{
  "$schema": "https://opencode.ai/config.json",
  "policies": [
    { "action": "tool.use", "resource": "browser:*", "effect": "deny" },
    { "action": "mcp.use", "resource": "*", "effect": "deny" },
    { "action": "mcp.use", "resource": "github", "effect": "allow" },
    { "action": "plugin.use", "resource": "*", "effect": "deny" },
  ],
}
```

- `tool.use` on `browser:*` blocks agents from the desktop app's built-in browser. People can still use the browser
  themselves.
- `mcp.use` allows only the MCP servers you name. Replace `github` with your approved server names.
- `plugin.use` blocks plugins from npm packages and local paths. Add an `allow` after it for each plugin you approve.

To also require a person's approval for every shell command, add these statements.

```jsonc
{
  "policies": [
    { "action": "experimental.permission.save", "resource": "*", "effect": "deny" },
    { "action": "experimental.tool.auto", "resource": "shell:*", "effect": "deny" },
  ],
}
```

- `experimental.permission.save` turns off **Allow always** and ignores saved approvals.
- `experimental.tool.auto` makes every shell command ask, even where an agent's rules allow it.

### Remote access

The background service listens on `127.0.0.1` and requires a password it generates on first start. Remote access is
off until someone runs `opencode pair --remote` or `opencode service set remote true`. Either command serves OpenCode on
the internet through an OpenTunnel address under `opentunnel.xyz`.

No policy turns remote access off. Service settings live in each user's configuration directory, so users can change
them. On managed machines, run these as each user and block the tunnel domains.

1. Run `opencode service get remote`. If it prints `true`, run `opencode service set remote false`.
2. Run `opencode service get hostname`. If it prints an address other than `127.0.0.1`, run
   `opencode service unset hostname`.
3. Block `opentunnel.xyz` and `*.opentunnel.xyz` in your network or endpoint controls. This holds even if a user turns
   remote access back on.

Block other tunnel services, such as ngrok and Cloudflare Tunnel, the same way. They can expose any local port,
including OpenCode's.

### Console workspace

A [Console workspace](/console#policies) can block the browser too. On the workspace's Policies page, add a Tools rule
for `browser`.

Keep the system file as the baseline. Disconnecting a workspace clears its policies (see [Console](/policies#console)),
while the system file stays in place. To allow only your workspace, also deploy
[Require your Console workspace](#require-your-console-workspace).

The Console rule that limits members to approved MCP servers covers only the servers the workspace provides. Keep
`mcp.use` in the system file for servers configured on the machine.

## Check it works

- Run `/connect` and `/models` as a user and confirm only what you allowed appears.
- Check the server log for warnings. A statement that fails validation is dropped and the rest still apply.
- A blocked tool call fails with `Blocked by configuration policy`, or `Blocked by <workspace>'s policy` when the rule
  comes from a Console workspace. To check the browser block, ask an agent in the desktop app to open a web page.
- Run `opencode debug config` to print every configuration source OpenCode loaded, with its `policies`.

## Versions

| Action                                                                         | Requires |
| ------------------------------------------------------------------------------ | -------- |
| `integration.connect`, `integration.use`, `mcp.use`, `skill.use`, `plugin.use` | 2.2.3    |
| `websearch.use`                                                                | 2.2.6    |
| `tool.use` for the built-in browser                                            | 2.4.0    |
| `experimental.tool.auto`, `experimental.permission.save`                       | 2.4.4    |

Older clients ignore these statements.