← Back to Blog
Header image for blog post: How to run the Codex AI coding agent securely in the cloud
Simo Aleksandrov
Published 21st September 2026

How to run the Codex AI coding agent securely in the cloud

Running Codex securely in the cloud entails setting up an isolated coding workspace and limiting the files, credentials, and network connections the AI coding agent can access. A Codex sandbox adds command-level restrictions as the agent edits code, executes commands, and runs tests in that workspace.

This article shows you how to run Codex securely in the cloud with Northflank Cloud Harnesses, from setting up your workspace and configuring access to running your first task.

TL;DR: How to run Codex securely in the cloud

Use Northflank Cloud Harnesses to give Codex a remote workspace with your repository, development tools, and task-specific access. Create and authenticate the workspace first, then prepare your project, review permissions, and run a small task. Check the changes and test results before keeping the work, and pause or delete the workspace when finished.

  • Create a Cloud Harness, select Codex, and choose its environment.
  • Authenticate Codex, connect your repository and branch, and review runtime and storage options.
  • Install dependencies and add the development configuration your tests need.
  • Review Codex's permissions, run a small task, and inspect the changes and test results.
  • Add application ports if the task needs a preview.
  • Use the browser or SSH, monitor resources, and pause with persistent storage enabled or export your work before deletion.

Get started with Northflank Cloud Harnesses on a self-serve Pay As You Go plan and follow the Cloud Harness quickstart guide, or book a demo to see how Cloud Harnesses fit your team's security and infrastructure requirements.

What is a Codex sandbox?

A Codex sandbox restricts which files and network resources Codex's commands can access. It lets the agent work within defined permissions while editing code and running tests. Codex's approval settings separately control when it pauses for authorization before executing an action.

When you run Codex in the cloud, the coding workspace holds your repository, tools, and running processes. The command sandbox operates within that environment, alongside the credentials and network controls you configure for the workspace.

How do you run Codex securely in the cloud?

Run Codex in an isolated cloud workspace with your repository, development tools, and only the credentials its task needs. Review its command permissions, control network access, and inspect the resulting code changes before merging them.

A cloud workspace gives Codex somewhere to edit files and run tests away from your laptop. Moving execution there changes which files and services it can reach, so keep production credentials and unrelated data outside that workspace.

Northflank is an AI-agent sandbox and workload platform for running untrusted code in isolated environments on managed infrastructure or in your own cloud. A Cloud Harness brings that infrastructure into an interactive coding workflow: you choose the environment, supply the repository, and work with the agent inside it.

In this tutorial, you will create that workspace with Northflank Cloud Harnesses. Northflank is the cloud platform that runs the workspace; a Cloud Harness brings together your coding agent, repository, runtime tools, and storage. You can use Northflank-managed infrastructure or your own cloud.

What do you need to run Codex on Northflank?

Before creating your Cloud Harness, have the following ready:

  • A Northflank account on a Pay As You Go plan.
  • An account with Codex access, or an OpenAI API key, for agent authentication.
  • A Git integration if you want to connect an existing repository.

To follow along, choose an existing repository with a test suite and a development branch. Start with a small task, such as fixing a failing unit test. Connecting a repository is optional when creating a Cloud Harness, but you’ll need one to follow this example.

How do you create a Cloud Harness for Codex?

Create the workspace in the Northflank dashboard using the Cloud Harness creation flow.

  1. Create or open a project. A project groups related resources. To create a project, select Create project from your team dashboard, enter a name, select the region for your chosen infrastructure, and select Create project again. Open Harnesses in the project.
  2. Select Codex as the coding agent.
  3. Name the Cloud Harness, for example codex-test-fix.
  4. Select the environment where it should run.
  5. Choose authentication. Under Authentication, select an API key or linked account.
  6. Choose a repository. Under Repository, select an existing repository and branch, create a repository, or continue without one.
  7. Review Advanced options if needed. Configure runtime variables, the runtime image, resources, and workspace storage. The runtime image supplies the operating environment and installed tools.
  8. Select Create Harness. Northflank opens the terminal. Complete the agent sign-in if prompted.

codex-harness.webp

Your Cloud Harness is now created. The following sections cover preparing your project, working with Codex, and managing the workspace after setup.

How do you prepare your project for Codex?

Prepare the project inside your Cloud Harness by installing dependencies, adding development configuration, and running the existing tests. Follow the repository's setup instructions, and configure any services and credentials the tests require before running them.

Read installation scripts first, especially in an unfamiliar repository. They execute code with access to credentials available in their environment.

In the Northflank dashboard, open the Cloud Harness and select the Environment variables icon in the right sidebar, then click Edit. Add the runtime variables or secret files your application needs and select Update & restart. These Cloud Harness settings supply configuration to code running in the workspace.

codex-environment.png

Use development credentials with access limited to the task. Keep production credentials outside the workspace, and avoid scripts that save secrets in logs or generated files. Run the project's existing tests in the Cloud Harness's shell, from the repository directory, and keep the results as your starting point.

Which Codex controls should you check before running a task?

Review the active Codex sandbox and approval settings inside your Cloud Harness before asking the agent to work. In a Codex CLI session, enter /permissions to open the permissions picker. Choose permissions appropriate to the task and keep approval requests directed to you when you want to review broader access.

The Cloud Harness provides the workspace; Codex's command sandbox separately restricts file and network access. Check the active session rather than assuming the workspace enables a particular Codex policy. On Linux, check sandbox startup warnings and the bubblewrap and user-namespace prerequisites before relying on command sandboxing.

Project instructions and prompts guide Codex's behaviour. They do not enforce access restrictions. Also review any connected web, app, or MCP tools, which use access controls separate from the command sandbox.

How do you run and review a Codex task?

Open the Codex session inside your Northflank Cloud Harness and give it a small task with a clear stopping point. Adapt this prompt to a failing test in your repository:

Read the project instructions and identify the relevant test command.
Investigate the failing test described below.
Explain the cause and propose the smallest relevant fix before editing files.
Do not change unrelated files or add dependencies without asking.

Failing test: <paste the test name and failure output>

Review the proposed approach, then ask Codex to implement the agreed change and run the affected tests. Ask it to show the command used and any failures that remain. Review requests for broader access before approving them.

In the Cloud Harness's shell, run these commands from the repository directory to inspect the changes:

git status --short --untracked-files=all
git diff --stat
git diff
git diff --cached

The status command lists changed and untracked files. The diff commands show a summary, unstaged changes, and staged changes. Open untracked files separately because they do not appear in git diff.

Run the affected tests yourself and compare the result with the original failure. Check for unrelated changes, unnecessary dependencies, and accidentally included secrets. If a command fails because a tool or service is missing, correct the development configuration before expanding access.

Complete any application preview checks the task needs, then commit and push the reviewed changes through your normal pull-request process. Keep the task, starting commit, patch, and test results together in your AI-agent execution audit trail.

How do you preview an application built with Codex?

To preview an application, ask Codex to start its development server inside the Cloud Harness and identify the listening port. In the Northflank dashboard, open the Cloud Harness overview and select the Networking icon in the right sidebar:

  1. Select Add port.
  2. Enter the application's port and select its protocol.
  3. Enable Publicly expose only if people need to access the preview from the internet.
  4. Select Save changes.

The networking controls support private and public ports, with domains for publicly exposed ports. For a web preview, bind the application to 0.0.0.0 so Northflank can route traffic to it.

codex-port.png

Before sharing a public preview, check for sensitive data, debug routes, and missing authentication. Remove public access when it is no longer needed.

Port exposure controls incoming connections. For outbound restrictions on your own cluster, configure BYOC network policies; without egress rules, outbound traffic is allowed.

How do you access your Codex workspace through SSH?

You can use Northflank's SSH access to work in the Cloud Harness from your local terminal, or continue using the browser terminal.

Install and authenticate the Northflank command-line interface (CLI). To connect to your Cloud Harness locally, open its overview in the Northflank dashboard, select Connect under Local access, and copy the generated command. Run it in your local terminal. It has this form:

northflank dev ssh --projectId YOUR_PROJECT_ID --harnessId YOUR_HARNESS_ID

Use the generated command, or replace both placeholders with your project and Cloud Harness IDs. This SSH connection opens access to the existing cloud workspace.

How do you monitor CPU and memory usage in your Codex workspace?

Northflank shows CPU and memory usage for the Cloud Harness and its running processes. Check these metrics while installing dependencies or running a demanding test suite to see whether workspace resources may be contributing to slow performance.

To monitor the workspace, open its overview in the Northflank dashboard and select the Observe icon in the right sidebar.

If the project needs more resources, select Settings, adjust the resource configuration, and select Update options. Rerun the task and check its behaviour and resource usage again.

codex-monitor-harness.png

How do you pause or delete your Codex cloud workspace?

In Northflank, pause the Cloud Harness to return to the work later, or delete it after saving the files you need. An active Cloud Harness keeps running until you pause or delete it; closing your terminal does not stop it.

To pause your Cloud Harness, open its overview and select the Pause harness icon in the top-right corner. With persistent workspace storage enabled, files under /home/harness survive, while terminal sessions and running processes stop. Select Resume harness from the overview when you want to continue, then restart any development servers or other processes you need.

Persistent storage defaults to enabled at creation. If you disabled it, files are lost when the container restarts, is redeployed, or stops.

Before deleting, push your commits or export the files you want to keep. Open the three-dot menu in the top-right corner, select Delete harness, and confirm. Deleting a Cloud Harness permanently removes its associated workspace. Revoke temporary credentials at the services that issued them when they are no longer needed.

Start your next Codex task in a Cloud Harness

You now have a workflow for creating a Codex workspace, giving it the access a task needs, reviewing its changes, and deciding what to retain. Start with one repository and one small fix, then reuse that process as your team takes on larger tasks.

Get started with Northflank, or book a demo to discuss running Cloud Harnesses in your own cloud.

Frequently asked questions about Codex in Cloud Harnesses

Is a Cloud Harness the same as Codex's command sandbox?

A Cloud Harness is the cloud workspace where Codex runs. Codex's command sandbox restricts which files and network resources its commands can access. Review the session's permissions alongside the workspace's credentials and network access.

Can teammates work in the same Codex workspace?

Yes. Multiple team members can work in the same Cloud Harness simultaneously. Share access with collaborators authorised to use the same repository, development data, and credentials.

Can I run Codex in my own cloud account?

Yes. You can run Codex in a Northflank Cloud Harness on Northflank-managed infrastructure or in your own cloud account. Northflank BYOC creates and manages Kubernetes clusters in your cloud account, where your cloud provider bills you for the resources.

Can I keep workspace files between Codex sessions?

Yes. With persistent workspace storage enabled, files under /home/harness survive pause and resume. Running processes and terminal sessions stop when paused. Export the files you need before deleting the Cloud Harness.

Share this article with your network
X