@@ -310,8 +310,12 @@ async function executeCode(request, executionId) {
310310 info: (...args) => __log(...args),
311311 };
312312
313- // Set up fetch function that uses the host's secure fetch
314- async function fetch(url, options) {
313+ // Set up fetch function that uses the host's secure fetch. The raw
314+ // host bridge is captured in this closure so the hardening step below
315+ // can undefine the global without breaking fetch().
316+ (() => {
317+ const __fetch = globalThis.__fetchRef;
318+ globalThis.fetch = async function fetch(url, options) {
315319 let optionsJson;
316320 if (options) {
317321 try {
@@ -323,7 +327,7 @@ async function executeCode(request, executionId) {
323327 throw new Error('fetch options exceed maximum payload size');
324328 }
325329 }
326- const resultJson = await __fetchRef .apply(undefined, [url, optionsJson], { result: { promise: true } });
330+ const resultJson = await __fetch .apply(undefined, [url, optionsJson], { result: { promise: true } });
327331 let result;
328332 try {
329333 result = JSON.parse(resultJson);
@@ -355,7 +359,8 @@ async function executeCode(request, executionId) {
355359 blob: async () => { throw new Error('blob() not supported in sandbox'); },
356360 arrayBuffer: async () => { throw new Error('arrayBuffer() not supported in sandbox'); },
357361 };
358- }
362+ };
363+ })();
359364
360365 const sim = (() => {
361366 const broker = __brokerRef;
@@ -408,7 +413,7 @@ async function executeCode(request, executionId) {
408413 const undefined_globals = [
409414 'Isolate', 'Context', 'Script', 'Module', 'Callback', 'Reference',
410415 'ExternalCopy', 'process', 'require', 'module', 'exports', '__dirname', '__filename',
411- '__brokerRef', '__broker', '__callSimBroker'
416+ '__fetchRef', ' __brokerRef', '__broker', '__callSimBroker'
412417 ];
413418 for (const name of undefined_globals) {
414419 try {
0 commit comments