Skip to main content
The EnvironmentVariables resource provides methods for managing environment variables inside sandboxes at runtime.

Accessing Environment Variables Resource

import { Sandbox } from '@hopx-ai/sdk';

const sandbox = await Sandbox.create({ template: 'code-interpreter' });
await sandbox.init();
const env = sandbox.env;  // Lazy-loaded resource

Getting Environment Variables

getAll()

Get all environment variables.
const envVars = await sandbox.env.getAll();
console.log(envVars.PATH);
console.log(envVars.HOME);
Method Signature:
async getAll(): Promise<Record<string, string>>

get()

Get a specific environment variable value.
const apiKey = await sandbox.env.get('API_KEY');
const dbUrl = await sandbox.env.get('DATABASE_URL') || 'postgres://localhost/db';
Method Signature:
async get(key: string): Promise<string | undefined>

Setting Environment Variables

set()

Set a single environment variable (merges with existing).
await sandbox.env.set('API_KEY', 'sk-prod-xyz');
await sandbox.env.set('NODE_ENV', 'production');
Method Signature:
async set(key: string, value: string): Promise<void>

setAll()

Replace all environment variables (destructive).
await sandbox.env.setAll({
  API_KEY: 'sk-prod-xyz',
  DATABASE_URL: 'postgres://localhost/db',
  NODE_ENV: 'production'
});
Warning: This replaces ALL existing environment variables.

update()

Update specific environment variables (merge with existing).
await sandbox.env.update({
  NODE_ENV: 'production',
  DEBUG: 'false'
});
Note: This merges with existing variables.

Deleting Environment Variables

delete()

Delete an environment variable.
await sandbox.env.delete('DEBUG');
await sandbox.env.delete('TEMP_TOKEN');
Method Signature:
async delete(key: string): Promise<void>