Skip to content
Dashboard

Safely inject credentials in HTTP headers with Vercel Sandbox

const sandbox = await Sandbox.create({
timeout: 300_000,
networkPolicy: {
allow: {
"ai-gateway.vercel.sh": [{
transform: [{
headers: {
authorization: `Bearer ${process.env.AI_GATEWAY_API_KEY}`
}
}],
}],
},
},
});
// Code inside the sandbox calls AI Gateway without knowing the API key
const result = await sandbox.runCommand('curl',
['-s', 'https://ai-gateway.vercel.sh/v1/models']
);

const sandbox = await Sandbox.create({
networkPolicy: {
allow: {
"ai-gateway.vercel.sh": [{
transform: [{
headers: {
Authorization: `Bearer ${process.env.AI_GATEWAY_API_KEY}`
}
}],
}],
"*.github.com": [{
transform: [{
headers: {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`
}
}],
}],
// Allow traffic to all other domains.
"*": []
}
}
});

Link to headingLive updates

// Phase 1: Clone repos with credentials
await sandbox.updateNetworkPolicy({
allow: {
"api.github.com": [{
transform: [{
headers: {
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`
}
}],
}],
}
});
// ... clone repos, download data ...
// Phase 2: Lock down before running untrusted code
await sandbox.updateNetworkPolicy('deny-all');

Link to headingKey highlights

Ready to deploy?