paperclipai/paperclip · error · Error

Could not create working directory "${cwd}" on remote target

Error message

Could not create working directory "${cwd}" on remote target${detail ? `: ${detail}` : "."}

What it means

Thrown by ensureAdapterExecutionTargetDirectory when createIfMissing is true and the `mkdir -p <cwd> && [ -d <cwd> ]` command exits non-zero on a remote target. This means the directory creation itself failed — the system attempted to create it but could not.

Source

Thrown at packages/adapter-utils/src/execution-target.ts:1012

  const script = createIfMissing
    ? `mkdir -p ${quoted} && [ -d ${quoted} ]`
    : `[ -d ${quoted} ]`;

  const result = await runAdapterExecutionTargetShellCommand(runId, target, script, {
    cwd: target.kind === "remote" ? target.remoteCwd : cwd,
    env: options.env,
    timeoutSec: options.timeoutSec ?? 15,
    graceSec: options.graceSec ?? 5,
    onLog: options.onLog,
  });

  if (result.timedOut) {
    throw new Error(`Timed out checking working directory on remote target: "${cwd}"`);
  }
  if ((result.exitCode ?? 1) !== 0) {
    const detail = (result.stderr || result.stdout || "").trim();
    if (createIfMissing) {
      throw new Error(
        `Could not create working directory "${cwd}" on remote target${detail ? `: ${detail}` : "."}`,
      );
    }
    throw new Error(
      `Working directory does not exist on remote target: "${cwd}"${detail ? ` (${detail})` : ""}`,
    );
  }
}

export function adapterExecutionTargetSessionIdentity(
  target: AdapterExecutionTarget | null | undefined,
): Record<string, unknown> | null {
  if (!target || target.kind === "local") return null;
  if (target.transport === "ssh") return buildRemoteExecutionSessionIdentity(target.spec);
  return {
    transport: "sandbox",
    providerKey: target.providerKey ?? null,
    environmentId: target.environmentId ?? null,

View on GitHub (pinned to 67001ec6eb)

Solutions

  1. Check the detail string (appended stderr/stdout) for the specific OS error message.
  2. Verify the user/lease has write permissions on the parent directory of cwd.
  3. Ensure the remote filesystem is not read-only or quota-limited.
  4. Confirm the path does not conflict with an existing file at the same location.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await ensureAdapterExecutionTargetDirectory(runId, target, cwd, { createIfMissing: true });
} catch (err) {
  if (err instanceof Error && err.message.includes("Could not create working directory")) {
    // Inspect the detail in err.message for the OS-level reason
    throw new Error(`Failed to create remote workspace dir: ${err.message}`);
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling ensureAdapterExecutionTargetDirectory(runId, target, cwd, { createIfMissing: true, ... }) with a remote target; the mkdir command returned a non-zero exit code (not a timeout).

Common situations: The parent path is on a read-only filesystem; permission denied creating directories under the given path; the path contains invalid characters or resolves to a file rather than a directory; disk full on the remote; the sandbox filesystem quota is exceeded.

Related errors


AI-assisted analysis of paperclipai/paperclip@67001ec6eb (2026-08-12). Data as JSON: /api/errors/75ca2566fe3f8f73. Report an issue: GitHub.