Access Private Resources from RWX Sandboxes
Connect RWX sandboxes to Twingate so the agent in each sandbox can reach only the private Resources you assign to it.
A coding agent that uses RWX, such as Claude Code or Codex, can run its commands in an RWX sandbox with rwx sandbox exec (RWX sandboxes). With the setup on this page, each sandbox connects to Twingate as a Service and has access only to the Resources you assign to that Service, such as a staging API or an internal package registry. RWX publishes a twingate/setup package that installs the Twingate Client and runs headless setup with your Service Key. You’ll use it in the steps below, which start from the minimal sandbox.yml in RWX’s sandbox guide with the ubuntu:26.04 image and rwx/base 1.2.1.
How it works
You define the sandbox in .rwx/sandbox.yml, where a task named sandbox runs the rwx-sandbox command. When a sandbox starts, RWX does the following:
- Runs a
twingatetask, which calls thetwingate/setuppackage to install the Client and set it up with your Service Key. - Starts the Client as a background process of the
sandboxtask and waits up to 30 seconds fortwingate statusto printonline. - Runs
rwx-sandbox. From then on, the agent can run commands in the sandbox.
Prerequisites
- An RWX organization.
- The RWX CLI, installed and signed in with
rwx login. - A
.rwx/sandbox.ymlin your repository. You can create one withrwx sandbox init(RWX sandboxes).
Step 1: Create a Service
Set up a Service for the agent (Create a New Service):
- Create a Service.
- Assign it the Resources the agent needs to reach.
- Generate a Service Key with a reasonable expiration (Service Key lifecycle).
Step 2: Store the key in an RWX vault
Store the key as a secret named TWINGATE_SERVICE_KEY in an RWX vault that your sandbox runs can access (RWX secrets, RWX vaults). Use the raw JSON from the key file as the value. This command will store it in the default vault:
rwx vaults secrets set TWINGATE_SERVICE_KEY="$(cat service-key.json)"Step 3: Add Twingate to the sandbox
In .rwx/sandbox.yml, add a twingate task after the code task. Then change the sandbox task so that it uses the twingate task and starts the Client as a background process:
- key: twingate call: twingate/setup 1.1.1 with: twingate-service-key: ${{ secrets.TWINGATE_SERVICE_KEY }}
- key: sandbox use: [code, twingate] background-processes: - key: twingate run: sudo twingate start ready-check: run: '[ "$(twingate status)" = online ]' timeout-seconds: 30 run: rwx-sandboxIf you stored the key in a vault other than default, use ${{ vaults.<vault>.secrets.TWINGATE_SERVICE_KEY }} instead. If the Client doesn’t come online within 30 seconds, the sandbox task will fail, and rwx sandbox exec will print the error (RWX sandbox exec).
Step 4: Verify
Run these commands from the directory that contains .rwx/sandbox.yml:
rwx sandbox exec -- twingate statusrwx sandbox exec -- twingate resourcesrwx sandbox exec -- curl -sS -o /dev/null -w '%{http_code}\n' https://staging.internal.example.comReplace https://staging.internal.example.com with the URL of a web Resource. The first command will print online, the second will list the Service’s Resources, and the third will print the HTTP status code that the Resource returns, such as 200. For a Resource that isn’t a web service, such as a database, connect to it with a client for its protocol instead. Don’t test with ping, because the ubuntu:26.04 image doesn’t include it.
Network access
These steps use RWX’s default network setup. The ports required by the Client are listed in Endpoint Requirements.
Troubleshooting
The Client writes its log to /var/log/twingated.log in the sandbox. Run rwx sandbox exec -- sudo cat /var/log/twingated.log to read it.
- If
rwx sandbox execfails because thesandboxtask failed, open the run that the CLI links to and read the log of thetwingatebackground process. After you fix the problem, runrwx sandbox exec --reset -- twingate statusto start a new sandbox. - If the
twingatetask can’t access the secret, check that the vault is unlocked or that your user has access to it (RWX vaults).
For anything else, see Troubleshooting in Linux Headless Mode.
Related
Last updated