Skip to content

Simple development environment for the Glide Code Sandbox

glideapps/code-sandbox-playground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Glide JS Code Sandbox

This is a simple development environment for creating and testing Javascript code that can be used in the Glide Code Sandbox.

Overview

This sandbox allows you to write a JavaScript function that:

  • Takes a JSON object as input
  • Returns a JSON object as output
  • Can use the NPM packages that come with the sandbox
  • Can be easily tested

Using a Coding Agent

This environment is friendly to coding agents like Claude Code, so just run it and tell it what kind of code you need. It'll figure it out. Once it's done, copy/paste the code in code.js into the plugin. You can ignore the rest of this document unless you want to develop manually.

Getting Started Manually

  1. Install dependencies:
npm install
  1. Edit code.js to implement your logic in the run function

  2. Test your code:

npm test
  1. Run your code with custom input:
npm start -- '{ "your": "input" }'

Available Packages

Your code.js file can import and use these packages:

  • lodash - Utility library
  • date-fns - Date manipulation
  • ms - Time string conversion
  • uuid - UUID generation
  • fast-deep-equal - Deep equality checking

Using Secrets and Environment Variables

CRITICAL SECURITY RULE

🚨 NEVER HARDCODE SECRETS IN YOUR CODE! 🚨

API keys, tokens, passwords, and any sensitive data MUST ONLY be stored in .env files and accessed via process.env. NEVER write secrets directly in code.js or any other code file!

❌ WRONG - NEVER DO THIS:

// DANGER! This exposes your secrets! const apiKey = 'sk-1234567890abcdef'; // ❌ NO! const password = 'mySecretPassword'; // ❌ NO!

βœ… CORRECT - ALWAYS DO THIS:

// Safe! Secrets stored in .env file const apiKey = process.env.API_KEY; // βœ… YES! const password = process.env.PASSWORD; // βœ… YES!

How to Use Environment Variables

  1. Create a .env file in the project root (see .env.example for reference):
API_KEY=your_secret_api_key_here DATABASE_URL=postgres://localhost/mydb
  1. Access them in your code.js:
export async function run(input) { const apiKey = process.env.API_KEY; const dbUrl = process.env.DATABASE_URL; // Use your secrets safely return { authenticated: !!apiKey }; }

Important:

  • .env is already in .gitignore - it will NEVER be committed to version control
  • Use .env.example to document which variables are needed (without actual secret values)
  • When deploying to Glide, configure these secrets in the Glide environment
  • NEVER EVER put actual secret values in code files!

Error Handling and Exceptions

Throw exceptions to signal errors - Glide will automatically retry!

When your code throws an exception, Glide treats it as an error and will automatically retry the operation. This means you can simply throw exceptions when something goes wrong, and Glide handles the retry logic for you.

Example:

export async function run(input) { const response = await fetch('https://api.example.com/data'); // Just throw an exception if something goes wrong if (!response.ok) { throw new Error(`API request failed: ${response.status} ${response.statusText}`); } return { data: await response.json() }; }

Key points:

  • Throw exceptions to signal errors
  • Glide automatically retries when exceptions are thrown
  • The dev environment will catch and display exceptions with helpful messages
  • No retry logic needed in your code - Glide handles this automatically

File Structure

  • code.js - Your main implementation (edit this!)
  • code.test.js - Test suite for your code
  • runner.js - CLI runner (don't modify)
  • package.json - Project configuration

Writing Your Code

The code.js file must export an async function named run:

export async function run(input) { // Your logic here // input is a JSON object // return a JSON object return { result: "your output" }; }

Example

import _ from 'lodash'; export async function run(input) { return { uppercased: _.upperCase(input.text), timestamp: new Date().toISOString() }; }

Run it:

npm start -- '{ "text": "hello world" }'

Testing

Tests use Node's built-in test runner. Add your tests to code.test.js:

import { test, describe } from 'node:test'; import assert from 'node:assert'; import { run } from './code.js'; describe('my tests', () => { test('should work correctly', async () => { const result = await run({ input: 'test' }); assert.strictEqual(result.output, 'expected'); }); });

Run tests:

npm test

Rules and Constraints

  • Only code.js can be modified for your implementation
  • The function must be named run and must be exported
  • Only the specified packages are available
  • No other code files can be imported
  • Input and output must be JSON-serializable objects

Example Usage

# Simple input npm start -- '{ "name": "Alice" }' # Complex input npm start -- '{ "users": ["Alice", "Bob"], "active": true, "count": 42 }' # Run tests npm test

Console Output

All console.log() statements in your code.js will output to the console, making debugging easy.

About

Simple development environment for the Glide Code Sandbox

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published