본문으로 건너뛰기
Skillpedia
일반 코딩7.8k · #12980

run-shell-python-file-io

하는 일

이 스킬은 AI 에이전트가 셸에서 Python을 실행해 파일을 읽고, 내용을 바꾸고, 저장하는 방법을 보여 줍니다. 샌드박스가 작업 폴더의 파일을 볼 수 없는 사람을 위한 스킬입니다.

사용하는 경우

  • ✓코드 샌드박스가 작업 폴더의 파일에 접근하지 못할 때.
  • ✓파일을 읽고, 내용을 바꾸고, 결과를 저장해야 할 때.
  • ✓긴 파일 작업에서 여러 단계를 실행할 임시 Python 스크립트가 필요할 때.

스킬 링크

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/run-shell-python-file-io/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/run-shell-python-file-io/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“작업 폴더에 있는 input.txt를 읽어서 글자를 모두 대문자로 바꾼 뒤 output.txt로 저장해 주세요. 샌드박스는 이 폴더를 볼 수 없습니다.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 셸에서 짧은 Python 프로그램을 실행합니다. 이 프로그램은 입력 파일을 읽고 글을 처리한 다음 결과 파일을 씁니다. 작업 폴더 경로와 완료 메시지를 출력해서 결과를 확인할 수 있게 합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Run Shell Python File I/O

When to Use This Skill

Use this technique when execute_code_sandbox cannot access files in your working directory, but you need to perform file operations (read, write, transform) as part of your task execution.

The Pattern

Instead of using execute_code_sandbox, run Python code directly through run_shell with explicit path handling. This provides reliable file I/O capabilities within the task workspace.

How to Apply

Step 1: Identify File Access Needs

Determine which files you need to read from or write to in the working directory.

Step 2: Write Inline Python via run_shell

Construct a Python script that handles your file operations and execute it through run_shell:

python3 -c "
import os

# Get the working directory
work_dir = os.getcwd()
print(f'Working directory: {work_dir}')

# Read a file
with open('input.txt', 'r') as f:
    content = f.read()

# Process the content
processed = content.upper()

# Write to output file
with open('output.txt', 'w') as f:
    f.write(processed)

print('File operation complete')
"

Step 3: Handle Complex Logic

For more complex operations, write a temporary Python script file first:

cat > /tmp/process.py << 'EOF'
import os
import json

work_dir = os.getcwd()

# Read input
with open('data.json', 'r') as f:
    data = json.load(f)

# Transform
result = {k: v * 2 for k, v in data.items()}

# Write output
with open('result.json', 'w') as f:
    json.dump(result, f, indent=2)

print(f'Processed {len(data)} items')
EOF

python3 /tmp/process.py

Step 4: Verify File Operations

After execution, verify the files were created/modified correctly:

ls -la
cat output.txt

Best Practices

  1. Use Absolute or Relative Paths Explicitly: Always specify file paths clearly; os.getcwd() helps confirm your working directory.

  2. Handle Errors Gracefully: Add try/except blocks to catch file I/O errors:

    try:
        with open('file.txt', 'r') as f:
            content = f.read()
    except FileNotFoundError:
        print('File not found')
    
  3. Use Here-Docs for Complex Scripts: For scripts longer than a few lines, use bash here-documents to avoid escaping issues.

  4. Clean Up Temporary Files: If you create temporary scripts, consider removing them after execution.

  5. Check Working Directory First: Print os.getcwd() to confirm you're operating in the expected directory.

Common Use Cases

  • Reading configuration files from the workspace
  • Writing generated reports or outputs
  • Transforming data files (CSV, JSON, XML)
  • Batch processing multiple files
  • Generating structured documents (PDFs, spreadsheets)

Example: Processing Multiple Files

python3 -c "
import os
import glob

work_dir = os.getcwd()
files = glob.glob('*.txt')

for f in files:
    with open(f, 'r') as file:
        content = file.read()
    # Process each file
    with open(f'processed_{f}', 'w') as out:
        out.write(content.strip().upper())

print(f'Processed {len(files)} files')
"

Troubleshooting

Issue Solution
File not found Check os.getcwd() output; use absolute paths if needed
Permission denied Ensure the directory is writable; avoid protected system paths
Encoding errors Specify encoding explicitly: open('file.txt', 'r', encoding='utf-8')
Multi-line script issues Use here-doc (<< 'EOF') instead of -c for complex scripts
자주 묻는 질문

에이전트는 왜 작업 폴더 경로를 출력하나요?

스크립트가 어떤 폴더를 사용하는지 보여 주므로, 파일이 예상한 위치에 있는지 확인할 수 있습니다.

더 긴 작업은 어떻게 하나요?

스킬은 복잡한 로직이 있으면 먼저 임시 Python 스크립트 파일을 만든 다음 실행하라고 안내합니다.

원본 파일이 삭제되나요?

예시는 입력 파일을 읽고 별도의 출력 파일을 쓰므로, 입력 파일은 그대로 남습니다.

상세 정보

작성자의 원본 설명

Use run_shell with inline Python for reliable file I/O when execute_code_sandbox cannot access working directory files

repo: HKUDS/AgentPilot

인기도

GitHub 스타
7.8k
순위
#12980
라이선스
MIT
업데이트
2026. 11. 1.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬