OpenCode on Hugging Face Spaces

Run OpenCode β€” an open-source AI coding agent that supports 75+ LLM providers β€” in your browser, hosted on Hugging Face's free CPU tier.

Setup (one-time, ~2 minutes)

  1. Duplicate this Space to your own HF account (top-right β†’ Duplicate Space).

  2. Add your secrets in Settings β†’ Variables and secrets:

    Secret name Required? Where to get it
    OPENCODE_SERVER_PASSWORD Yes Any password you choose β€” protects the web UI
    ANTHROPIC_API_KEY One of these https://console.anthropic.com
    OPENAI_API_KEY (pick your https://platform.openai.com/api-keys
    GEMINI_API_KEY provider) https://aistudio.google.com/apikey
    OPENCODE_API_KEY https://opencode.ai/zen (curated models)
  3. The Space will rebuild (~60-90 seconds) and start on the URL shown above.

  4. Log in with username opencode and the password you set.

That's it. You now have a free, browser-accessible AI coding agent.

How it works

  • The Dockerfile installs OpenCode via the official install script and runs opencode web.
  • The web UI is bound to 0.0.0.0:4096 so HF's reverse proxy can reach it.
  • HTTP basic auth is enabled via the OPENCODE_SERVER_PASSWORD secret.
  • Your workspace lives at /home/user/workspace inside the container.

Using OpenCode

Once you're in the web UI:

  • New session β†’ describe what you want to build, refactor, or fix
  • Files panel β†’ browse your workspace, upload code, or open the in-browser editor
  • Plan mode (press Tab) β†’ have the agent draft a plan before changing anything
  • Share β†’ get a public link to any session for sharing or debugging
  • /init β†’ generates an AGENTS.md for your project so OpenCode remembers context across sessions

For full usage docs, see https://opencode.ai/docs/

Persistence: read this

Free CPU Spaces are ephemeral. Anything not pushed to git will be lost when the Space restarts (which happens after ~48h of inactivity, or when the free tier quota resets).

Recommended workflow:

  1. In the OpenCode terminal, cd workspace
  2. git clone https://github.com/your-user/your-repo.git
  3. Work on the project
  4. git add . && git commit -m "..." && git push before stepping away

For pure scratch work (no git), everything resets on restart β€” so commit early and often.

Caveats

  • CPU only β€” no GPU. The agent works fine; you just can't run local LLMs here.
  • Sleeps after ~48h idle on the free tier (Hugging Face does this automatically).
  • Resource limits β€” free CPU Spaces are throttled compared to local dev. Heavy multi-file refactors can be slower.
  • No outbound ports β€” the agent can git clone public repos, but you can't expose additional services.
  • CORS / session storage β€” sessions live in the container's filesystem, so restarts wipe them. Use the /share command to save a session URL externally.

If you want to upgrade later

When you outgrow the free tier:

Need Upgrade to
Always-on, no sleep HF Spaces paid CPU ($0.03/hr β‰ˆ $5/mo)
Persistent storage HF Spaces Storage bucket add-on
More CPU/RAM Spaces hardware upgrade to cpu-upgrade or cpu-performance
Always-on + git auto-sync Self-host on Oracle Cloud Always Free (24GB RAM, 4 ARM cores) β€” different guide

License

MIT. OpenCode is Β© Anomaly. This Dockerfile is just glue.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support