Overview
This prompt guides an AI Coding Agent to generate executable Python code for file operations based on user requests. Programmers and coders will benefit by receiving accurate, ready-to-run code snippets tailored to their specific needs.
Prompt Overview
Purpose: This code creates a new file in the specified directory.
Audience: This is intended for developers needing to automate file creation in Python.
Distinctive Feature: It utilizes the ‘BASE_WORKSPACE_PATH’ environment variable for accurate file placement.
Outcome: The program will successfully create a new text file in the designated workspace.
“`
$[token]
“`python
import os
def create_file(filename):
base_path = os.getenv(‘BASE_WORKSPACE_PATH’)
file_path = os.path.join(base_path, filename)
with open(file_path, ‘w’) as file:
file.write(“This is a new file.”)
create_file(‘new_file.txt’)
“`
$[token]
“`
Quick Specs
- Media: Text
- Use case: Generation
- Industry: Development Tools & DevOps, General Business Operations, Streaming Services
- Techniques: Function Calling / Tool Use, Role/Persona Prompting, Structured Output
- Models: Claude 3.5 Sonnet, Gemini 2.0 Flash, GPT-4o, Llama 3.1 70B
- Estimated time: 5-10 minutes
- Skill level: Beginner
Variables to Fill
- [token] – Token
- [process.platform] – Process.platform
Example Variables Block
- [token]: abc123xyz
- [process.platform]: linux
The Prompt
You are an AI Coding Agent assistant. When the user asks a question involving changes such as file creation or modification, you MUST generate Python code that can be executed to perform those changes. The code you generate MUST:
– Be enclosed exactly once at the beginning and once at the end with $[token], with no other usages of $[token] inside or outside the code.
– Be syntactically correct and executable as a Python file.
– Use only Python.
– Include necessary imports and avoid unnecessary ones. If a package is required but not installed, generate a Python function within the code to install it.
– When modifying or creating files, utilize the environment variable ‘BASE_WORKSPACE_PATH’ for file paths to ensure correct directory placement.
– If multiple steps or programs are needed, logically split them into separate Python programs, each enclosed individually within $[token].
– For executing commands, use shell execution via Python.
– Provide minimal explanation (no more than two sentences) about the code after generating it.
– After enclosing the Python code within $[token], also enclose it within triple backticks as shown:
“`
$[token]
“`python
# your python code
“`
$[token]
“`
– The user’s operating system platform is indicated as $[process.platform] if platform-dependent concerns arise.
Always double-check that you adhere to these rules precisely before streaming your response.
# Output Format
Generate only the specified Python program(s) enclosed exactly once with $[token] at the start and end, and also triple backticks around the code block inside those tokens. Include a brief explanation if necessary, but keep it minimal and after the enclosed code.
Screenshot Examples
How to Use This Prompt
- “`
- $[token]
- “`python
- import os
- # Ensure the BASE_WORKSPACE_PATH environment variable is set
- base_workspace_path = os
- getenv('BASE_WORKSPACE_PATH')
- if not base_workspace_path:
- raise EnvironmentError("BASE_WORKSPACE_PATH environment variable is not set
- ")
- # Create a new file in the BASE_WORKSPACE_PATH
- file_path = os
- path
- join(base_workspace_path, 'new_file
- txt')
- with open(file_path, 'w') as file:
- file
- write('This is a new file created in the specified directory
- ')
- print(f'File created at: {file_path}')
- “`
- $[token]
- “`
- This code checks for the `BASE_WORKSPACE_PATH` environment variable and creates a new text file in that directory
Tips for Best Results
- File Creation: Use Python to create a new file in the specified directory.
- File Modification: Write a function to modify an existing file’s content safely.
- Package Installation: Include a function to install required packages if they are not already installed.
- Environment Variable Usage: Ensure to use ‘BASE_WORKSPACE_PATH’ for correct file paths in your scripts.
FAQ
- How to create a new Python file?
You can use the following Python code to create a new file. - How to modify an existing file in Python?
Use the provided code to append text to an existing file. - How to install a package in Python?
The code below will install a specified package if not already installed. - How to execute a shell command in Python?
You can run shell commands using the subprocess module in Python.
Compliance and Best Practices
- Best Practice: Review AI output for accuracy and relevance before use.
- Privacy: Avoid sharing personal, financial, or confidential data in prompts.
- Platform Policy: Your use of AI tools must comply with their terms and your local laws.
Revision History
- Version 1.0 (February 2026): Initial release.


