Skip to content

improvement(code): add wand config and system prompt for python code generation, strip \n from stdout in JS/Python - #1862

Merged
waleedlatif1 merged 1 commit into
stagingfrom
sim-369
Nov 9, 2025
Merged

improvement(code): add wand config and system prompt for python code generation, strip \n from stdout in JS/Python#1862
waleedlatif1 merged 1 commit into
stagingfrom
sim-369

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • add wand config and system prompt for python code generation so it is able to generate python code
  • strip \n from stdout in JS/Python (same way jupyter notebook and repl's do it)
  • remove RCE state management that is no longer used now that the toggle is gone

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

…generation, strip \n from stdout in JS/Python
@vercel

vercelBot commented Nov 9, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentPreviewCommentsUpdated (UTC)
docsSkippedSkippedNov 9, 2025 0:39am

@waleedlatif1
waleedlatif1 marked this pull request as ready for review November 9, 2025 00:40

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

Enhances Python code generation and improves stdout formatting across JavaScript and Python execution paths.

Key Changes:

  • Added PYTHON_AI_PROMPT system prompt in code.tsx with detailed instructions for AI-generated Python code, including parameter referencing (<paramName>) and environment variable syntax ({{ENV_VAR}})
  • Implemented dynamic wand config that applies Python-specific prompt and placeholder when Python language is selected
  • Introduced cleanStdout() function in route.ts that strips one trailing newline from all execution outputs (VM and E2B paths)
  • Enhanced E2B execution in e2b.ts to remove trailing empty lines after filtering result markers
  • Removed unused remoteExecution state management from code editor component

Impact:
The changes improve UX by making stdout display match REPL/notebook behavior (no extra trailing newlines) and enable better AI-assisted Python code generation with language-specific prompts.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-contained, focused improvements with clear intent. The stdout cleaning logic is simple and defensive (only removes one trailing newline if present). The Python AI prompt addition is purely additive and doesn't affect existing JavaScript functionality. The removal of unused remoteExecution code is clean refactoring. All changes follow existing patterns in the codebase.
  • No files require special attention

Important Files Changed

File Analysis

FilenameScoreOverview
apps/sim/app/api/function/execute/route.ts5/5Added cleanStdout() helper to strip trailing newlines from execution output, applied consistently across all execution paths (VM and E2B)
apps/sim/lib/execution/e2b.ts5/5Enhanced E2B execution to remove trailing empty lines from stdout after filtering result markers, improving output consistency
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/components/code/code.tsx5/5Removed remoteExecution state management (now unused), added Python-specific AI prompt and dynamic wand config based on language selection

Sequence Diagram

sequenceDiagram
participant User
participant CodeEditor as Code Editor Component
participant WandHook as useWand Hook
participant ExecuteAPI as /api/function/execute
participant E2B as E2B Sandbox
Note over CodeEditor: User selects Python language
CodeEditor->>CodeEditor: dynamicWandConfig computed<br/>PYTHON_AI_PROMPT applied
CodeEditor->>WandHook: Initialize with dynamicWandConfig
User->>CodeEditor: Write/generate Python code
CodeEditor->>ExecuteAPI: POST code with language='python'
ExecuteAPI->>ExecuteAPI: resolveCodeVariables()<br/>Wrap code with prologue
ExecuteAPI->>E2B: executeInE2B(code, 'python', timeout)
E2B->>E2B: runCode() in sandbox
E2B->>E2B: Filter __SIM_RESULT__ marker
E2B->>E2B: Remove trailing empty line
E2B-->>ExecuteAPI: {result, stdout, sandboxId}
ExecuteAPI->>ExecuteAPI: cleanStdout(stdout)<br/>Strip trailing \n
ExecuteAPI-->>CodeEditor: {success, output: {result, stdout}}
CodeEditor-->>User: Display cleaned output
Loading

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
waleedlatif1 merged commit 7c6e6d1 into stagingNov 9, 2025
9 checks passed
waleedlatif1 added a commit that referenced this pull request Nov 9, 2025
waleedlatif1 added a commit that referenced this pull request Nov 9, 2025
@waleedlatif1
waleedlatif1 deleted the sim-369 branch November 11, 2025 02:21
waleedlatif1 added a commit that referenced this pull request Nov 12, 2025
@waleedlatif1waleedlatif1 mentioned this pull request Nov 12, 2025
10 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@waleedlatif1