Understanding the Difference Between Code Generation and Code Execution with Genspark - Practical Application of Sandbox Environments

💡 What you'll learn in this article
  • The essential difference between code generation and code execution
  • Why "AI writes code = it can be executed" is a misunderstanding
  • The role of Genspark's sandbox environment
  • Practical examples of role-sharing in the Eric George Method

1. Misunderstood "AI Coding"

When hearing the phrase "AI can write code," some may understand it as "AI will complete and execute the program for me." However, this is a misconception.

⚠️ Common Misconception
"If I ask ChatGPT to write code, I'll get a program that runs immediately."

Reality
What ChatGPT generates is code as text, and whether it actually works is a separate issue.

In this article, we will explain the difference between Code Generation and Code Execution through practical examples from Genspark development.

🎯 Important: AI generating code and actually executing that code are separate technological domains. Understanding this distinction is crucial in software development in the AI era.
📖 Terminology
  • Code Generation: AI creating program code as text
  • Code Execution: Running the generated code in practice
  • Sandbox: An isolated, secure execution environment. It allows testing programs without affecting external systems.

2. What is Code Generation?

An Extension of AI-driven Text Generation

Code generation is, in essence, a type of text generation. AI tools such as ChatGPT, GitHub Copilot, and Claude learn from vast amounts of code examples and generate contextually relevant code as text.

📋 Example of Code Generation
User: "Write Python code to read a file."
AI:
with open('file.txt', 'r') as f:
    content = f.read()
    print(content)
This is syntactically correct code, but it requires file.txt to execute.

Three Issues with Generated Code

1. Potential for Syntax Errors
Code generated by AI may contain violations of programming language grammar (syntax errors).

2. Unresolved Dependencies
External libraries (dependencies) required for the code to run may not be explicitly stated.

3. Execution Environment Mismatch
The execution environment assumed by the generated code (OS, Python version, etc.) may differ from the actual environment.
📖 Technical Terms
  • Syntax error: An error that violates the grammatical rules of a programming language
  • Dependencies: Other libraries or tools required for a program to function

3. What is Code Execution?

The Necessity of an Execution Environment

To execute code, an appropriate execution environment is necessary. This includes (for details, refer to the Official Python Tutorial):

  • Programming language interpreter/runtime (Python, Node.js (JavaScript execution environment), etc.)
  • Installation of necessary libraries
  • Setting environment variables
  • Access permissions to the file system (a mechanism for storing and managing files)

Genspark's Sandbox Environment

Genspark provides a sandbox environment, which has the following characteristics:

🔧 Genspark's Sandbox Environment
  • Isolation: A secure environment that does not affect external systems
  • Completeness: Pre-installed with a Linux environment (open-source OS (Operating System: basic software that runs a computer)), Python, Node.js, etc.
  • Flexibility: Allows adding necessary libraries with pip install, etc.
  • Persistence constraints: The file system is temporary (may be cleared after the session ends)
📖 Technical Terms
  • Environment variables: Configuration values that control program behavior (e.g., API key (authentication information for API usage), Database connection information (settings for accessing a database))
  • Debugging: The process of finding and fixing errors (bugs) in a program

4. Genspark's Practical Example: The Eric George Method

The Eric George Method, introduced in Article 53 (V-model Application), clearly separates the roles of code generation and code execution. Furthermore, Article 51 demonstrated the differences in judgment capabilities among various AIs.

🎯 The Birth of the Eric George Method
This division of roles between code generation and code execution was the user's initiative. As a solution to a long-standing bug, the user proposed a method applying the V-model (one of the software development lifecycle models) to separate the upstream process (design and code generation) from the downstream process (implementation and code execution).

This role division enabled development that leveraged the strengths of each AI. However, it was a partial success, not a complete one, and user intervention may still be required.

Eric (Upstream Process AI): Responsible for Code Generation

Role
  • Generates design-level code based on requirements definition
  • Designs overall structure, function definitions, and processing flow
  • Clarifies "what needs to be implemented"
Typical Deliverables
  • Structured design documents
  • Signatures of key functions (definition of function names, argument types, and names)
  • Pseudocode that illustrates the processing flow (code that expresses the processing flow, independent of a specific programming language)
Limitations
  • Whether the generated code actually works is untested
  • Cannot consider detailed dependencies
  • Judgment capability is at a junior high school level (demonstrated in Article 51). However, it can present the broad framework of the design. Detailed judgment and implementation are handled by George and the user.
🎯 Important: The Eric George Method applies the V-model to AI development based on user initiative. By clearly separating code generation and code execution, it enables development that leverages the strengths of each AI.

George (Downstream Process AI): Responsible for Code Execution

Role
  • Implements Eric's design into actually runnable code
  • Executes tests in a sandbox environment
  • Detects and fixes errors (debugging)
Typical Tasks
  • Installation of necessary libraries (pip install: command to install libraries using Python's package management tool, etc.)
  • Implementation of file reading/writing and data processing
  • Identifying and fixing causes of errors when they occur
Strengths
  • Implementation capability is at a mid-career employee level (demonstrated in Article 51)
  • Understands execution environment constraints
  • Can identify problems from error messages

Examples of Role Sharing

⚠️ Challenges during the Development Process

During this development process, there were multiple instances where the user had to instruct error correction, such as when scripts generated by Eric failed due to Gemini API authentication errors. This was a partial success, not a complete one, and continuous improvement is necessary.

🎯 Example of Article Creation Tool Development

Eric (Code Generation)
  • Understood the requirement "create a quality check script"
  • Formulated a design to "call the Gemini API (AI API provided by Google)" and "save results in JSON (text format for data exchange)" (explained in detail in Article 52)
  • Generated the framework of a Bash script (shell script used in Linux)
George (Code Execution)
  • Implemented Eric's design
  • Wrote code to call the Gemini API using the curl command (a command-line tool for sending HTTP requests (communication requests to a web server))
  • Executed in the sandbox and corrected errors
  • Completed as article_quality_check_critical.sh

5. Why is this distinction important?

Reason 1: Code Generation Alone is Insufficient

No matter how excellent a code generation AI is, it's difficult to fully predict execution environment constraints. Many issues only become apparent when the code is actually run.

🎯 Important: Code generation AI is like "the person drawing blueprints," while the execution environment is "the construction site where the building is actually built." Neither alone is sufficient; both are necessary.
⚠️ Common Failure Examples
  • Copied and pasted Python code generated by ChatGPT, but encountered a ModuleNotFoundError (an error indicating that a required library is not installed)
  • Generated code uses syntax from an older version and does not run in the latest environment
  • File paths are environment-dependent and do not work in other environments

Reason 2: Complexity of Debugging

If a program doesn't work as expected, debugging is required. This is a different skill from mere code generation (Reference: Python Debugging Guide - Practical Guide to Python Debugging Techniques).

Typical Debugging Flow
  1. Error Occurs: An error message is displayed during program execution
  2. Root Cause Identification: Identify the problem area from error messages and logs
  3. Correction: Modify the code in the relevant section
  4. Retest: Re-execute after correction to confirm functionality
This process is a challenging task for code generation AIs.

Reason 3: Execution Environment Management

In actual development, managing the execution environment is one of the critical tasks (Reference: The Twelve-Factor App - Best Practices for Cloud-Native Application Development).

  • Dependency Management: Which library and which version are required (refer to pip Official Documentation - Python package management tool)
  • Environment Variable Configuration: Secure management of sensitive information like API keys
  • File System Constraints: Write permissions, disk space (amount of data that can be stored), etc.

6. Summary - Understanding Coding in the AI Era

Code generation and code execution are distinct technical domains. Understanding this difference is crucial for software development in the AI era.

🔍 Code Generation vs. Code Execution

Item Code Generation Code Execution
Essence Text generation Program execution
Main Tools ChatGPT, Copilot, etc. Sandbox environment
Deliverable Code as text Working program
Verification Method Syntax check Execution test
Eric George Method Eric (Upstream Process AI) George (Downstream Process AI)
🎯 Key Points
  • Code generation AI is like "the person drawing blueprints," while the execution environment is "the construction site where the building is actually built."
  • Neither alone is sufficient; both are necessary
  • Genspark's sandbox environment acts as a bridge between generation and execution

Genspark's Features

Genspark provides both code generation and code execution:

  • Code Generation: AI-powered design and code creation support (refer to Genspark Official Website)
  • Code Execution: Immediate execution and testing in a sandbox environment
  • Iterative Improvement: Streamlining the generate → execute → revise cycle
⚠️ Current Limitations and Challenges
  • Eric's Judgment Capability: Junior high school level, with limitations in complex design decisions
  • Sandbox Constraints: The file system is temporary and unsuitable for long-term data storage
  • Execution Time Limits: Restrictions on programs that run for extended periods
  • Need for User Intervention: For complex problems, user judgment and intervention are still required

Even as AI technology evolves, understanding the difference between code generation and execution is the first step towards effective AI utilization.

🎯 Important: Genspark streamlines the generate → execute → revise cycle by providing both code generation and code execution. This is a strength as an AI development platform.

📚 Related Articles