You can set ENV['yourkey'] = 'yourval' in your plugin and that works. I used it just today to test my code.
Also, you can install gems specific to modes. I haven’t tried it myself yet but here’s an example. discourse-assign/Gemfile at main · discourse/discourse-assign · GitHub