How do Dify API, Plugin Daemon, Code Sandbox, and SSRF proxies actually isolate traffic, and which assumptions mislead?
Short answer
At pinned commit 8394eb1, Dify wires two distinct ingress paths through Nginx: /console/api, /api, and /v1 route to api:5001, while /e/ proxies directly to plugin_daemon:5002 with Dify-Hook-Url. Internally, API and Celery workers call plugin_daemon via a pooled httpx client that explicitly sets trust_env=False, whereas CodeExecutor calls sandbox:8194 without disabling environment proxy inheritance.
Two network boundaries are easy to misread: sandbox sits solely on the internal-only ssrf_proxy_network and relies on ssrf_proxy:3128 for outbound requests, whereas plugin_daemon attaches to both ssrf_proxy_network and default; and Dify also runs a separate local_sandbox (shellctl:5004) with its own dedicated agent_ssrf_proxy:3128. This is independent static source analysis, not upstream endorsement or a runtime trace.
Pinned-commit evidence
Every evidence link below is bound to langgenius/dify commit 8394eb190b16544e0d6c8b005fd18d7f07a00e71 and points to an exact line or range.
Open the offline interactive artifact · Inspect the JSON source · Open the pinned commit ↗
| From | To | Evidence kind | Finding and permalinks |
|---|---|---|---|
nginx |
api_worker |
config / deployment wiring | Nginx routes /console/api, /api, and /v1 to api:5001. docker/nginx/conf.d/default.conf.template#L8-L33 |
nginx |
plugin_daemon |
config / deployment wiring | Nginx proxies /e/ directly to plugin_daemon:5002 with Dify-Hook-Url. docker/nginx/conf.d/default.conf.template#L47-L52 |
api_worker |
plugin_daemon |
direct HTTP/RPC call | Pooled httpx.Client uses PLUGIN_DAEMON_URL, X-Api-Key, and explicit trust_env=False. api/core/plugin/impl/base.py#L52-L79api/core/plugin/impl/base.py#L154-L187 |
plugin_daemon |
api_worker |
config / deployment wiring | Plugin Daemon configures DIFY_INNER_API_URL=http://api:5001 and shares both ssrf_proxy_network and default. docker/envs/core-services/plugin-daemon.defaults#L69-L82docker/docker-compose.yaml#L657-L678 |
api_worker |
sandbox |
direct HTTP/RPC call | CodeExecutor posts to /v1/sandbox/run with enable_network=True using an httpx.Client that omits trust_env=False. api/core/helper/code_executor/code_executor.py#L19-L47api/core/helper/code_executor/code_executor.py#L81-L105 |
sandbox |
ssrf_proxy |
config / deployment wiring | sandbox attaches only to internal ssrf_proxy_network and routes HTTP(S)_PROXY to ssrf_proxy:3128; Squid denies to_private_networks. docker/docker-compose.yaml#L604-L620docker/envs/core-services/sandbox.defaults#L5-L25docker/ssrf_proxy/squid.conf.template#L3-L17 |
local_sandbox |
agent_ssrf_proxy |
config / deployment wiring | local_sandbox runs shellctl on 5004 with HTTP(S)_PROXY set to dedicated agent_ssrf_proxy:3128 over local_sandbox_proxy_network. docker/docker-compose.yaml#L631-L643docker/docker-compose.yaml#L813-L815docker/docker-compose.yaml#L1421-L1435 |
Boundaries that mislead
Plugin client disables env proxies (trust_env=False), while CodeExecutor does not
api/core/plugin/impl/base.py explicitly passes trust_env=False to its pooled httpx.Client so container HTTP_PROXY settings do not hijack api-to-plugin_daemon calls. api/core/helper/code_executor/code_executor.py omits trust_env=False, so misconfigured container proxy environment variables can intercept sandbox calls unless NO_PROXY excludes sandbox.
api/core/plugin/impl/base.py#L76-L79api/core/helper/code_executor/code_executor.py#L43-L47
sandbox is internal-only, whereas plugin_daemon attaches to default and /e/ bypasses api
sandbox connects only to ssrf_proxy_network (internal: true), forcing egress through Squid ssrf_proxy:3128. By contrast, plugin_daemon connects to both ssrf_proxy_network and default, and Nginx exposes /e/ directly to plugin_daemon:5002 without traversing api:5001.
docker/docker-compose.yaml#L619-L620docker/docker-compose.yaml#L676-L678docker/nginx/conf.d/default.conf.template#L47-L52
Calls and ownership
1. Nginx splits public traffic between API and Plugin Daemon
docker/nginx/conf.d/default.conf.template sends /console/api, /api, and /v1 to api:5001, while location /e/ proxies directly to plugin_daemon:5002 and injects Dify-Hook-Url. Plugin endpoints therefore do not pass through the Python API container on ingress.
2. Asymmetric httpx proxy handling inside Dify API & Workers
BasePluginClient builds its pooled httpx.Client with trust_env=False (max_connections=100, max_keepalive_connections=50) and authenticates with X-Api-Key from PLUGIN_DAEMON_KEY. By contrast, _build_code_executor_client constructs httpx.Client without trust_env=False when posting to /v1/sandbox/run with enable_network=True.
3. Two isolated sandbox networks and two Squid proxies
The code-execution sandbox attaches only to ssrf_proxy_network (internal: true) and configures HTTP_PROXY/HTTPS_PROXY to http://ssrf_proxy:3128, where Squid blocks to_private_networks and allows .marketplace.dify.ai. Separately, local_sandbox runs shellctl on port 5004 with HTTP_PROXY/HTTPS_PROXY pointed to agent_ssrf_proxy:3128 over local_sandbox_proxy_network.
What this proves — and what it does not
- This article is independent static source analysis, not an endorsement by the Dify maintainers. Conclusions are limited to langgenius/dify commit 8394eb190b16544e0d6c8b005fd18d7f07a00e71.
- Direct Python HTTP client calls and Docker Compose / Nginx deployment wiring are labeled separately. Runtime overrides in docker/.env, custom Squid templates, Kubernetes manifests, or external reverse proxies can alter effective routing.
- The seven evidence edges cover the Nginx, API/worker, Plugin Daemon, Code Sandbox, Local Sandbox, and Squid SSRF proxy boundary; database, vector store, Redis, and model-provider edges are intentionally outside this scope.
- Static source review does not prove live SSRF enforcement, container firewall rules, or production request latency.
Reuse with your agent
Give an agent the pinned commit and this review prompt; require it to open every permalink and keep unknowns explicit.
Audit only langgenius/dify commit 8394eb190b16544e0d6c8b005fd18d7f07a00e71. Map the Nginx /e/ direct route to plugin_daemon:5002, contrast trust_env=False in api/core/plugin/impl/base.py against code_executor.py, separate internal-only sandbox + ssrf_proxy from dual-network plugin_daemon, and distinguish local_sandbox + agent_ssrf_proxy. Do not infer runtime firewall behavior or undocumented call sites.
Cite this source case in Markdown
[Dify Plugin Daemon & Sandbox SSRF Boundaries](https://archify.si/cases/dify-plugin-sandbox)
Archify independent static source analysis, limited to the pinned commit.