Skip to content

Long-Running Agents

Use beamctl to manage agents that keep running after you disconnect from a beam.

Build with agents
On this page

You can use Teleport Beams to securely manage long-running agentic workloads, such as complex coding projects. Each beam deploys with a tool, beamctl, that allows you to manage services that continue running after you exit your SSH session.

In this guide, you will learn how to manage long-running agentic workloads on a Teleport beam by walking through a small demo project.

How it works

Teleport Beams are micro VM sandboxes for running agentic workloads, hosted on the Teleport Cloud infrastructure. beam-init is the init system for a Teleport beam, similar to systemd in that it runs as PID 1 and spawns other processes that run on the host. beamctl is a CLI for managing processes spawned by beam-init, which it communicates with over a local Unix socket.

These processes are called services. Unlike systemd, which loads service definition files from disk, beam-init requires the user to declare new services while executing them over the command line. This is consistent with the ephemeral nature of a Teleport beam, which expires after 11 hours.

This guide illustrates the following beamctl commands in action:

Command Description
beamctl start <command> Create a service. Assigns a random service name (e.g., 2341e33f4f3c550f) unless you provide a name with the --name flag.
beamctl stop <service name> Terminate a service process.
beamctl restart <service name> Terminate a service process and start it again using its original command.
beamctl list List all services and their statuses.
beamctl logs <service name> Show the output of a service.

Deleting a service

If you terminate a beam-init service with beamctl stop, the default behavior is for beam-init to retain the service in its list of managed services. To remove a service from the list of services beam-init tracks, run the following command, replacing service-name with the name shown by beamctl list:

CLI
beamctl stop --prune service-name

Otherwise, beam-init does not allow you to start a service with the same name as an existing one, even if that service is stopped.

For a full list of commands, run the following on your beam:

CLI
beamctl help

Prerequisites

This guide requires a Teleport Beams account. Start your free trial.

Install the client tools and sign in

Beams is a Teleport project and uses official Teleport client tools.

The client tools include tsh to sign in and run commands, and tctl to administer your cluster if you have permission.

Cluster: example.beams.run. Edit this example to use your cluster name.

Install version 18.11.10 of the client:

Operating system
macOS

Download and open the macOS installer, then follow its instructions.

CLI
curl -O https://cdn.teleport.dev/teleport-tools-18.11.10.pkg
open teleport-tools-18.11.10.pkg
Linux

For Linux x86-64, download and install the client tools:

CLI
curl -O https://cdn.teleport.dev/teleport-v18.11.10-linux-amd64-bin.tar.gz
tar -xzf teleport-v18.11.10-linux-amd64-bin.tar.gz
sudo ./teleport/install
Windows

For Windows x86-64, run these commands in PowerShell. Add the extraction directory ($env:LOCALAPPDATA\Teleport) to your user PATH to use tsh in future terminals; the last command adds it to this terminal's PATH.

PowerShell
Invoke-WebRequest -Uri https://cdn.teleport.dev/teleport-v18.11.10-windows-amd64-bin.zip -OutFile teleport.zip
Expand-Archive -Path teleport.zip -DestinationPath "$env:LOCALAPPDATA\Teleport" -Force
$env:Path += ";$env:LOCALAPPDATA\Teleport"

Follow the official client tools install guide for other versions and architectures.

Check that you’re running v18.11.10 of the client with tsh version.

CLI
tsh version
Sign-in method
Passwordless

I sign in without a password (e.g. a passkey).

CLI
tsh login --proxy='example.beams.run' --auth=passwordless
Password & MFA

I have a password & MFA set up for my account:

Replace you@example.com with your Teleport username.

CLI
tsh login --proxy='example.beams.run' --user=you@example.com
SSO

I sign in with SSO (e.g. Okta, GitHub, SAML).

CLI
tsh login --proxy='example.beams.run'

In the demo project we’ll use for this guide, you will run two continuous agent workloads to build a simple web application:

  • Agent 1: Runs tests and gets them to pass by writing and optimizing code.
  • Agent 2: Writes tests and designs testable function signatures, but leaves implementations up to Agent 1.

Agent 2 writes tests that handle edge cases Agent 1 hasn’t addressed yet. This forces the agents to adopt a test-driven development (TDD) workflow and prevents the agent writing the application code from adding trivial tests.


WARNING

The demo we run in this guide skips permissions in agent prompts. Since an agent on a Teleport beam inherits the permissions of the user who started the beam, we recommend that you authenticate to Teleport as a user with no access to Teleport-protected resources before starting this guide.


Step 1/2. Set up the demo project

The demo project we’ll create in this guide lets users enter Morse code using a browser button and converts it to text.


TIP

Feel free to use another project idea. If you do, read through the rest of the guide first to understand the relevant workflows.


Create a Teleport beam and set up a project so that your agents have a place to carry out their work:

  1. Create a beam and begin an SSH session with it:

    CLI
    tsh beams add
  2. On the beam, set up a project directory:

    CLI
    mkdir morsecode
    cd morsecode
  3. Set up your project:

    CLI
    npm init
  4. Name the package morsecode and accept all the npm defaults.

  5. Install Vite, which we’ll use to set up the NodeJS project, and vitest for testing:

    CLI
    npm install -D vitest vite@~8.2.0
  6. Add empty directories:

    CLI
    mkdir tests src
  7. Start a dev server, which reloads automatically when source files change:

    CLI
    beamctl start --name=server -- \
      bash -c 'export HOME=/home/beams; \
        cd /home/beams/morsecode; \
        npx vite --host --port=8080;'
    Text
    Started service server

    beamctl start starts a service managed by the beam-init init system, which manages all processes that run on a Teleport beam. Here we set the home directory as the one in which we created our Vite project to ensure npm can work as expected.

    The server must run on port 8080 so you can visit it via Teleport later in the guide.

  8. Copy the following text to a file called SPEC.md on the beam:

    plaintext
    # Morse code in your browser
    
    When the user taps a button, the app reads it as Morse code and converts text
    to a readout below the button. There is a collapsable Morse code key as a
    reference for the user.
  9. Start the testing agent with claude, which comes preinstalled on the beam (as does codex). Every 10 seconds, the testing agent adds new tests to implement the application and address potential edge cases. Like the coding agent we’ll start next, the testing agent has a limit of 30 executions, amounting to around five minutes of work:

    CLI
    beamctl start --name=tester -- bash -c ' \
      export HOME=/home/beams; \
      export count=0; \
      cd /home/beams/morsecode; \
      while [ $count -lt 30 ]; do \
        claude -p --dangerously-skip-permissions < /dev/null "\
          Read SPEC.md and the existing test files under tests. Identify one \
          behavior from the spec that is not covered by an existing test yet, \
          e.g., a new function, or an additional edge case for a function  \
          you have already tested. If a test calls a function that does not exist \
          yet, import it in the new test and assume it has a testable function \
          signature, but do not create or modify anything in src. Another agent \
          will define functions and get tests to pass. Do not modify or remove \
          existing tests."; \
       sleep 10; \
       count=$((count+1)); \
     done;'
    Text
    Started service tester
  10. Start the coding agent:

    CLI
    beamctl start --name=coder -- bash -c ' \
      export HOME=/home/beams; \
      export count=0; \
      cd /home/beams/morsecode; \
      while [ $count -lt 30 ]; do \
        if ! npx vitest run --silent; then \
          claude -p --dangerously-skip-permissions < /dev/null "\
            Read SPEC.md and existing test files under tests. Get the tests to \
            pass by editing files in src. Maintain a minimal Vite entrypoint at \
            index.html to wire everything up."; \
        fi; \
       sleep 10; \
       count=$((count+1)); \
     done;'
    Text
    Started service coder
  11. Make sure all services are running as expected. All should report running:

    CLI
    beamctl list
    Text
      bootstrap (running PID=2)
      coder (running PID=168)
      server (running PID=5817)
      tester (running PID=136)

    Problem starting a service?

    If a service has not started correctly, check its logs:

    CLI
    beamctl logs tester
    beamctl logs coder
    beamctl logs server

    If you started a service with the wrong command, prune it first. This example removes tester; replace that name if you’re fixing a different service.

    CLI
    beamctl stop --prune tester

    Then rerun the appropriate beamctl start command above with the correction.

  12. Exit your session.

    CLI
    exit
    Text
    logout
    the connection was closed on the remote side at <timestamp>

Once you exit the session, the agents you spawned with beamctl will continue their work.

Step 2/2. Check your app

After a few minutes, your agents should have made substantial progress on your demo project.

  1. Find the beam you created so you can access it:

    CLI
    tsh beams ls
  2. Publish the application. The command below enrolls your demo project as a Teleport-protected web app. Assign beam-name to the name of your beam:

    CLI
    tsh beams publish beam-name
  3. Follow the prompts to authenticate to Teleport and visit your app.

  4. In your terminal, SSH into your beam:

    CLI
    tsh beams ssh beam-name
  5. Show the status of all the beamctl services you started:

    CLI
    beamctl list
    Text
      bootstrap (running PID=2)
      coder (running PID=168)
      server (running PID=5817)
      tester (running PID=136)
  6. Check the logs of your beamctl services. For example, you can see the tester discussing the tests it has added:

    CLI
    beamctl logs tester

    You can add the --follow flag to stream the service’s logs to your terminal.

  7. If the services are still running, you can terminate their processes with the following command:

    CLI
    beamctl stop tester
    beamctl stop coder
  8. If any services have stopped, and you would like them to resume their work, you can run the following command to restart them. For example:

    CLI
    beamctl restart coder
    beamctl restart tester
    beamctl restart server

Search docs

Loading search and AI…

Skills

Install all available skills. All Beams and Teleport skills are hosted in our OSS Teleport repository.

npx skills add https://github.com/gravitational/teleport