denoland/deno · error · AnyError

RUNNER_ENVIRONMENT environment variable is not set

Error message

RUNNER_ENVIRONMENT environment variable is not set

What it means

`RUNNER_ENVIRONMENT` (values like `github-hosted` or `self-hosted`) is read into the provenance predicate's run details to identify where the build executed. This error means `deno publish --provenance` reached predicate construction without that variable, i.e. the GitHub Actions environment is incomplete — almost always because the CLI was re-executed in a container or wrapper that dropped runner env vars.

Solutions

  1. Forward RUNNER_ENVIRONMENT (ideally the whole runner env block: GITHUB_* and RUNNER_*) into the publish subprocess/container.
  2. Keep the publish step directly on the runner rather than inside a stripped container.
  3. If you intentionally publish outside GitHub Actions, remove `--provenance` from the command.

Example fix

# before
docker run --rm -e GITHUB_SHA publisher deno publish --provenance

# after
docker run --rm \
  -e GITHUB_SHA -e GITHUB_REF -e GITHUB_REPOSITORY -e GITHUB_SERVER_URL \
  -e GITHUB_RUN_ID -e GITHUB_RUN_ATTEMPT -e RUNNER_ENVIRONMENT \
  -e ACTIONS_ID_TOKEN_REQUEST_URL -e ACTIONS_ID_TOKEN_REQUEST_TOKEN \
  publisher deno publish --provenance
Defensive patterns

Strategy: validation

Validate before calling

const provenanceVars = ['GITHUB_REPOSITORY', 'GITHUB_SERVER_URL',
  'GITHUB_REF', 'GITHUB_SHA', 'RUNNER_ENVIRONMENT', 'GITHUB_RUN_ID',
  'GITHUB_RUN_ATTEMPT'];
if (provenanceVars.some((k) => !Deno.env.get(k))) {
  const args = ['publish']; // no --provenance
}

Try / catch

try {
  await runDeno(['publish', '--provenance']);
} catch (e) {
  if (String(e.message).includes('RUNNER_ENVIRONMENT')) {
    // runner metadata was dropped by a wrapper; restore env inheritance and retry
  }
}

Prevention

When it happens

Trigger: Container actions or `docker run` publish steps that forward only auth vars; environment scrubbing via `env -i`, minimal Docker images with no ENV inheritance; non-GHA CI partially impersonating GitHub Actions.

Common situations: Hardened containers that start with an empty env; scripts that build a curated env dict and forget RUNNER_*; moving a working workflow step into a composite/container action.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/8f6b5f614977d960. Report an issue: GitHub.

Appendix: source

Thrown at cli/tools/publish/provenance.rs:187

      .replace(&format!("{}/", &repo), "");

    let (workflow_path, workflow_ref) = if let Some(delimn) = rel_ref.find('@')
    {
      let (path, ref_) = rel_ref.split_at(delimn);
      (path, &ref_[1..])
    } else {
      (rel_ref.as_str(), "")
    };

    let server_url = std::env::var("GITHUB_SERVER_URL").map_err(|_| {
      anyhow!("GITHUB_SERVER_URL environment variable is not set")
    })?;
    let github_ref = std::env::var("GITHUB_REF")
      .map_err(|_| anyhow!("GITHUB_REF environment variable is not set"))?;
    let github_sha = std::env::var("GITHUB_SHA")
      .map_err(|_| anyhow!("GITHUB_SHA environment variable is not set"))?;
    let runner_env = std::env::var("RUNNER_ENVIRONMENT").map_err(|_| {
      anyhow!("RUNNER_ENVIRONMENT environment variable is not set")
    })?;
    let run_id = std::env::var("GITHUB_RUN_ID")
      .map_err(|_| anyhow!("GITHUB_RUN_ID environment variable is not set"))?;
    let run_attempt = std::env::var("GITHUB_RUN_ATTEMPT").map_err(|_| {
      anyhow!("GITHUB_RUN_ATTEMPT environment variable is not set")
    })?;

    Ok(Self {
      build_definition: BuildDefinition {
        build_type: GITHUB_BUILD_TYPE,
        external_parameters: ExternalParameters {
          workflow: GhaWorkflow {
            ref_: workflow_ref.to_string(),
            repository: format!("{}/{}", server_url, &repo),
            path: workflow_path.to_string(),
          },
        },
        internal_parameters: InternalParameters {

View on GitHub (pinned to 9ad36f7a2c)