06 / OpenCode / 40 min READ + PRACTICE
Use OpenCode as a security learning partner.
Install the coding agent, build a local practice project, review its changes and keep tests and secrets under your control.
Install and launch
Follow the current installation instructions at https://opencode.ai/docs/ . On Linux with npm already installed, the documented CLI command is npm install -g @opencode/cli. Open a dedicated lab project and run opencode. Connect a model provider using the interface’s /connect command. A model subscription or provider account may be needed. Do not paste API keys into a repository.
npm install -g @opencode/cli
mkdir -p ~/security-lab/hello-python
cd ~/security-lab/hello-python
opencode Give the agent a narrow task
Provide the target, constraints and success criteria: “Write a localhost-only TCP echo service; set a timeout; include a test for malformed input; explain how to stop it.” Ask it to show the changed files and run tests. Review code and dependency requests before execution.
Use it for defense and analysis
OpenCode can explain protocol traces, generate synthetic fixtures, review a local app for access-control mistakes, write parsers for sample logs and draft a remediation report. Ask for citations to actual local code and distinguish observed facts from suggestions. Keep real passwords, session cookies and production keys out of prompts.
Keep the human in charge
Use version control to inspect diffs; run automated tests; reproduce claims yourself in the isolated lab. For a security-sensitive change, ask for both a failing test before the fix and a passing test afterward. Reject changes that broaden the test target beyond your written scope.
Try it in your lab
Ask OpenCode to build the loopback TCP exercise from Lesson 5, then review its changes and run the test. Record one correction you made after review.
Make sure it clicks
What evidence would you require before accepting an AI-generated security finding?
A prompt you can adapt
Act as my pair programmer for a local-only Python security lab. First inspect the project, then propose a small plan, implement one testable improvement and show the diff and test result.How to set up OpenCode ↗