Implementation:2aronS Duel Agents Config Path Resolution
| Knowledge Sources | |
|---|---|
| Domains | Configuration, Security |
| Last Updated | 2026-10-27 14:00 GMT |
Overview
Concrete tool for resolving the config and env file paths for OpenClaw (and Claude/Codex) with path-sandboxing protection against directory traversal, provided by @duel-agents/core.
Description
The Config Path Resolution group resolves the filesystem locations for OpenClaw's config and env files, and the Claude/Codex env file paths. The key security-sensitive function is resolveOpenClawConfigPath, which:
- Defaults to
~/.openclaw/openclaw.json - If
OPENCLAW_CONFIG_PATHenv var is set, resolves it to an absolute path and validates it is inside~/.openclawviaisPathInside— throws if the path escapes the sandbox - This prevents an attacker from pointing the config patcher at an arbitrary file
The other resolvers are simple:
resolveOpenClawEnvPath→~/.openclaw/.envresolveClaudeEnvPath→~/.claude/.envresolveCodexEnvPath→<cwd>/.env
The internal isPathInside helper handles cross-drive paths on Windows.
Usage
Import these functions when you need to:
- Resolve the OpenClaw config path safely (with sandbox check)
- Resolve env file paths for Claude, Codex, or OpenClaw
- Understand the path-sandboxing guard for
OPENCLAW_CONFIG_PATH
Code Reference
Source Location
- Repository: Duel-Agents
- File:
packages/core/src/index.ts(lines 14-55)
Signature
/** Sandboxing helper: is child inside parent? */
function isPathInside(child: string, parent: string): boolean;
/** Resolve openclaw.json path; validates OPENCLAW_CONFIG_PATH is inside ~/.openclaw. */
export function resolveOpenClawConfigPath(): string;
/** Resolve ~/.openclaw/.env. */
export function resolveOpenClawEnvPath(): string;
/** Resolve ~/.claude/.env. */
export function resolveClaudeEnvPath(): string;
/** Resolve <cwd>/.env. */
export function resolveCodexEnvPath(cwd?: string): string;
Import
import {
resolveOpenClawConfigPath,
resolveOpenClawEnvPath,
resolveClaudeEnvPath,
resolveCodexEnvPath,
} from "@duel-agents/core";
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (env) | OPENCLAW_CONFIG_PATH |
No | Custom config path (must be inside ~/.openclaw)
|
| cwd (resolveCodexEnvPath) | string |
No | Working dir (default process.cwd())
|
Outputs
| Name | Type | Description |
|---|---|---|
resolveOpenClawConfigPath returns |
string |
Absolute path to openclaw.json
|
resolveOpenClawConfigPath throws |
Error |
If OPENCLAW_CONFIG_PATH escapes ~/.openclaw
|
| other resolvers return | string |
Absolute env file path |
Usage Examples
Resolve OpenClaw Config Path (Default)
import { resolveOpenClawConfigPath, resolveOpenClawEnvPath } from "@duel-agents/core";
const configPath = resolveOpenClawConfigPath();
// => "/home/user/.openclaw/openclaw.json"
const envPath = resolveOpenClawEnvPath();
// => "/home/user/.openclaw/.env"
Custom Config Path (Sandboxed)
process.env.OPENCLAW_CONFIG_PATH = "/home/user/.openclaw/custom.json";
const path = resolveOpenClawConfigPath();
// => "/home/user/.openclaw/custom.json" (inside sandbox, OK)
process.env.OPENCLAW_CONFIG_PATH = "/etc/passwd";
resolveOpenClawConfigPath();
// throws: "OPENCLAW_CONFIG_PATH must be inside ~/.openclaw..."