# \[Container Agent\] Failed to copy circleci-agent into container "primary"

**URL:** <https://discuss.circleci.com/t/container-agent-failed-to-copy-circleci-agent-into-container-primary/45711>\
**Category:** Build Environment\
**Created:** [October 7, 2022, 11:46am UTC](https://discuss.circleci.com/t/container-agent-failed-to-copy-circleci-agent-into-container-primary/45711 "2022-10-07T11:46:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![petermein](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/petermein/32/31316_2.png) [@petermein](https://discuss.circleci.com/u/petermein)\
**Post date:** [October 7, 2022, 11:46am UTC](https://discuss.circleci.com/t/container-agent-failed-to-copy-circleci-agent-into-container-primary/45711/1 "2022-10-07T11:46:29Z")

</div>

Yesterday I had a working container with the image `cimg/deploy:2022.09` and today all containers give this error.

I’am running `circleci/container-agent:1.0.17278-5c2bd95`.

`could not start task: failed to copy circleci-agent into container "primary", Error: error executing command /bin/sh -c cat > $HOME/circleci-agent : error executing command /bin/sh -c cat > $HOME/circleci-agent : command terminated with exit code 2`

It looks like either a user/id error or something has changed with our permissions.

---

<div class="post-metadata">

**Author:** ![sebastian-lerner](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/sebastian-lerner/32/27833_2.png) [@sebastian-lerner](https://discuss.circleci.com/u/sebastian-lerner)\
**Post date:** [October 7, 2022, 12:37pm UTC](https://discuss.circleci.com/t/container-agent-failed-to-copy-circleci-agent-into-container-primary/45711/2 "2022-10-07T12:37:28Z")

</div>

@petermein Taking a look with the team. I’ll report back when I have more. Can you share the version of container-agent you’re using please? It should be on the Self-hosted Runner Inventory screen from the left-hand nav of the CircleCI application

---

<div class="post-metadata">

**Author:** ![sebastian-lerner](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/sebastian-lerner/32/27833_2.png) [@sebastian-lerner](https://discuss.circleci.com/u/sebastian-lerner)\
**Post date:** [October 7, 2022, 12:52pm UTC](https://discuss.circleci.com/t/container-agent-failed-to-copy-circleci-agent-into-container-primary/45711/3 "2022-10-07T12:52:42Z")

</div>

@petermein Actually, ignore me. I don’t need the version I see it in the output. We’re still taking a look.

---

<div class="post-metadata">

**Author:** ![sebastian-lerner](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/sebastian-lerner/32/27833_2.png) [@sebastian-lerner](https://discuss.circleci.com/u/sebastian-lerner)\
**Post date:** [October 7, 2022, 1:17pm UTC](https://discuss.circleci.com/t/container-agent-failed-to-copy-circleci-agent-into-container-primary/45711/4 "2022-10-07T13:17:23Z")

</div>

One small, thing is there any way you can try downloading the latest helm chart from the new location and seeing if you’re still experiencing this issue? I don’t see any reason why that would be the cause but it’s one thing we can rule out.

> **[Container runner open preview - CircleCI](https://circleci.com/docs/container-runner/#installing-the-helm-chart)**
>
> Open preview of container runner

the location with packagecloud is the new helm hosting location.

Can you also share a build link if possible? Feel free to send via direct message if you prefer.

---

<div class="post-metadata">

**Author:** ![lucasvdh](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/lucasvdh/32/25082_2.png) [@lucasvdh](https://discuss.circleci.com/u/lucasvdh)\
**Post date:** [January 12, 2023, 10:47am UTC](https://discuss.circleci.com/t/container-agent-failed-to-copy-circleci-agent-into-container-primary/45711/5 "2023-01-12T10:47:36Z")

</div>

@sebastian-lerner the issue was that we had a custom `runAsUser` value which I guess was required for us to run the container agent previously.

```yaml
          securityContext:
            runAsUser: 1000

```

Completely removing this resolved the issue.

---

<div class="post-metadata">

**Author:** ![dmpeters](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/dmpeters/32/35131_2.png) [@dmpeters](https://discuss.circleci.com/u/dmpeters)\
**Post date:** [March 15, 2024, 5:04pm UTC](https://discuss.circleci.com/t/container-agent-failed-to-copy-circleci-agent-into-container-primary/45711/6 "2024-03-15T17:04:01Z")

</div>

@sebastian-lerner the solution @lucasvdh provided doesn’t seem to work for me.

The error message I’m seeing:

> CircleCI failed to run this build, check your config. Try re-running the build and if this issue persists, open a Support ticket. Detail: failed to copy circleci-agent into container primary, Error: error executing command mkdir -p $HOME/.local/bin : error executing command /bin/bash -c set -o pipefail ; mkdir -p $HOME/.local/bin 21 | tee /proc/1/fd/1 : command terminated with exit code 1

Self Hosted Infra Info:

```auto
Circleci-runner version 3.0.19-5234-08c7340 (circleci-container-runner-container-agent)
Task-agent version 1.0.229736-54e0c9a4
Platform info Kubernetes-Runner (os: linux; arch: amd64; version: v1.27.9-eks-5e0fdde; virtualization: linux/amd64)

```

Chart Values:

```auto
agent:
  resourceClasses:
    org/some-resource-class:
      token: "TOKEN"
      spec:
        securityContext:
          runAsNonRoot: true
          runAsUser: 1000
  containerSecurityContext:
    runAsUser: 1000
    runAsGroup: 1000
    runAsNonRoot: true

```

CircleCI Config:

```auto
jobs:
  some_job:
    docker:
      - image: cimg/base:2021.11
    resource_class: org/some-resource-class
    steps:
      - checkout
      - run: ...

```

I also get the same error message with `cimg/base:current`. Any thoughts or ideas?

---

<div class="post-metadata">

**Author:** ![rit1010](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rit1010/32/34738_2.png) [@rit1010](https://discuss.circleci.com/u/rit1010)\
**Post date:** [March 15, 2024, 5:20pm UTC](https://discuss.circleci.com/t/container-agent-failed-to-copy-circleci-agent-into-container-primary/45711/7 "2024-03-15T17:20:21Z")

</div>

As you are using a self-hosted environment it is going to come down to what UID was assigned when you created the environment. The following writeup covers the detail

> **[Container Runner job failing to copy circleci-agent into container](https://support.circleci.com/hc/en-us/articles/17294396354459-Container-Runner-job-failing-to-copy-circleci-agent-into-container)**
>
> Overview
> When using runAsNonRootUser and runAsUser you may experience the following error message in your CircleCI job. 
> CircleCI failed to run this build, check your config. Try re-running the bui...

While a UID value of 1000 was the right answer for the original question and the result in the above writeup it does not mean it is the right answer for your configuration.

---

<div class="post-metadata">

**Author:** ![dmpeters](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/dmpeters/32/35131_2.png) [@dmpeters](https://discuss.circleci.com/u/dmpeters)\
**Post date:** [March 15, 2024, 6:12pm UTC](https://discuss.circleci.com/t/container-agent-failed-to-copy-circleci-agent-into-container-primary/45711/8 "2024-03-15T18:12:06Z")

</div>

Thanks @rit1010 I had the wrong UID.
