I'm not sure what's going on but the last two batches of homemade cashew and sunflower seed milks went bad faster than usual i.e. 1-2 days.
What can be added to make them last longer? Both artificial and natural preservatives are ok for me.
This question has two facades:
Before blending the nuts, I soak them in vinegar for a while and rinse thoroughly. And always using sanitized equipment and boiling the water (and sugar if you're adding) is quite a good practice to kill the microorganisms you might have in your ingredients.
If you have a sous-vide setup, using the lowest pasteurization temperature at 54C you can try to pasteurize. Please check some charts on this. It's hard to give an estimate without knowing your container sizes. Some nut-milk can handle acidity, some can't you can experiment with that as well.
Roast your nuts first in the oven. Use water that's been previously boiled. Ensure all containers and tools are sterilized. Add a pinch of salt.