You can do following if you are not willing to type ‘yes’ everytime you install.
npm_config_yes=true npx cowsay "hello"
See this https://github.com/npm/cli/issues/2226
npx also has a --yes flag you can use to bypass the prompt:
npx --yes some-npm-package
This is undocumented if you run npx --help, but the documentation for this flag is hidden in the command’s “description” on the NPM website.
There is also a --no flag available if you need to reject the prompt instead.