# Cursor-agent authentication issue inside docker

**URL:** <https://forum.cursor.com/t/cursor-agent-authentication-issue-inside-docker/143995>\
**Category:** Bug Reports\
**Tags:** cli\
**Created:** [November 24, 2025, 10:16pm UTC](https://forum.cursor.com/t/cursor-agent-authentication-issue-inside-docker/143995 "2025-11-24T22:16:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohammad\_Mazraeh](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@Mohammad\_Mazraeh](https://forum.cursor.com/u/Mohammad_Mazraeh)\
**Post date:** [November 24, 2025, 10:16pm UTC](https://forum.cursor.com/t/cursor-agent-authentication-issue-inside-docker/143995/1 "2025-11-24T22:16:04Z")

</div>

### Where does the bug appear (feature/product)?

Cursor CLI

### Describe the Bug

I use same token to authenticate on my laptop and again inside a docker container, but authentication fails inside the container. I want to run cli inside container full autonomously , at scale.

### Steps to Reproduce

Dockerfile

```auto
FROM ubuntu:22.04

# Install curl (required for Cursor installation)
RUN apt-get update && \
    apt-get install -y curl && \
    rm -rf /var/lib/apt/lists/*

# Install Cursor CLI using official installation method
# See https://cursor.com/docs/cli/installation
RUN curl https://cursor.com/install -fsS | bash

# Add ~/.local/bin to PATH (where cursor-agent is installed)
ENV PATH="/root/.local/bin:${PATH}"

# Verify installation
RUN cursor-agent --version || echo "Cursor CLI installed (may need auth setup)"

# Default command
CMD ["cursor-agent", "-p", "--api-key", "$CURSOR_API_KEY", "2 + 2 ?"]

```

To reproduce the error:

```auto
docker build -f Dockerfile -t cursor-minimal:latest .

# CURSOR_API_KEY should be set on the host
docker run -it -e CURSOR_API_KEY cursor-minimal:latest

```

### Expected Behavior

It should authenticate fine!

### Screenshots / Screen Recordings

 ![image (1).png](https://us1.discourse-cdn.com/cursor1/original/3X/0/3/03c75208258fa22a7196569f2bacb3165d7c1a3a.png)

### Operating System

Linux

### Current Cursor Version (Menu → About Cursor → Copy)

cursor-agent --version

2025.11.20-a4d3945

### Does this stop you from using Cursor

Yes - Cursor is unusable

---

<div class="post-metadata">

**Author:** ![deanrie](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/deanrie/32/1263_2.png) [@deanrie](https://forum.cursor.com/u/deanrie)\
**Post date:** [November 25, 2025, 4:51am UTC](https://forum.cursor.com/t/cursor-agent-authentication-issue-inside-docker/143995/2 "2025-11-25T04:51:03Z")

</div>

Hey, thanks for the report.

In your Dockerfile, the CMD line uses JSON array syntax, which doesn’t expand environment variables. When you write:

```auto
CMD ["cursor-agent", "-p", "--api-key", "$CURSOR_API_KEY", "2 + 2 ?"]

```

Docker passes the literal string “$CURSOR\_API\_KEY” instead of its value.

Solution option 1: use the shell form

```auto
CMD cursor-agent -p --force --api-key "$CURSOR_API_KEY" "create a.txt with a random word"

```

Solution option 2: remove the `--api-key` flag completely (recommended)

`cursor-agent` automatically reads `CURSOR_API_KEY` from the environment. Just use:

```auto
CMD ["cursor-agent", "-p", "--force", "create a.txt with a random word"]

```

Then run:

```auto
 docker run -it -e CURSOR_API_KEY=your_actual_key_here cursor-minimal:latest

```

This should fix the “invalid API key” error. Let me know if it works.

---

<div class="post-metadata">

**Author:** ![Mohammad\_Mazraeh](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@Mohammad\_Mazraeh](https://forum.cursor.com/u/Mohammad_Mazraeh)\
**Post date:** [November 25, 2025, 7:47am UTC](https://forum.cursor.com/t/cursor-agent-authentication-issue-inside-docker/143995/3 "2025-11-25T07:47:41Z")

</div>

> [@deanrie](#):
>
> ```auto
> docker run -it -e CURSOR_API_KEY=your_actual_key_here cursor-minimal:latest
> 
> ```

Thanks for the reply @deanrie !

Unfortunately it does not work for me. The code snippets I’ve provided are just to reproduce the error, when I run shell inside the container, set `CURSOR_API_KEY` , and try the cursor-agent, it still fails with the same error.

---

<div class="post-metadata">

**Author:** ![ravirahman](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/ravirahman/32/20386_2.png) [@ravirahman](https://forum.cursor.com/u/ravirahman)\
**Post date:** [November 25, 2025, 8:40am UTC](https://forum.cursor.com/t/cursor-agent-authentication-issue-inside-docker/143995/6 "2025-11-25T08:40:41Z")

</div>

Hi @Mohammad_Mazraeh , could you try solution 2 again? Note that you would have to rebuild the dockerimage after changing the `CMD` argument. This should work, assuming your CURSOR\_API\_KEY is set in your host environment, as the agent reads this variable.

---

<div class="post-metadata">

**Author:** ![Mohammad\_Mazraeh](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@Mohammad\_Mazraeh](https://forum.cursor.com/u/Mohammad_Mazraeh)\
**Post date:** [November 25, 2025, 9:26am UTC](https://forum.cursor.com/t/cursor-agent-authentication-issue-inside-docker/143995/7 "2025-11-25T09:26:44Z")

</div>

> [@deanrie](#):
>
> `create a.txt with a random word`

Thanks @ravirahman for the reply. I have tried #2. Please check the screenshot for the same test on host and inside container (I’m using `bash` to enter container, so `CMD` is being overriden)

 ![image](https://us1.discourse-cdn.com/cursor1/original/3X/f/f/ff9333177a2163f4487018d7206f9a98988d728a.png)

\*\*Update:

1. I just used Ubuntu 24 as base image to be able to install `cursor-agent 2025.11.25-e276529` and the same issue still persists.
2. Even if I run just `cursor-agent` without any parameters or prompts, I’m getting the same error.
3. The other issue is `cursor-agent login` timeouts in a few seconds inside docker container (getting fixed does not solve my problem and I still need API based authentication)

---

<div class="post-metadata">

**Author:** ![ravirahman](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/ravirahman/32/20386_2.png) [@ravirahman](https://forum.cursor.com/u/ravirahman)\
**Post date:** [November 25, 2025, 9:59am UTC](https://forum.cursor.com/t/cursor-agent-authentication-issue-inside-docker/143995/9 "2025-11-25T09:59:49Z")

</div>

This error indicates that the API key was provided, but could not be used to log in. Could you verify that it was supplied correctly? If that doesn’t work, could you try making a new API key?

---

<div class="post-metadata">

**Author:** ![Mohammad\_Mazraeh](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@Mohammad\_Mazraeh](https://forum.cursor.com/u/Mohammad_Mazraeh)\
**Post date:** [November 25, 2025, 10:03am UTC](https://forum.cursor.com/t/cursor-agent-authentication-issue-inside-docker/143995/10 "2025-11-25T10:03:09Z")

</div>

@ravirahman in the attached screenshot to the above message, I’m using same API key on the host (my laptop) and it seems to be working. same series of commands inside the container doesn’t work. I’ve tested a few ways of providing the API key.

Did you happen to get a chance and see if you can reproduce the error?

---

<div class="post-metadata">

**Author:** ![Mohammad\_Mazraeh](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@Mohammad\_Mazraeh](https://forum.cursor.com/u/Mohammad_Mazraeh)\
**Post date:** [December 1, 2025, 9:27pm UTC](https://forum.cursor.com/t/cursor-agent-authentication-issue-inside-docker/143995/12 "2025-12-01T21:27:58Z")

</div>

@ravirahman @deanrie Did you get a chance to try and reproduce the error? I asked my colleagues as well and I’m confident it’s an issue with cursor authentication inside a docker container.

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/system/32/99069_2.png) [@system](https://forum.cursor.com/u/system)\
**Post date:** [December 23, 2025, 9:28pm UTC](https://forum.cursor.com/t/cursor-agent-authentication-issue-inside-docker/143995/14 "2025-12-23T21:28:44Z")

</div>

This topic was automatically closed 22 days after the last reply. New replies are no longer allowed.
