Skip to content
GitHub Get Started
Agent

Codex

server.ts
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.

See Full Example

Set the relevant variable(s) on the session’s env, sourced from your server’s environment:

  • OPENAI_API_KEY — OpenAI API key (built-in openai provider).
  • OPENAI_BASE_URL — route through a gateway or OpenAI-compatible endpoint.
  • Custom providers — defined in ~/.codex/config.toml; each provider’s env_key names 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.

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-style
description: 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 session
await 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 automatically
const session = await agent.createSession("codex", {
env: { OPENAI_API_KEY: process.env.OPENAI_API_KEY! },
});

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" },
},
],
});

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.