Safeguard
Security Guides•

Is Flask debug mode safe to leave on? The Werkzeug debugger explained

No. Flask debug mode enables an interactive debugger that runs Python from the browser. The PIN is not a security control. What to run in production.

Safeguard Security Team
4 min read

No. Flask debug mode starts the Werkzeug interactive debugger, which can execute arbitrary Python code from a browser. A PIN guards it, but the Flask and Werkzeug docs say not to rely on that for security. Never run the development server or the debugger in production, and use a real WSGI server.

What debug mode turns on

Run flask run --debug and you get the interactive debugger and the reloader. When an unhandled error occurs, the browser shows a traceback with a console that lets you evaluate code in any frame. That is excellent on your laptop.

The Flask debugging page puts it plainly: the debugger allows executing arbitrary Python code from the browser, it is protected by a pin, and it still represents a major security risk. The Werkzeug page goes further and labels it a danger, saying the debugger must never be used on production machines and that "production" means anything that is not development and anything publicly accessible.

Note that last phrase. A staging server on a public address counts. So does a test box on a shared network.

Why the PIN is not enough

A PIN is a speed bump, not an access control. Flask's docs say the pin should not be relied on for security. Treat any exposed debugger as full remote code execution on the host, running with your application's privileges and able to read its environment, files and credentials.

Dev server versus production server

Flask's deployment page says the development server is for local development only and is not designed to be particularly secure, stable or efficient. It defines production simply as "not development".

SettingDevelopmentProduction
ServerBuilt-in dev serverDedicated WSGI server such as Gunicorn or Waitress
DebuggerAllowed, on localhostOff
ReloaderOnOff
Error detailsBrowser tracebackLogging and error tracking

The deployment page lists several WSGI servers and recommends putting an HTTP server in front as a reverse proxy.

Setting debug the right way

The configuration docs say DEBUG is a special value that can behave inconsistently if changed after the app begins setting up. Use the --debug option on the flask command, and avoid setting DEBUG in config or code, which the docs call strongly discouraged. A practical consequence: do not hardcode app.run(debug=True) in the file your production image runs, because a container that starts it will launch the debugger.

How to check what you have

  1. Search the codebase for debug=True, use_debugger and DEBUG = True.
  2. Look at your container entry point and process manager unit. It should call your WSGI server, not flask run or python app.py.
  3. Make sure no environment variable such as FLASK_DEBUG is set in production configuration.
  4. Confirm that unhandled errors in production return a generic page and appear in your logs.

The debugging page suggests an error logging tool or logging with notifications as the production alternative, and says if you must debug remotely, enable a debugger only temporarily.

Try it yourself

Click through it at your own pace, or open it full screen. See how probing a running app can surface exposed error and debug behavior.

Quick check

Does the debugger PIN make it safe for staging?

No. The docs say not to rely on it for security. Anything reachable from outside your own machine should run with the debugger off.

Is the Flask development server fine for a small internal tool?

Flask says production means not development, and the dev server is not meant for it. Use a WSGI server even for internal tools.

Safeguard's SAST can flag debug=True in a pull request, and policy gates can block the merge. A free scan is available.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.