Skip to main content
Manage environment variables in HopX sandboxes using the env command. List, get, set, and delete environment variables to configure execution environments.

Command Syntax

hopx env <subcommand> [options]

Subcommands

list

List all environment variables in a sandbox. Syntax:
hopx env list SANDBOX_ID [OPTIONS]
Arguments:
  • SANDBOX_ID - Sandbox ID (required)
Options:
  • --output, -o FORMAT - Output format: table, json, plain (default: table)
Examples:
# List all environment variables
hopx env list sb_abc123

# List with JSON output
hopx env list sb_abc123 --output json
Expected Output (Table):
┌───────────┬─────────────┐
│ Variable  │ Value       │
├───────────┼─────────────┤
│ API_KEY   │ secret123   │
│ DEBUG     │ true        │
│ NODE_ENV  │ production  │
└───────────┴─────────────┘
Exit Codes:
  • 0 - Success
  • 3 - Authentication error
  • 4 - Sandbox not found

get

Get the value of a specific environment variable. Syntax:
hopx env get SANDBOX_ID VARIABLE [OPTIONS]
Arguments:
  • SANDBOX_ID - Sandbox ID (required)
  • VARIABLE - Environment variable name (required)
Examples:
# Get environment variable
hopx env get sb_abc123 API_KEY

# Get with JSON output
hopx env get sb_abc123 DEBUG --output json
Expected Output:
secret123
Exit Codes:
  • 0 - Success
  • 3 - Authentication error
  • 4 - Sandbox or variable not found

set

Set one or more environment variables. Syntax:
hopx env set SANDBOX_ID [KEY] [VALUE] [OPTIONS]
Arguments:
  • SANDBOX_ID - Sandbox ID (required)
  • KEY - Environment variable name (optional, use with --env for multiple)
  • VALUE - Environment variable value (optional, use with --env for multiple)
Options:
  • --env, -e TEXT - Environment variable in KEY=VALUE format (repeatable)
  • --env-file PATH - Load environment variables from file
Examples:
# Set single variable (positional arguments)
hopx env set sb_abc123 API_KEY secret123

# Set multiple variables using --env flag
hopx env set sb_abc123 --env API_KEY=secret123 --env DEBUG=true --env NODE_ENV=production

# Set from file
hopx env set sb_abc123 --env-file .env
Expected Output:
✓ Environment variables set
Exit Codes:
  • 0 - Success
  • 3 - Authentication error
  • 4 - Sandbox not found

delete

Delete an environment variable. Syntax:
hopx env delete SANDBOX_ID VARIABLE [OPTIONS]
Arguments:
  • SANDBOX_ID - Sandbox ID (required)
  • VARIABLE - Environment variable name to delete (required)
Examples:
# Delete environment variable
hopx env delete sb_abc123 DEBUG
Expected Output:
✓ Environment variable deleted: DEBUG
Exit Codes:
  • 0 - Success
  • 3 - Authentication error
  • 4 - Sandbox or variable not found

Shell Scripting Examples

Configure Environment for Code Execution

#!/bin/bash
set -e

SANDBOX_ID="sb_abc123"

# Set environment variables
hopx env set "$SANDBOX_ID" \
  API_KEY=secret123 \
  DEBUG=true \
  NODE_ENV=production

# Execute code that uses environment variables
hopx run "import os; print(os.environ['API_KEY'])" --sandbox "$SANDBOX_ID"

Load Environment from File

#!/bin/bash

# Create .env file
cat > .env << EOF
API_KEY=secret123
DEBUG=true
NODE_ENV=production
EOF

# Load into sandbox
hopx env set sb_abc123 --env-file .env

Conditional Environment Setup

#!/bin/bash

# Check if variable exists
if hopx env get sb_abc123 API_KEY > /dev/null 2>&1; then
    echo "API_KEY already set"
else
    echo "Setting API_KEY..."
    hopx env set sb_abc123 API_KEY=secret123
fi

List and Export Variables

#!/bin/bash

# List variables and export to local environment
hopx env list sb_abc123 --output json | jq -r 'to_entries[] | "export \(.key)=\(.value)"' | source /dev/stdin

Next Steps