For Flask apps, you can create a launch.json configuration that will run your Flask app using VS Code's debugger. VS Code's launch.json supports a number of options, including the setting of environment variables that your Flask app needs.
Start with installing the Python extension for VS Code, to add support for "debugging of a number of types of Python applications, which includes Flask. Then, follow the Flask Tutorial from the VS Code docs.
Basically, you'll need to create a launch.json file in your workspace's .vscode folder.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "run-flask-app",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "/path/to/app.py",
"FLASK_ENV": "development",
"FLASK_DEBUG": "0",
"AAA": "value of AAA env var",
"BBB": "value of BBB env var",
"CCC": "value of CCC env var"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"jinja": true
},
]
}
The env portion is where you set all the environment variables. By default, it includes the required FLASK_*-related variables because it uses the flask command line tool for running apps.
Here, as an example, I've also set custom AAA and BBB and CCC vars. You can access that from code as normal env vars:
@app.route('/test')
def root():
aaa = os.environ.get("AAA")
bbb = os.environ.get("BBB")
ccc = os.environ.get("CCC")
print(f'{aaa}, {bbb}, {ccc}')
return f'{aaa}, {bbb}, {ccc}'
Then run it from the Debug panel:

Just hit the play button and you should be able to see the printed env values from the Terminal panel or from the browser after accessing the /test endpoint. (If you have multiple terminals, it should appear under the Python Debug Console).

Lastly, by saving the .vscode/launch.json file under the workspace folder, then it's workspace-specific, and it will only affect the runtime environment used to launch your Flask app.