Skip to content

9.2. Local Coding Assistant

Setting up a productive coding environment usually means switching between an editor, terminal, browser, and documentation. Backend.AI GO's Cowork menu brings all of these capabilities into a single autonomous workflow: describe your coding task, and the agent reads your codebase, writes code, runs tests, and organizes files—entirely on your local machine.

This guide walks through setting up Cowork as a local coding assistant and provides a concrete example of building a Python CLI tool from scratch.

Why Use Cowork for Coding?

Traditional workflow Cowork workflow
Switch between editor, terminal, and browser Single interface for the entire task
Manually create files and write boilerplate Agent scaffolds project structure automatically
Run tests by hand, fix, repeat Agent writes code, runs tests, and iterates
Look up documentation in a separate window Agent searches docs and applies patterns directly

Privacy advantage: Your source code never leaves your machine. Unlike cloud-based AI coding assistants, Cowork runs the model locally, so proprietary code stays private.

Prerequisites

Before you begin, make sure you have:

  • Backend.AI GO installed and running
  • At least one model loaded — a capable model (7B+ parameters recommended) for best code generation quality
  • A project folder you want the agent to work with

Built-in Tools for Coding

The Cowork menu provides several built-in tools for coding tasks. No plugins or extensions are required.

Category Tools Description
File System read_file, write_file, list_directory, create_directory, delete_file, move_file Browse, create, edit, and organize project files
Code Execution run_python, run_command Execute Python scripts and shell commands directly
Search search_files, search_content Find files by pattern and search code content with regex
Data json_query, csv_reader Query JSON/CSV configuration or data files
Web web_search, fetch_url Search documentation and fetch API references
Utility calculator, get_current_time, get_system_info Math, timestamps, system information

Setting Up for Coding

Step 1: Open Cowork

Click the Cowork icon in the sidebar to open the Cowork interface.

Step 2: Add Your Project Folder

The agent needs access to your project files.

  1. Click the Folder Permissions toggle in the task input area.

  2. Click Add Folder and select your project folder.

  3. Choose the appropriate permission level:

    • Read Only — The agent can browse and understand your code but cannot modify it. Good for code review or explanation tasks.
    • Read & Write — The agent can read existing files and create or modify files. Recommended for most coding tasks.
    • Full Access — The agent can also delete and move files. Use when restructuring projects.

Start with Read Only

If you want the agent to understand your codebase before making changes, add the folder as Read Only first. Once you are satisfied with the plan, upgrade to Read & Write.

Step 3: Set Folder-Specific Instructions (Optional)

You can attach instructions to individual folders to encode project conventions:

  • Click the gear icon next to a folder in the permissions list.
  • Enter instructions such as: "This is a Python 3.12+ project. Follow PEP 8. Use type hints. Tests are in the tests/ directory."

These instructions apply only when the agent works within that folder.

Step 4: Configure Global Instructions (Optional)

Global instructions apply to all Cowork tasks.

  1. Open the Settings drawer (gear icon in the header).

  2. Go to the Instructions tab.

  3. Enter instructions such as:

    Always write tests for new code.
    Use TypeScript strict mode for .ts files.
    Follow the existing code style in the project.
    Include docstrings for public functions.
    
  4. Enable the instructions and close the drawer.

Step-by-Step Example: Building a Python CLI Tool

This example demonstrates a complete coding workflow using the Cowork menu.

Scenario: Create a file organizer CLI tool that sorts files by extension.

Step 1: Enter the Coding Task

In the task input at the bottom of the Cowork page, describe your goal:

Create a Python CLI tool called organizer.py that sorts files in a given directory by their extension into subdirectories. Include argument parsing with argparse, a --dry-run mode that shows what would happen without moving files, and a test file using pytest. Save everything in my project folder.

Press Enter (or click Start Task) to begin.

Step 2: Watch the Agent Work

The agent breaks the task into steps and executes them autonomously:

  1. Explore — Uses list_directory to examine the project structure and understand existing files.

  2. Plan — Determines the file structure: organizer.py for the main tool and test_organizer.py for tests.

  3. Write code — Uses write_file to create organizer.py with:

    • Argparse setup for source directory, --dry-run, and --verbose flags
    • File extension detection and directory creation logic
    • Proper error handling and logging
  4. Write tests — Uses write_file to create test_organizer.py with pytest test cases covering normal operation, dry-run mode, and edge cases.

  5. Verify — Uses run_python to execute the tests and confirm they pass.

  6. Summary — Presents what was created and any important notes.

Tool Approval

Write operations within permitted folders may require approval the first time. You can choose to approve once or for the session. Read operations within permitted folders are auto-approved by default.

Step 3: Steer the Agent Mid-Task

If you want to adjust the direction while the agent is working, use the Steering input:

  • "Also add a --verbose flag that logs each file move"
  • "Use pathlib instead of os.path"
  • "Add a --extensions filter so users can specify which extensions to organize"

The agent incorporates your guidance without restarting from scratch.

Step 4: Iterate and Refine

After the initial task completes, you can follow up with additional requests:

Add a --undo feature that reads a log file from the previous run and reverses the file moves. Update the tests to cover this new feature.

The agent remembers the project context from the previous task and builds on it.

Example: Code Review and Refactoring

Cowork can also review and improve existing code.

  1. Add your project folder with Read & Write permission.

  2. Enter a task like:

    Review the code in src/utils.py. Identify any bugs, security issues, or style violations. Refactor the code to follow best practices and add type hints. Run the existing tests afterward to ensure nothing is broken.

The agent will use read_file to examine the code, write_file to apply improvements, and run_python or run_command to verify tests still pass.

Example: Adding Tests to Existing Code

  1. Add your project folder with Read & Write permission.

  2. Enter a task like:

    Read through src/auth.py and write comprehensive pytest tests for all public functions. Save the tests as tests/test_auth.py. Run the tests and fix any failures.

The agent examines the source, generates tests, runs them, and iterates until they pass.

Agent Profiles and Sub-Agents

For specialized coding tasks, you can select a coding-oriented Agent Profile:

  • Open the Agent Profile selector in the Cowork interface.
  • Choose a profile optimized for coding (if available).
  • The profile adjusts the agent's system prompt, tool preferences, and behavior for coding workflows.

Sub-agents can parallelize independent tasks—for example, writing code in one sub-agent while another writes documentation.

Tool Approval and Safety

The Cowork system uses a permission model to keep your code safe:

Operation Default behavior
Read files within permitted folders Auto-approved
Write/create files within permitted folders Requires approval (configurable)
Delete/move files Requires approval
Shell commands (run_command) Always requires approval
Python execution (run_python) Runs in a sandboxed environment

Sandboxed Python

The run_python tool runs in a restricted environment with a Python import hook that blocks dangerous modules at the top level. Blocked modules include os, subprocess, shutil, socket, http, urllib, pickle, ctypes, multiprocessing, and others that could enable command execution, network access, file system manipulation, or unsafe deserialization. Safe modules such as math, statistics, json, csv, collections, itertools, re, datetime, random, hashlib, and typing are available for use. Note that this is an application-level defense; it is not kernel-level sandboxing. Timeout is configurable, with a default of 30 seconds.

Tips

  • Start with Read Only to let the agent explore your codebase before making changes. This builds better context.
  • Use folder-specific instructions to encode project conventions (language version, style guide, test framework).
  • Use Steering to course-correct without restarting the task.
  • Chain tasks: first ask the agent to analyze the code, then make changes in a follow-up task.
  • Combine with the API server: use Cowork to write code, then test it via the OpenAI-compatible API endpoint.
  • Larger models produce better code. For complex coding tasks, use the largest model that fits your hardware.

Troubleshooting

Problem Solution
Agent writes code but cannot run tests Ensure run_python or run_command is approved. Check that the project folder has Read & Write permission.
Generated code has import errors Use a larger model (13B+) for better import awareness. Add folder-specific instructions listing key dependencies.
Agent modifies wrong files Be specific in your task description about which files to modify. Use folder-specific instructions to mark certain directories as read-only.
Tests fail after agent edits Use Steering to ask the agent to re-run tests and fix failures. Or start a follow-up task: "Fix the failing tests in tests/."