CodexWrapper.Commands.Sandbox (CodexWrapper v0.4.0)

Copy Markdown View Source

Sandbox command -- run a command inside the Codex sandbox.

Wraps codex sandbox [OPTIONS] [COMMAND]....

The platform is no longer part of the invocation. Codex used to take it as a subcommand (codex sandbox macos -- ls); as of codex-cli 0.14x the command is flat and the platform is inferred from the host, so new/1 takes the command directly. See #56.

Usage

config = CodexWrapper.Config.new()

sandbox =
  CodexWrapper.Commands.Sandbox.new("ls")
  |> CodexWrapper.Commands.Sandbox.arg("-la")

{:ok, output} = CodexWrapper.Commands.Sandbox.execute(sandbox, config)

Sandbox state

The sandbox-state options configure what the sandboxed process can reach. They are independent of the :permission_profile, which selects a named profile from the Codex config:

CodexWrapper.Commands.Sandbox.new("pytest")
|> CodexWrapper.Commands.Sandbox.permission_profile("ci")
|> CodexWrapper.Commands.Sandbox.sandbox_state_readable_root("/usr/share")
|> CodexWrapper.Commands.Sandbox.sandbox_state_disable_network()

Summary

Functions

Add an argument to the sandboxed command.

Add multiple arguments to the sandboxed command.

Build the argument list for this command.

Working directory for the sandboxed command (--cd).

Execute the sandbox command synchronously.

Create a sandbox command for the given command.

Select a named permission profile (--permission-profile).

Disable network access inside the sandbox (--sandbox-state-disable-network).

Path to a sandbox state JSON file (--sandbox-state-json).

Grant read access to a root (--sandbox-state-readable-root).

Types

t()

@type t() :: %CodexWrapper.Commands.Sandbox{
  cd: String.t() | nil,
  command: String.t(),
  command_args: [String.t()],
  permission_profile: String.t() | nil,
  sandbox_state_disable_network: boolean(),
  sandbox_state_json: String.t() | nil,
  sandbox_state_readable_roots: [String.t()]
}

Functions

arg(s, arg)

@spec arg(t(), String.t()) :: t()

Add an argument to the sandboxed command.

args(s, args)

@spec args(t(), [String.t()]) :: t()

Add multiple arguments to the sandboxed command.

build_args(s)

@spec build_args(t()) :: [String.t()]

Build the argument list for this command.

cd(s, dir)

@spec cd(t(), String.t()) :: t()

Working directory for the sandboxed command (--cd).

Distinct from Config's :working_dir, which sets the subprocess cwd.

execute(sandbox, config)

@spec execute(t(), CodexWrapper.Config.t()) :: {:ok, String.t()} | {:error, term()}

Execute the sandbox command synchronously.

new(command)

@spec new(String.t()) :: t()

Create a sandbox command for the given command.

permission_profile(s, profile)

@spec permission_profile(t(), String.t()) :: t()

Select a named permission profile (--permission-profile).

sandbox_state_disable_network(s)

@spec sandbox_state_disable_network(t()) :: t()

Disable network access inside the sandbox (--sandbox-state-disable-network).

sandbox_state_json(s, path)

@spec sandbox_state_json(t(), String.t()) :: t()

Path to a sandbox state JSON file (--sandbox-state-json).

sandbox_state_readable_root(s, root)

@spec sandbox_state_readable_root(t(), String.t()) :: t()

Grant read access to a root (--sandbox-state-readable-root).

Accumulates: call once per root.