Run failed: Failed to execute code, which is likely a network issue, please check if the sandbox service is running. ( Error: Failed to execute code, got status code 502, please check if the sandbox service is running ) #6278

Closed
opened 2026-02-21 18:14:51 -05:00 by yindo · 4 comments
Owner

Originally created by @Megadeth9919 on GitHub (Oct 23, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.9.2

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

  1. Start with Local Source Code without frontend
  2. Start Frontend Docker Container Separately
  3. Then create a demo workflow with code executor like this
    image

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @Megadeth9919 on GitHub (Oct 23, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.9.2 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce 1. [Start with Local Source Code without frontend](https://docs.dify.ai/getting-started/install-self-hosted/local-source-code) 2. [Start Frontend Docker Container Separately](https://docs.dify.ai/getting-started/install-self-hosted/start-the-frontend-docker-container) 3. Then create a demo workflow with code executor like this ![image](https://github.com/user-attachments/assets/b345b120-04a6-400e-800c-a62b9ee7395d) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:14:51 -05:00
yindo closed this issue 2026-02-21 18:14:51 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 23, 2024):

@Megadeth9919 Hello there! I'm here to help you with bugs, questions, and becoming a contributor. Let's squash those bugs together! 🤖

I found some similar issues and discussions that might help you resolve the 502 error related to the sandbox service in your self-hosted Dify environment:

  1. Local Docker Setup Failure - This discussion is open and might contain relevant troubleshooting steps for Docker setup issues [1].

  2. Sandbox can't use - This is another open discussion that addresses issues with the sandbox service [2].

  3. Sandbox service start - This discussion is also open and might provide insights into starting the sandbox service correctly [3].

For resolving the 502 error, ensure the following:

  • Sandbox Service Availability: Verify that the sandbox service is running. Use docker compose ps to check the status of all containers and ensure the sandbox service is active [4].

  • Configuration Settings: Check that the dify_config.CODE_EXECUTION_ENDPOINT and dify_config.CODE_EXECUTION_API_KEY are correctly set. The API key should match the one configured in your setup [4].

  • Network and Proxy Configuration: Ensure there are no network issues and that the ssrf_proxy service is running and properly configured. The proxy settings should match the proxy service's address [4].

  • Nginx Configuration: Use the command docker ps -q | xargs -n 1 docker inspect --format '{{ .Name }}: {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' to find the correct IP addresses for your containers. Update the Nginx configuration with these IPs and restart the Nginx container [4].

These steps should help you troubleshoot and resolve the 502 error in your Dify setup.

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Oct 23, 2024): <!-- Greeting --> @Megadeth9919 Hello there! I'm here to help you with bugs, questions, and becoming a contributor. Let's squash those bugs together! 🤖 <!-- Answer --> I found some similar issues and discussions that might help you resolve the 502 error related to the sandbox service in your self-hosted Dify environment: 1. **[Local Docker Setup Failure](https://github.com/langgenius/dify/discussions/9344)** - This discussion is open and might contain relevant troubleshooting steps for Docker setup issues <sup>[[1]](https://github.com/langgenius/dify/discussions/9344)</sup>. 2. **[Sandbox can't use](https://github.com/langgenius/dify/discussions/8612)** - This is another open discussion that addresses issues with the sandbox service <sup>[[2]](https://github.com/langgenius/dify/discussions/8612)</sup>. 3. **[Sandbox service start](https://github.com/langgenius/dify/discussions/8520)** - This discussion is also open and might provide insights into starting the sandbox service correctly <sup>[[3]](https://github.com/langgenius/dify/discussions/8520)</sup>. For resolving the 502 error, ensure the following: - **Sandbox Service Availability**: Verify that the sandbox service is running. Use `docker compose ps` to check the status of all containers and ensure the sandbox service is active <sup>[[4]](https://github.com/langgenius/dify/blob/main/api/core/helper/code_executor/code_executor.py)</sup>. - **Configuration Settings**: Check that the `dify_config.CODE_EXECUTION_ENDPOINT` and `dify_config.CODE_EXECUTION_API_KEY` are correctly set. The API key should match the one configured in your setup <sup>[[4]](https://github.com/langgenius/dify/blob/main/api/core/helper/code_executor/code_executor.py)</sup>. - **Network and Proxy Configuration**: Ensure there are no network issues and that the `ssrf_proxy` service is running and properly configured. The proxy settings should match the proxy service's address <sup>[[4]](https://github.com/langgenius/dify/blob/main/api/core/helper/code_executor/code_executor.py)</sup>. - **Nginx Configuration**: Use the command `docker ps -q | xargs -n 1 docker inspect --format '{{ .Name }}: {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'` to find the correct IP addresses for your containers. Update the Nginx configuration with these IPs and restart the Nginx container <sup>[[4]](https://github.com/langgenius/dify/blob/main/api/core/helper/code_executor/code_executor.py)</sup>. These steps should help you troubleshoot and resolve the 502 error in your Dify setup. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@Megadeth9919 commented on GitHub (Oct 23, 2024):

local api server log

2024-10-23 13:47:28,357.357 INFO [Thread-4423 (process_request_thread)] [_internal.py:97] - 127.0.0.1 - - [23/Oct/2024 13:47:28] "POST /console/api/apps/9cf38c92-14a7-4332-94d4-27d434680235/advanced-chat/workflows/draft/run HTTP/1.1" 200 -
2024-10-23 13:47:28,805.805 INFO [Thread-4424 (_generate_worker)] [_client.py:1038] - HTTP Request: POST https://open.bigmodel.cn/api/paas/v4/chat/completions "HTTP/1.1 200 OK"
2024-10-23 13:47:30,946.946 INFO [Thread-4424 (_generate_worker)] [_client.py:1038] - HTTP Request: POST http://127.0.0.1:8194/v1/sandbox/run "HTTP/1.1 502 Bad Gateway"

docker-ssrf_proxy-1 log

(empty)

docker-sandbox-1 log

2024-10-23 21:50:02 [GIN] 2024/10/23 - 13:50:02 | 200 | 41.25µs | ::1 | GET "/health"
2024-10-23 21:50:32 [GIN] 2024/10/23 - 13:50:32 | 200 | 32.272µs | ::1 | GET "/health"
2024-10-23 21:51:02 [GIN] 2024/10/23 - 13:51:02 | 200 | 43.875µs | ::1 | GET "/health"
2024-10-23 21:51:32 [GIN] 2024/10/23 - 13:51:32 | 200 | 33.745µs | ::1 | GET "/health"

@Megadeth9919 commented on GitHub (Oct 23, 2024): # local api server log 2024-10-23 13:47:28,357.357 INFO [Thread-4423 (process_request_thread)] [_internal.py:97] - 127.0.0.1 - - [23/Oct/2024 13:47:28] "POST /console/api/apps/9cf38c92-14a7-4332-94d4-27d434680235/advanced-chat/workflows/draft/run HTTP/1.1" 200 - 2024-10-23 13:47:28,805.805 INFO [Thread-4424 (_generate_worker)] [_client.py:1038] - HTTP Request: POST https://open.bigmodel.cn/api/paas/v4/chat/completions "HTTP/1.1 200 OK" 2024-10-23 13:47:30,946.946 INFO [Thread-4424 (_generate_worker)] [_client.py:1038] - HTTP Request: POST http://127.0.0.1:8194/v1/sandbox/run "HTTP/1.1 502 Bad Gateway" # docker-ssrf_proxy-1 log (empty) # docker-sandbox-1 log 2024-10-23 21:50:02 [GIN] 2024/10/23 - 13:50:02 | 200 | 41.25µs | ::1 | GET "/health" 2024-10-23 21:50:32 [GIN] 2024/10/23 - 13:50:32 | 200 | 32.272µs | ::1 | GET "/health" 2024-10-23 21:51:02 [GIN] 2024/10/23 - 13:51:02 | 200 | 43.875µs | ::1 | GET "/health" 2024-10-23 21:51:32 [GIN] 2024/10/23 - 13:51:32 | 200 | 33.745µs | ::1 | GET "/health"
Author
Owner

@crazywoola commented on GitHub (Oct 23, 2024):

Please follow the instructions carefully when you use Self Hosted (Source). You need to start the sandbox services as well.

@crazywoola commented on GitHub (Oct 23, 2024): Please follow the instructions carefully when you use `Self Hosted (Source)`. You need to start the sandbox services as well.
Author
Owner

@Megadeth9919 commented on GitHub (Oct 23, 2024):

I think maybe I have already started the sandbox service, but it still doesn't work.
image

@Megadeth9919 commented on GitHub (Oct 23, 2024): I think maybe I have already started the sandbox service, but it still doesn't work. ![image](https://github.com/user-attachments/assets/5575d056-1326-4989-bf3f-8dbe89ce6d13)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6278