refactor sandbox key generation and saving