PRACTICAL AI & AUTOMATION
Getting Started with Codex on Ubuntu for Linux Work and Automation
Set up Codex CLI on Ubuntu, write AGENTS.md, build a repeatable file report and verify Linux automation with Git checkpoints and scoped permissions.

Set up Codex CLI on Ubuntu, write AGENTS.md, build a repeatable file report and verify Linux automation with Git checkpoints and scoped permissions.
Step 1: Choose a small Ubuntu project
Codex CLI is a coding agent that works from your terminal. Start with a folder you can inspect and a reversible task: build a report of files in a scratch directory. That teaches the same habits needed for Linux automation without beginning with service changes or system-wide cleanup.
Use your normal Ubuntu user. Install Git, Python and curl, then create a repository. Your source folder, model provider, credentials and execution permissions are separate choices. This guide uses ordinary Codex sign-in; a locally installed CLI does not by itself mean the model runs locally.
Open the complete copyable example — example-01.txt
# Open full code above.Step 2: Install and authenticate Codex
Download and inspect the official Linux installer, then run it and confirm codex --version. Open a new shell if needed to pick up PATH changes. Launch codex in the lab directory and choose an available sign-in method. Account access and usage depend on the authentication option you use.
Start by asking ‘Explain this directory and propose a read-only file report.’ Read the plan before requesting edits. The official installation guide covers installation and initial sign-in; the CLI reference documents flags.
Open the complete copyable example — example-02.txt
# Open full code above.Step 3: Write a useful AGENTS.md
Put project expectations in AGENTS.md so future sessions can see the same task boundaries. Include allowed paths, the output format and the verification command. A project instruction file guides behavior; operating-system permissions and sandbox settings provide separate enforcement.
Keep credentials out of this file. A concise file is easier to maintain than an enormous collection of unrelated instructions. Update it when the actual project workflow changes.
Open the complete copyable example — AGENTS.md.txt
# Open full code above.Step 4: Build and inspect your first automation
Ask Codex: ‘Create report.py using only the Python standard library. List regular files directly inside scratch/ with name and size in bytes, sorted by name. Do not follow symbolic links. Write reports/files.json. Create the output directory if needed. Running twice should produce identical JSON. Do not modify the input files.’ This specification gives it a testable outcome.
Use a workspace-write sandbox for this bounded edit. Afterward inspect git diff, read report.py and run the verification below. The first diff does not show untracked files, so inspect git status and open newly created files too. Do not equate an agent’s success message with a checked result.
Open the complete copyable example — example-04.txt
# Open full code above.Step 5: Make repeated runs predictable
Use codex exec for a bounded non-interactive request, such as explaining an existing script. For recurring file reports, schedule the deterministic report script itself once reviewed; you do not need to ask a model to rediscover the same logic each day. Keep model-driven planning and routine execution as distinct steps.
The read-only example below writes the final response to a report file through the CLI output option. It does not grant the agent permission to edit the repository. Before automating any write task, explicitly choose its sandbox and failure behavior. Non-interactive runs cannot rely on a human answering an interactive prompt.
Open the complete copyable example — example-05.txt
# Open full code above.Step 6: Keep checkpoints and diagnose failures
Once you have read and checked the files, commit only the intended project files. Before the next task, use a branch and record the known-good result. For system administration, begin with inventory and a proposed change; service restarts, package removal and permission changes deserve their own clear scope.
Troubleshooting: command not found means inspect PATH and installation; authentication errors mean check the sign-in route; sandbox errors mean identify the exact required path or capability. Expand only the permission that the task needs. For a failed script, capture its exit code and reproduce it outside the model conversation.
Your first milestone is modest and useful: a repeatable script, a checked output and a readable change. In the next guide, OpenClaw adds persistent agent routing. For Japanese practice: ‘We check the result’ becomes the marked sentence in the opposite column.
Continue the series
UbuntuでCodexを始める:Linux作業と自動化
手順1:小さなUbuntuプロジェクトを選ぶ
Codex CLIは端末から作業するコーディングエージェントです。試験フォルダーのファイル一覧をレポートにする小さな可逆的作業から始めます。サービス変更の前にLinux自動化の習慣を学べます。
通常ユーザーでGit、Python、curlを入れ、リポジトリーを作ります。フォルダー、プロバイダー、認証、実行権限は別の設定です。CLIのローカル導入だけでモデルもローカルになるわけではありません。
コピー可能な完全なコードを開く — example-01.txt
# Open full code above.手順2:Codexを導入して認証する
公式インストーラーを取得して確認後に実行し、codex --versionを確認します。PATH変更後は端末を開き直します。ラボ内でcodexを起動し、利用可能な認証を選びます。利用条件は認証方法によります。
最初は「このフォルダーを説明し、読み取り専用レポートを提案して」と依頼し、計画を読みます。公式導入ガイドとCLI仕様を参照してください。
コピー可能な完全なコードを開く — example-02.txt
# Open full code above.手順3:役立つAGENTS.mdを書く
AGENTS.mdにパス、出力形式、検証方法を記載します。これは行動を案内する文書で、OS権限やサンドボックスとは別です。
認証情報は書きません。短く保ち、実際の作業方法が変わったら更新します。
コピー可能な完全なコードを開く — AGENTS.md.txt
# Open full code above.手順4:最初の自動化を作って確認する
依頼例:「標準ライブラリーだけでreport.pyを作る。scratch/直下の通常ファイルを名前順に並べ、名前とバイト数をreports/files.jsonへ保存する。シンボリックリンクは追わない。入力を変更せず、再実行でも同じ結果にする。」検証できる結果を指定します。
限定編集にはworkspace-writeを使います。git diffだけでなくgit statusと新規ファイルも確認します。未追跡ファイルは最初のdiffに出ません。スクリプトを読み、出力を検証します。
コピー可能な完全なコードを開く — example-04.txt
# Open full code above.手順5:繰り返し実行を安定させる
codex execは既存スクリプトの説明など、範囲を決めた非対話処理に使えます。定期レポートには確認済みの決定的スクリプト自体を実行すればよく、毎日モデルへ同じロジックを作らせる必要はありません。
下の例は読み取り専用で、CLIの出力機能により最終回答を保存します。リポジトリー編集の許可ではありません。書き込み処理ではサンドボックスと失敗時の動作を明示し、対話承認へ依存しない構成にします。
コピー可能な完全なコードを開く — example-05.txt
# Open full code above.手順6:チェックポイントと失敗原因を残す
ファイルを確認して検証後、意図したものだけコミットします。次の作業はブランチを使います。システム管理は現状確認と提案から始め、再起動、パッケージ削除、権限変更の範囲を明確にします。
コマンドがなければPATH、認証失敗なら認証経路、サンドボックスの失敗なら必要な機能を特定します。必要分だけ権限を広げ、スクリプトの終了コードを残して失敗を再現します。
最初の成果は、再実行できるスクリプト、確認済み出力、読める変更です。次のOpenClaw記事では継続的なエージェント構成へ進みます。私たちは結果を確認します。
技術資料の確認日:2026年10月9日。コマンドとAPIは更新されることがあります。実行時に公式資料と利用中のバージョンを確認してください。
