Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Simple development environment for the Glide Code Sandbox

NotificationsYou must be signed in to change notification settings

glideapps/code-sandbox-playground

Repository files navigation

This is a simple development environment for creating and testing Javascript code that can be used in theGlide 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 incode.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. Editcode.js to implement your logic in therun function

  2. Test your code:

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

Available Packages

Yourcode.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 viaprocess.env. NEVER write secrets directly incode.js or any other code file!

❌ WRONG - NEVER DO THIS:

// DANGER! This exposes your secrets!constapiKey='sk-1234567890abcdef';// ❌ NO!constpassword='mySecretPassword';// ❌ NO!

✅ CORRECT - ALWAYS DO THIS:

// Safe! Secrets stored in .env fileconstapiKey=process.env.API_KEY;// ✅ YES!constpassword=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_hereDATABASE_URL=postgres://localhost/mydb
  1. Access them in yourcode.js:
exportasyncfunctionrun(input){constapiKey=process.env.API_KEY;constdbUrl=process.env.DATABASE_URL;// Use your secrets safelyreturn{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 willautomatically retry the operation. This means you can simply throw exceptions when something goes wrong, and Glide handles the retry logic for you.

Example:

exportasyncfunctionrun(input){constresponse=awaitfetch('https://api.example.com/data');// Just throw an exception if something goes wrongif(!response.ok){thrownewError(`API request failed:${response.status}${response.statusText}`);}return{data:awaitresponse.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

Thecode.js file must export an async function namedrun:

exportasyncfunctionrun(input){// Your logic here// input is a JSON object// return a JSON objectreturn{result:"your output"};}

Example

import_from'lodash';exportasyncfunctionrun(input){return{uppercased:_.upperCase(input.text),timestamp:newDate().toISOString()};}

Run it:

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

Testing

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

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

Run tests:

npmtest

Rules and Constraints

  • Onlycode.js can be modified for your implementation
  • The function must be namedrun 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 inputnpm start --'{ "name": "Alice" }'# Complex inputnpm start --'{ "users": ["Alice", "Bob"], "active": true, "count": 42 }'# Run testsnpmtest

Console Output

Allconsole.log() statements in yourcode.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

[8]ページ先頭

©2009-2025 Movatter.jp