Documentation Index
Fetch the complete documentation index at: https://developer.upsun.com/llms.txt
Use this file to discover all available pages before exploring further.
OpenCode is an open-source AI coding agent built for the terminal. This guide walks you through deploying an
OpenCode server instance on Upsun, a git-driven PaaS (powered by Platform.sh) that makes it easy
to deploy applications with a single git push.
Prerequisites
Before starting, make sure you have:- An Upsun account (15-day free trial available)
- The Upsun CLI installed
- Git installed
- An API key for at least one LLM provider (e.g., Anthropic, OpenAI, Google Gemini)
Overview
OpenCode is an application with a client/server architecture. In this tutorial, you deploy the OpenCode server on Upsun and connect to it remotely. The server exposes an HTTP API, which allows you to drive OpenCode from any client (TUI, IDE extension, or web) without having the agent running locally. The deployment relies on anodejs:24 runtime, persistent storage for the SQLite database that stores conversation
sessions, environment variables to securely pass LLM API keys, and routes to expose the server over HTTPS.
Step 1 - Set up your project
Clone or initialize a repository that contains your OpenCode configuration. If you are starting from scratch, create a new directory:Terminal
Step 2 - Create the Upsun configuration
At the root of your project, create the.upsun/ directory and add a config.yaml file:
Terminal
.upsun/config.yaml
mounts section defines writable directories so OpenCode can persist its SQLite database (sessions, conversations) and its config file across deploys.
The hooks.build section downloads and installs the OpenCode binary before the container starts, installs the Upsun skills (which include the MCP server), and the Upsun CLI.
The web.commands.start section launches OpenCode in server mode. Upsun injects $PORT automatically, and your app must listen on that port.
Finally, routes maps your project’s default domain to the OpenCode HTTP server.
install-github-asset.sh script
If you want to learn more about the script used to download OpenCode, check out the Up(sun) and ready with GitHub release assets installation.
It’s a reusable script that can download any asset from any GitHub release, and is especially useful in Upsun build
hooks where you want to fetch the latest version of a tool only once and, without hardcoding a specific version number.Step 3 - Create the OpenCode configuration
OpenCode uses anopencode.json file to configure the server application.
This file configures the Upsun MCP server as a remote MCP server for OpenCode,
which allows OpenCode to execute commands on the Upsun platform and interact with its resources.
Create an opencode.json file at the root of your repository with the following content:
opencode.json
Step 4 - Commit your code
Commit your configuration:Terminal
Step 5 - Create the Upsun project
Create a new Upsun project linked to your local repository:Terminal
Step 6 - Add your API keys as environment variables
Never commit API keys to your repository. Use Upsun’s variable system instead.OPENCODE_SERVER_PASSWORD note
By default, OpenCode’s server mode requires a password for authentication.
You can set this password via the OPENCODE_SERVER_PASSWORD environment variable.
If you prefer to disable authentication (not recommended for production), you can set OPENCODE_SERVER_PASSWORD to an empty string.Step 7 - Deploy
Push your code to Upsun:- Validate your
.upsun/config.yaml - Spin up a Node.js 24 container
- Run the build hook:
- downloading the OpenCode binary
- installing the Upsun skills and MCP server
- installing the Upsun CLI
- Run the deploy hook, which generates the OpenCode config file with the correct MCP server URL and API token
- Mount writable storage for the database and config
- Start the OpenCode server on the assigned port
- Route HTTPS traffic to it
Login
Open the URL in your browser. If you setOPENCODE_SERVER_PASSWORD, log in with the username opencode and
the password you configured. You can also connect from the OpenCode TUI client by pointing it to the same URL.Step 8 - Ask OpenCode to do something
OpenCode is now able to receive your commands from the TUI, execute them on the server, and return results. Examples: List existing organizations:Advanced: deploy a Symfony Demo app in a preview environment
Advanced: deploy a Symfony Demo app in a preview environment
Create a new Symfony application in a
symfony subfolder and test it in a preview environment:Troubleshooting
The server does not start / PORT is not set
Upsun automatically injects$PORT into the environment of the start command. Make sure your start command references $PORT and that OpenCode’s serve command accepts a --port flag. Check opencode serve --help for the exact flag name, as it may vary across versions.
Sessions are not persisting across deploys
Verify that your mounts are defined correctly in.upsun/config.yaml and that the paths match where OpenCode writes its SQLite database. The database path can be checked with:
API key not recognized
Confirm the variable is set in the correct environment:[hidden] — that is expected. Make sure the variable name matches exactly what OpenCode expects (e.g., ANTHROPIC_API_KEY).
OpenCode is slow to respond
If OpenCode is slow to respond, or stops in the middle of processing, check the resource usage of your Upsun container. You may need to scale up CPU/RAM if your agent is handling large contexts or multiple conversations.What’s next?
You can attach a custom domain withupsun domain:add yourdomain.com and adjust CPU/RAM
through upsun resources:set if the agent handles large contexts or multiple conversations.
To extend OpenCode with additional MCP server integrations,
configure them in ~/.config/opencode/ on the persistent mount. You can also use OpenCode’s
GitHub Actions integration to trigger the remote server on PR comments.