In dune-project you can specify the dependency versions of the project (and generate opam files)
Is there any way to ban a specific dependency, so that it can’t be used as a dependency in dune files (in libraries)?
For example if str is discouraged, how can you ban it from appearing in dune files?
Not quite what you asked, but there is a field (forbidden_libraries) in the (executable) stanza which can be used to forbid certain libraries from being linked into an executable. See Stanza Reference — Dune documentation for the details.