Skip to main content
OpenCode runs its tools inside the box. Configure it with its native JSON file and submit a task through boxlite exec. Complete the workstation setup. Run all commands below on your workstation.

Create the box and install OpenCode

Save create.py. Before running it, replace <YOUR_MODEL_HOST> with your model endpoint’s hostname, without the scheme or path. The prompt reads the real model key on your workstation; only BoxLite’s Secret configuration receives it.
create.py
Install the agent:

Configure OpenCode

Save opencode.json locally. Keep the apiKey placeholder exactly as shown:
opencode.json
Use an OpenAI Chat Completions-compatible endpoint with tool support. Replace the API base URL and <MODEL_ID>, and set Secret.hosts in create.py to the endpoint hostname. For another provider, use OpenCode’s native provider configuration and match the Secret’s hosts to its API endpoint. permission: "allow" lets this trusted task use tools without interactive approval. The agent can use the model connection and access the files and network available inside its box. The real provider key remains outside it. Upload the placeholder-only configuration:

Run a task

OpenCode is ready. Repeat the command with your own task. This example starts a new session for each call.

Optional: wake on a request

OpenCode provides a native HTTP server. This walkthrough creates a separate opencode-http box and sends tasks through its session API. Run these commands on your workstation in the directory containing opencode.json from above. Automatic stop is optional: use auto_stop=0 to keep the service running.

1. Create the service box

Save create-http.py, using the same model Secret and endpoint hostname as above:
create-http.py
The startup command waits for the installation and configuration, then starts OpenCode on every boot.

2. Install and configure the server

Generate a caller password locally. This password protects the HTTP API; it is separate from the model credential.
Keep server-password outside Git. OpenCode reads this caller password inside the box; the real model key stays in BoxLite Secret.

3. Create a session and run a task

Set OPENCODE_URL to the HTTPS URL from the tunnel command. Keep this shell open for the wake check.
Retry the health request after a few seconds if the server is still starting. Create a session and save its ID:
Send a task through the native message API:
Check that the response has no info.error and that the independent file check prints the expected value.

4. Wait for automatic stop

Stop sending HTTP requests, including health checks. Use only this control-plane check until Status is stopped:
Allow two idle minutes. Do not call start, exec, or cp before the next request.

5. Wake the server, then submit a task

Use an authenticated health request to wake the box and wait for OpenCode to be ready. This external request starts the box and its saved server command; do not call start or exec first.
This read-only health check retries startup failures and timeouts. Continue when it succeeds with "healthy": true; if it exhausts its retries, inspect the server before submitting a task. Then send a message to the existing session:
The session is retained across the stop. After the task response, verify retained work and the new task:
Leave it idle again and it stops automatically. Use the health request for cold startup: direct message submission during startup did not complete in this guide’s Cloud test. A task timeout can leave partial effects; inspect the session before resubmitting it.

6. Clean up

When you are finished