Agent
Codex
Quick start
Section titled “Quick start”import { agentOS, setup } from "@rivet-dev/agentos";import codex from "@agentos-software/codex";
const vm = agentOS({ software: [codex] });
export const registry = setup({ use: { vm } });registry.start();Read Sessions first for session options, streaming events, prompts, and lifecycle management.
LLM Credentials
Section titled “LLM Credentials”Set the relevant variable(s) on the session’s env, sourced from your server’s environment:
OPENAI_API_KEY— OpenAI API key (built-inopenaiprovider).OPENAI_BASE_URL— route through a gateway or OpenAI-compatible endpoint.- Custom providers — defined in
~/.codex/config.toml; each provider’senv_keynames the variable Codex reads for its key (e.g.AZURE_OPENAI_API_KEY,MISTRAL_API_KEY).
See LLM Credentials, and Codex’s config reference for details.
Skills
Section titled “Skills”Codex discovers SKILL.md files from its skills directory. Write the skill into the VM before creating a session and Codex loads it automatically.
const skill = `---name: commit-styledescription: How to write commit messages in this project.---
Write commit messages in the imperative mood and keep the subject under 50 characters.`;
// Write the skill before creating the sessionawait agent.mkdir("/home/agentos/.codex/skills/commit-style", { recursive: true });await agent.writeFile("/home/agentos/.codex/skills/commit-style/SKILL.md", skill);
// Codex discovers the skill automaticallyconst session = await agent.createSession("codex", { env: { OPENAI_API_KEY: process.env.OPENAI_API_KEY! },});MCP servers
Section titled “MCP servers”Expose extra tools to the agent by passing mcpServers to createSession. Both local child-process servers and remote URLs are supported.
const session = await agent.createSession("codex", { env: { OPENAI_API_KEY: process.env.OPENAI_API_KEY! }, mcpServers: [ { type: "local", command: "npx", args: ["-y", "@modelcontextprotocol/server-filesystem", "/home/agentos"], env: {}, }, { type: "remote", url: "https://mcp.example.com/sse", headers: { Authorization: "Bearer my-token" }, }, ],});Customizing the agent
Section titled “Customizing the agent”Codex is a built-in agent, but it’s just a software package under the hood. To ship your own ACP adapter, swap the underlying agent SDK, or register a tweaked build as a new agent, see Custom Agents.