the universal sandbox runtime for agents and humans.
pocketenv.io
sandbox
openclaw
agent
claude-code
vercel-sandbox
deno-sandbox
cloudflare-sandbox
atproto
sprites
daytona
1import sodium from "libsodium-wrappers";
2import process from "node:process";
3
4await sodium.ready;
5
6export default function decrypt(value?: string): string | undefined {
7 if (!value) {
8 return undefined;
9 }
10
11 const { PUBLIC_KEY, PRIVATE_KEY } = process.env;
12 if (!PUBLIC_KEY || !PRIVATE_KEY) {
13 throw new Error(
14 "PUBLIC_KEY and PRIVATE_KEY environment variables must be set for decryption",
15 );
16 }
17
18 const sealed = sodium.from_base64(
19 value,
20 sodium.base64_variants.URLSAFE_NO_PADDING,
21 );
22 const decryptedBytes = sodium.crypto_box_seal_open(
23 sealed,
24 sodium.from_hex(PUBLIC_KEY),
25 sodium.from_hex(PRIVATE_KEY),
26 );
27 return sodium.to_string(decryptedBytes);
28}