sandbox can't use #5672

Closed
opened 2026-02-21 18:12:07 -05:00 by yindo · 2 comments
Owner

Originally created by @blackwhite084 on GitHub (Sep 18, 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.8.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

api-1 | 2024-09-18 15:30:24,368.368 INFO [Dummy-1] [_client.py:1038] - HTTP Request: POST http://sandbox:8194/v1/sandbox/run "HTTP/1.1 502 Bad Gateway"

✔️ Expected Behavior

run the code

Actual Behavior

No response

Originally created by @blackwhite084 on GitHub (Sep 18, 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.8.2 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce api-1 | 2024-09-18 15:30:24,368.368 INFO [Dummy-1] [_client.py:1038] - HTTP Request: POST http://sandbox:8194/v1/sandbox/run "HTTP/1.1 502 Bad Gateway" ### ✔️ Expected Behavior run the code ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:12:07 -05:00
yindo closed this issue 2026-02-21 18:12:07 -05:00
Author
Owner

@blackwhite084 commented on GitHub (Sep 18, 2024):

the sandbox is running,docker exec -it ---> curl -f http://localhost:8194/health is ok

@blackwhite084 commented on GitHub (Sep 18, 2024): the sandbox is running,docker exec -it ---> curl -f http://localhost:8194/health is ok
Author
Owner

@dosubot[bot] commented on GitHub (Sep 18, 2024):

Hey @blackwhite084! I'm here to help you with any issues you encounter. I'm a bot that can assist you with bugs, questions, and contributions while you wait for a human maintainer.

I found some similar discussions that might be relevant to your issue:

  1. Sandbox service start (open)
  2. connection error: request error, status_code: 503 (open)
  3. Node Code run failed (open) [1][2][3].

The "502 Bad Gateway" error is likely due to a misconfiguration in the reverse proxy settings. Ensure that the cache_peer directive in the Squid configuration is set to the actual IP address or hostname of the sandbox server instead of sandbox.

Here is the relevant part of the configuration:

################################## Reverse Proxy To Sandbox ################################
http_port 8194 accel vhost
cache_peer <sandbox_ip_or_hostname> parent 8194 0 no-query originserver
acl src_all src all
http_access allow src_all

Additionally, ensure that the SSRF_SANDBOX_HOST environment variable in your .env file is correctly set to the actual hostname or IP address of the sandbox server:

# Environment Variables for SSRF Proxy
SSRF_HTTP_PORT=3128
SSRF_COREDUMP_DIR=/var/spool/squid
SSRF_REVERSE_PROXY_PORT=8194
SSRF_SANDBOX_HOST=<sandbox_ip_or_hostname>

Also, verify that the SANDBOX_PORT environment variable in your docker-compose.yaml file is set to 8194 and that the HTTP_PROXY and HTTPS_PROXY environment variables are correctly pointing to the SSRF proxy:

# The DifySandbox
sandbox:
  image: langgenius/dify-sandbox:0.2.9
  restart: always
  environment:
    API_KEY: ${SANDBOX_API_KEY:-dify-sandbox}
    GIN_MODE: ${SANDBOX_GIN_MODE:-release}
    WORKER_TIMEOUT: ${SANDBOX_WORKER_TIMEOUT:-15}
    ENABLE_NETWORK: ${SANDBOX_ENABLE_NETWORK:-true}
    HTTP_PROXY: ${SANDBOX_HTTP_PROXY:-http://ssrf_proxy:3128}
    HTTPS_PROXY: ${SANDBOX_HTTPS_PROXY:-http://ssrf_proxy:3128}
    SANDBOX_PORT: ${SANDBOX_PORT:-8194}
  volumes:
    - ./volumes/sandbox/dependencies:/dependencies
  healthcheck:
    test: [ "CMD", "curl", "-f", "http://localhost:8194/health" ]
  networks:
    - ssrf_proxy_network

After making these changes, restart the Squid service and the Docker containers to apply the new configuration [4][5][6][7].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 18, 2024): <!-- Greeting --> Hey @blackwhite084! I'm here to help you with any issues you encounter. I'm a bot that can assist you with bugs, questions, and contributions while you wait for a human maintainer. <!-- Answer --> I found some similar discussions that might be relevant to your issue: 1. [Sandbox service start](https://github.com/langgenius/dify/discussions/8520) (open) 2. [connection error: request error, status_code: 503](https://github.com/langgenius/dify/discussions/6181) (open) 3. [Node Code run failed](https://github.com/langgenius/dify/discussions/7902) (open) <sup>[[1]](https://github.com/langgenius/dify/discussions/8520)</sup><sup>[[2]](https://github.com/langgenius/dify/discussions/6181)</sup><sup>[[3]](https://github.com/langgenius/dify/discussions/7902)</sup>. The "502 Bad Gateway" error is likely due to a misconfiguration in the reverse proxy settings. Ensure that the `cache_peer` directive in the Squid configuration is set to the actual IP address or hostname of the sandbox server instead of `sandbox`. Here is the relevant part of the configuration: ```conf ################################## Reverse Proxy To Sandbox ################################ http_port 8194 accel vhost cache_peer <sandbox_ip_or_hostname> parent 8194 0 no-query originserver acl src_all src all http_access allow src_all ``` Additionally, ensure that the `SSRF_SANDBOX_HOST` environment variable in your `.env` file is correctly set to the actual hostname or IP address of the sandbox server: ```example # Environment Variables for SSRF Proxy SSRF_HTTP_PORT=3128 SSRF_COREDUMP_DIR=/var/spool/squid SSRF_REVERSE_PROXY_PORT=8194 SSRF_SANDBOX_HOST=<sandbox_ip_or_hostname> ``` Also, verify that the `SANDBOX_PORT` environment variable in your `docker-compose.yaml` file is set to `8194` and that the `HTTP_PROXY` and `HTTPS_PROXY` environment variables are correctly pointing to the SSRF proxy: ```yaml # The DifySandbox sandbox: image: langgenius/dify-sandbox:0.2.9 restart: always environment: API_KEY: ${SANDBOX_API_KEY:-dify-sandbox} GIN_MODE: ${SANDBOX_GIN_MODE:-release} WORKER_TIMEOUT: ${SANDBOX_WORKER_TIMEOUT:-15} ENABLE_NETWORK: ${SANDBOX_ENABLE_NETWORK:-true} HTTP_PROXY: ${SANDBOX_HTTP_PROXY:-http://ssrf_proxy:3128} HTTPS_PROXY: ${SANDBOX_HTTPS_PROXY:-http://ssrf_proxy:3128} SANDBOX_PORT: ${SANDBOX_PORT:-8194} volumes: - ./volumes/sandbox/dependencies:/dependencies healthcheck: test: [ "CMD", "curl", "-f", "http://localhost:8194/health" ] networks: - ssrf_proxy_network ``` After making these changes, restart the Squid service and the Docker containers to apply the new configuration <sup>[[4]](https://github.com/langgenius/dify/blob/main/docker-legacy/volumes/ssrf_proxy/squid.conf)</sup><sup>[[5]](https://github.com/langgenius/dify/blob/main/docker/docker-compose.middleware.yaml)</sup><sup>[[6]](https://github.com/langgenius/dify/blob/main/docker/.env.example)</sup><sup>[[7]](https://github.com/langgenius/dify/blob/main/docker/docker-compose.yaml)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5672