serverless
serverless copied to clipboard
Unconditional use of process.env.* errors in sandboxes such as the Slack deno runtime
Steps to reproduce
I want to use this library in the slack deno sdk. But, slack hosts your code for you, and runs it in a sandboxed deno runtime. One of the restrictions they place is they disallow access to process.env.
I am getting this error when doing the basic hello world:
import { neon } from '@neondatabase/serverless';
const sql = neon(process.env.DATABASE_URL);
const result = await sql`SELECT * FROM table WHERE id = ${1}`;
Caught error from user supplied module: NotCapable: Requires env access to "USER", run again with the --allow-env flag
at Object.getEnv [as get] (ext:deno_os/30_os.js:124:10)
at denoEnvGet (ext:deno_node/_process/process.ts:27:21)
at Object.get (ext:deno_node/_process/process.ts:44:22)
at file:///var/task/functions/agent_capn.js:52659:59
at file:///var/task/functions/agent_capn.js:50088:31
at file:///var/task/functions/agent_capn.js:52696:32
at file:///var/task/functions/agent_capn.js:50088:31
at file:///var/task/functions/agent_capn.js:54977:13
It looks to me like this is caused by https://github.com/neondatabase/serverless/blob/2c51902827a043df0646caf6a5ed8d812e7fb9b6/src/client.ts#L48-L64
We try to access the process.env even though I have passed the connection string so all the params have been set. Instead, can we make it so that we only try to access process.env if we NEED to? Since I passed a connection string, we should be able to avoid accessing process.env entirely.
This looks to me like the only place we access process.env, so with this fix hopefully this will run on slack's infra, which would be really cool, I can have an text to SQL agent right in slack's environment :)
Actually, it looks like the underlying pg library also accesses process.env at the top level, so we would need to also make these same changes there too for me to be able to use this in slack's runtime.