/**
* Indexes the runtime environment for sandbox usage with error logging.
*
* @returns {object} An object containing the indexed environment data and error logs.
*/
function indexRuntimeEnvironment() {
const environmentData = {};
const errorLogs = [];
try {
// Collect environment variables
const env = process.env;
for (const key in env) {
if (env.hasOwnProperty(key)) {
environmentData[key] = env[key];
}
}
// Collect global objects (careful with this for security)
environmentData.globalObjects = global;
// Collect built-in functions (careful with this for security)
environmentData.builtInFunctions = Object.keys(global).filter(key => typeof global[key] === 'function');
} catch (err) {
errorLogs.push({
type: 'environment_index_error',
message: `Error during environment indexing: ${err.message}`,
stack: err.stack
});
}
return {
environment: environmentData,
errors: errorLogs
};
}
// Example usage (for testing - remove in production)
const result = indexRuntimeEnvironment();
console.log(JSON.stringify(result.environment, null, 2)); // Output environment data
console.log(JSON.stringify(result.errors, null, 2)); // Output error logs
Add your comment